2019-02-05 02:48:08 +00:00
|
|
|
import $ from 'cafy';
|
|
|
|
import ID, { transform, ObjectId } from '../../../../misc/cafy-id';
|
2018-11-02 04:47:44 +00:00
|
|
|
import { getRelation } from '../../../../models/user';
|
|
|
|
import define from '../../define';
|
2018-10-31 15:11:21 +00:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
desc: {
|
|
|
|
'ja-JP': 'ユーザー間のリレーションを取得します。'
|
|
|
|
},
|
|
|
|
|
2019-02-23 02:20:58 +00:00
|
|
|
tags: ['users'],
|
|
|
|
|
2018-10-31 15:11:52 +00:00
|
|
|
requireCredential: true,
|
|
|
|
|
2018-10-31 15:11:21 +00:00
|
|
|
params: {
|
2018-11-01 18:32:24 +00:00
|
|
|
userId: {
|
2019-02-23 02:20:58 +00:00
|
|
|
validator: $.either($.type(ID), $.arr($.type(ID)).unique()),
|
2018-11-01 18:32:24 +00:00
|
|
|
transform: (v: any): ObjectId | ObjectId[] => Array.isArray(v) ? v.map(x => transform(x)) : transform(v),
|
2018-10-31 15:11:21 +00:00
|
|
|
desc: {
|
|
|
|
'ja-JP': 'ユーザーID (配列でも可)'
|
|
|
|
}
|
2018-11-01 18:32:24 +00:00
|
|
|
}
|
2018-10-31 15:11:21 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-22 02:46:58 +00:00
|
|
|
export default define(meta, async (ps, me) => {
|
2018-10-31 15:11:21 +00:00
|
|
|
const ids = Array.isArray(ps.userId) ? ps.userId : [ps.userId];
|
|
|
|
|
|
|
|
const relations = await Promise.all(ids.map(id => getRelation(me._id, id)));
|
|
|
|
|
2019-02-22 02:46:58 +00:00
|
|
|
return Array.isArray(ps.userId) ? relations : relations[0];
|
|
|
|
});
|