iceshrimp/src/server/api/endpoints/users/relation.ts
YuzuRyo61 e183c2b509 APIドキュメントの改善 (#6757)
* Update api document in admin/announcements

* Update api document in announcements

* Update api document in i/read-announcements

* Update api document in username/available

* Update api document & Fix typo in API 403 error

* Update api document

* Update api document

* Update api document

* Fix API permission definition

* Update api document

* Update api document

* Update api document

* Update api document

* Update api document

* Update api document

* Update api document

* Update api document

* Fix bug in users (api)

* Apply reviews #6757

* Apply reviews #6757

Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2021-03-06 22:34:11 +09:00

119 lines
3.0 KiB
TypeScript

import $ from 'cafy';
import define from '../../define';
import { ID } from '../../../../misc/cafy-id';
import { Users } from '../../../../models';
export const meta = {
desc: {
'ja-JP': 'ユーザー間のリレーションを取得します。'
},
tags: ['users'],
requireCredential: true as const,
params: {
userId: {
validator: $.either($.type(ID), $.arr($.type(ID)).unique()),
desc: {
'ja-JP': 'ユーザーID (配列でも可)'
}
}
},
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];
});