1
0
Files
pawkey-sk/packages/backend/src/server/api/endpoints/users/groups/update.ts
T
tamaina fcfb5ef0a3 Fix ajv (#8333)
* wip

* ✌️

* use ajv/dist/core

* revert try

* clean up
2022-02-20 13:15:40 +09:00

54 lines
1.1 KiB
TypeScript

import define from '../../../define';
import { ApiError } from '../../../error';
import { UserGroups } from '@/models/index';
export const meta = {
tags: ['groups'],
requireCredential: true,
kind: 'write:user-groups',
res: {
type: 'object',
optional: false, nullable: false,
ref: 'UserGroup',
},
errors: {
noSuchGroup: {
message: 'No such group.',
code: 'NO_SUCH_GROUP',
id: '9081cda3-7a9e-4fac-a6ce-908d70f282f6',
},
},
} as const;
export const paramDef = {
type: 'object',
properties: {
groupId: { type: 'string', format: 'misskey:id' },
name: { type: 'string', minLength: 1, maxLength: 100 },
},
required: ['groupId', 'name'],
} 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.findOne({
id: ps.groupId,
userId: me.id,
});
if (userGroup == null) {
throw new ApiError(meta.errors.noSuchGroup);
}
await UserGroups.update(userGroup.id, {
name: ps.name,
});
return await UserGroups.pack(userGroup.id);
});