2019-05-22 05:06:52 +09:00
|
|
|
import $ from 'cafy';
|
2021-08-19 21:55:45 +09:00
|
|
|
import { ID } from '@/misc/cafy-id';
|
|
|
|
|
import define from '../../../define';
|
|
|
|
|
import { ApiError } from '../../../error';
|
|
|
|
|
import { UserGroups } from '@/models/index';
|
2019-05-22 05:06:52 +09:00
|
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
|
tags: ['groups'],
|
|
|
|
|
|
2020-02-15 21:33:32 +09:00
|
|
|
requireCredential: true as const,
|
2019-05-22 05:06:52 +09:00
|
|
|
|
|
|
|
|
kind: 'write:user-groups',
|
|
|
|
|
|
|
|
|
|
params: {
|
|
|
|
|
groupId: {
|
|
|
|
|
validator: $.type(ID),
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
name: {
|
|
|
|
|
validator: $.str.range(1, 100),
|
2021-12-09 23:58:30 +09:00
|
|
|
},
|
2019-05-22 05:06:52 +09:00
|
|
|
},
|
|
|
|
|
|
2019-05-22 13:00:36 +09:00
|
|
|
res: {
|
2019-06-27 18:04:09 +09:00
|
|
|
type: 'object' as const,
|
|
|
|
|
optional: false as const, nullable: false as const,
|
2019-05-22 13:00:36 +09:00
|
|
|
ref: 'UserGroup',
|
|
|
|
|
},
|
|
|
|
|
|
2019-05-22 05:06:52 +09:00
|
|
|
errors: {
|
|
|
|
|
noSuchGroup: {
|
|
|
|
|
message: 'No such group.',
|
|
|
|
|
code: 'NO_SUCH_GROUP',
|
2021-12-09 23:58:30 +09:00
|
|
|
id: '9081cda3-7a9e-4fac-a6ce-908d70f282f6',
|
2019-05-22 05:06:52 +09:00
|
|
|
},
|
2021-12-09 23:58:30 +09:00
|
|
|
},
|
2019-05-22 05:06:52 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default define(meta, async (ps, me) => {
|
|
|
|
|
// Fetch the group
|
|
|
|
|
const userGroup = await UserGroups.findOne({
|
|
|
|
|
id: ps.groupId,
|
2021-12-09 23:58:30 +09:00
|
|
|
userId: me.id,
|
2019-05-22 05:06:52 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (userGroup == null) {
|
|
|
|
|
throw new ApiError(meta.errors.noSuchGroup);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await UserGroups.update(userGroup.id, {
|
2021-12-09 23:58:30 +09:00
|
|
|
name: ps.name,
|
2019-05-22 05:06:52 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return await UserGroups.pack(userGroup.id);
|
|
|
|
|
});
|