2022-02-27 11:07:39 +09:00
|
|
|
import define from '../../../define.js';
|
|
|
|
import { ApiError } from '../../../error.js';
|
|
|
|
import { UserGroups, UserGroupJoinings } from '@/models/index.js';
|
2021-10-16 17:42:17 +09:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
tags: ['groups', 'users'],
|
|
|
|
|
2022-01-18 22:27:10 +09:00
|
|
|
requireCredential: true,
|
2021-10-16 17:42:17 +09:00
|
|
|
|
|
|
|
kind: 'write:user-groups',
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchGroup: {
|
|
|
|
message: 'No such group.',
|
|
|
|
code: 'NO_SUCH_GROUP',
|
2021-12-09 23:58:30 +09:00
|
|
|
id: '62780270-1f67-5dc0-daca-3eb510612e31',
|
2021-10-16 17:42:17 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
youAreOwner: {
|
|
|
|
message: 'Your are the owner.',
|
|
|
|
code: 'YOU_ARE_OWNER',
|
2021-12-09 23:58:30 +09:00
|
|
|
id: 'b6d6e0c2-ef8a-9bb8-653d-79f4a3107c69',
|
2021-10-16 17:42:17 +09:00
|
|
|
},
|
2021-12-09 23:58:30 +09:00
|
|
|
},
|
2022-01-18 22:27:10 +09:00
|
|
|
} as const;
|
2021-10-16 17:42:17 +09:00
|
|
|
|
2022-02-20 13:15:40 +09:00
|
|
|
export const paramDef = {
|
2022-02-19 14:05:32 +09:00
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
groupId: { type: 'string', format: 'misskey:id' },
|
|
|
|
},
|
|
|
|
required: ['groupId'],
|
|
|
|
} as const;
|
|
|
|
|
2022-01-03 02:12:50 +09:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-02-19 14:05:32 +09:00
|
|
|
export default define(meta, paramDef, async (ps, me) => {
|
2021-10-16 17:42:17 +09:00
|
|
|
// Fetch the group
|
|
|
|
const userGroup = await UserGroups.findOne({
|
|
|
|
id: ps.groupId,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (userGroup == null) {
|
|
|
|
throw new ApiError(meta.errors.noSuchGroup);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (me.id === userGroup.userId) {
|
|
|
|
throw new ApiError(meta.errors.youAreOwner);
|
|
|
|
}
|
|
|
|
|
|
|
|
await UserGroupJoinings.delete({ userGroupId: userGroup.id, userId: me.id });
|
|
|
|
});
|