misskey/packages/backend/src/server/api/endpoints/users/groups/delete.ts

42 lines
810 B
TypeScript
Raw Normal View History

2019-05-18 13:36:33 +02:00
import $ from 'cafy';
import { ID } from '@/misc/cafy-id';
import define from '../../../define';
import { ApiError } from '../../../error';
import { UserGroups } from '@/models/index';
2019-05-18 13:36:33 +02:00
export const meta = {
tags: ['groups'],
2020-02-15 13:33:32 +01:00
requireCredential: true as const,
2019-05-18 13:36:33 +02:00
kind: 'write:user-groups',
params: {
groupId: {
validator: $.type(ID),
2021-12-09 15:58:30 +01:00
},
2019-05-18 13:36:33 +02:00
},
errors: {
noSuchGroup: {
message: 'No such group.',
code: 'NO_SUCH_GROUP',
2021-12-09 15:58:30 +01:00
id: '63dbd64c-cd77-413f-8e08-61781e210b38',
},
},
2019-05-18 13:36:33 +02:00
};
2022-01-02 18:12:50 +01:00
// eslint-disable-next-line import/no-default-export
2019-05-18 13:36:33 +02:00
export default define(meta, async (ps, user) => {
const userGroup = await UserGroups.findOne({
id: ps.groupId,
2021-12-09 15:58:30 +01:00
userId: user.id,
2019-05-18 13:36:33 +02:00
});
if (userGroup == null) {
throw new ApiError(meta.errors.noSuchGroup);
}
await UserGroups.delete(userGroup.id);
});