From 649177985dd7fa7ef220e3b61f4007eec3cd3e7f Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 1 Nov 2018 00:11:21 +0900 Subject: [API] Implement users/relation --- src/server/api/endpoints/users/relation.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/server/api/endpoints/users/relation.ts (limited to 'src/server/api/endpoints/users') diff --git a/src/server/api/endpoints/users/relation.ts b/src/server/api/endpoints/users/relation.ts new file mode 100644 index 0000000000..d29065d11f --- /dev/null +++ b/src/server/api/endpoints/users/relation.ts @@ -0,0 +1,28 @@ +import $ from 'cafy'; import ID from '../../../../misc/cafy-id'; +import { ILocalUser, getRelation } from '../../../../models/user'; +import getParams from '../../get-params'; + +export const meta = { + desc: { + 'ja-JP': 'ユーザー間のリレーションを取得します。' + }, + + params: { + userId: $.or($.type(ID), $.arr($.type(ID)).unique()).note({ + desc: { + 'ja-JP': 'ユーザーID (配列でも可)' + } + }) + } +}; + +export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => { + const [ps, psErr] = getParams(meta, params); + if (psErr) return rej(psErr); + + const ids = Array.isArray(ps.userId) ? ps.userId : [ps.userId]; + + const relations = await Promise.all(ids.map(id => getRelation(me._id, id))); + + res(Array.isArray(ps.userId) ? relations : relations[0]); +}); -- cgit v1.2.3-freya