paricafe/src/server/api/endpoints/users/relation.ts
syuilo b9cb6d1c10 refactor: refactoring imports
将来ESMに移行しやすいように
Related: #7658

なんかmochaが起動しなくなってるけど理由不明
すぐ直したい
2021-08-19 18:33:41 +09:00

111 lines
2.9 KiB
TypeScript

import $ from 'cafy';
import define from '../../define.js';
import { ID } from '@/misc/cafy-id.js';
import { Users } from '@/models/index.js';
export const meta = {
tags: ['users'],
requireCredential: true as const,
params: {
userId: {
validator: $.either($.type(ID), $.arr($.type(ID)).unique()),
}
},
res: {
oneOf: [
{
type: 'object' as const,
optional: false as const, nullable: false as const,
properties: {
id: {
type: 'string' as const,
optional: false as const, nullable: false as const,
format: 'id'
},
isFollowing: {
type: 'boolean' as const,
optional: false as const, nullable: false as const
},
hasPendingFollowRequestFromYou: {
type: 'boolean' as const,
optional: false as const, nullable: false as const
},
hasPendingFollowRequestToYou: {
type: 'boolean' as const,
optional: false as const, nullable: false as const
},
isFollowed: {
type: 'boolean' as const,
optional: false as const, nullable: false as const
},
isBlocking: {
type: 'boolean' as const,
optional: false as const, nullable: false as const
},
isBlocked: {
type: 'boolean' as const,
optional: false as const, nullable: false as const
},
isMuted: {
type: 'boolean' as const,
optional: false as const, nullable: false as const
}
}
},
{
type: 'array' as const,
optional: false as const, nullable: false as const,
items: {
type: 'object' as const,
optional: false as const, nullable: false as const,
properties: {
id: {
type: 'string' as const,
optional: false as const, nullable: false as const,
format: 'id'
},
isFollowing: {
type: 'boolean' as const,
optional: false as const, nullable: false as const
},
hasPendingFollowRequestFromYou: {
type: 'boolean' as const,
optional: false as const, nullable: false as const
},
hasPendingFollowRequestToYou: {
type: 'boolean' as const,
optional: false as const, nullable: false as const
},
isFollowed: {
type: 'boolean' as const,
optional: false as const, nullable: false as const
},
isBlocking: {
type: 'boolean' as const,
optional: false as const, nullable: false as const
},
isBlocked: {
type: 'boolean' as const,
optional: false as const, nullable: false as const
},
isMuted: {
type: 'boolean' as const,
optional: false as const, nullable: false as const
}
}
}
}
]
}
};
export default define(meta, async (ps, me) => {
const ids = Array.isArray(ps.userId) ? ps.userId : [ps.userId];
const relations = await Promise.all(ids.map(id => Users.getRelation(me.id, id)));
return Array.isArray(ps.userId) ? relations : relations[0];
});