2021-08-19 21:55:45 +09:00
|
|
|
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'],
|
|
|
|
|
|
2022-01-18 22:27:10 +09:00
|
|
|
requireCredential: true,
|
2019-05-22 05:06:52 +09:00
|
|
|
|
|
|
|
|
kind: 'write:user-groups',
|
|
|
|
|
|
2019-05-22 13:00:36 +09:00
|
|
|
res: {
|
2022-01-18 22:27:10 +09:00
|
|
|
type: 'object',
|
|
|
|
|
optional: false, nullable: false,
|
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
|
|
|
},
|
2022-01-18 22:27:10 +09:00
|
|
|
} as const;
|
2019-05-22 05:06:52 +09:00
|
|
|
|
2022-02-19 14:05:32 +09:00
|
|
|
const paramDef = {
|
|
|
|
|
type: 'object',
|
|
|
|
|
properties: {
|
|
|
|
|
groupId: { type: 'string', format: 'misskey:id' },
|
|
|
|
|
name: { type: 'string', minLength: 1, maxLength: 100 },
|
|
|
|
|
},
|
|
|
|
|
required: ['groupId', 'name'],
|
|
|
|
|
} 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) => {
|
2019-05-22 05:06:52 +09:00
|
|
|
// 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);
|
|
|
|
|
});
|