1
0
Files
pawkey-sk/packages/backend/src/server/api/endpoints/users/groups/show.ts
T
syuilo 1c67c26bd8 refactor: migrate to typeorm 3.0 (#8443)
* wip

* wip

* wip

* Update following.ts

* wip

* wip

* wip

* Update resolve-user.ts

* maxQueryExecutionTime

* wip

* wip
2022-03-26 15:34:00 +09:00

57 lines
1.2 KiB
TypeScript

import define from '../../../define.js';
import { ApiError } from '../../../error.js';
import { UserGroups, UserGroupJoinings } from '@/models/index.js';
export const meta = {
tags: ['groups', 'account'],
requireCredential: true,
kind: 'read:user-groups',
res: {
type: 'object',
optional: false, nullable: false,
ref: 'UserGroup',
},
errors: {
noSuchGroup: {
message: 'No such group.',
code: 'NO_SUCH_GROUP',
id: 'ea04751e-9b7e-487b-a509-330fb6bd6b9b',
},
},
} as const;
export const paramDef = {
type: 'object',
properties: {
groupId: { type: 'string', format: 'misskey:id' },
},
required: ['groupId'],
} as const;
// eslint-disable-next-line import/no-default-export
export default define(meta, paramDef, async (ps, me) => {
// Fetch the group
const userGroup = await UserGroups.findOneBy({
id: ps.groupId,
});
if (userGroup == null) {
throw new ApiError(meta.errors.noSuchGroup);
}
const joining = await UserGroupJoinings.findOneBy({
userId: me.id,
userGroupId: userGroup.id,
});
if (joining == null && userGroup.userId !== me.id) {
throw new ApiError(meta.errors.noSuchGroup);
}
return await UserGroups.pack(userGroup);
});