enhance: ユーザーリストおよびユーザーリスト内のユーザーの作成可能数を設定可能に

This commit is contained in:
syuilo
2023-01-14 17:38:16 +09:00
parent c41879c542
commit 76c049522e
9 changed files with 88 additions and 4 deletions

View File

@@ -5,6 +5,8 @@ import type { UserList } from '@/models/entities/UserList.js';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { UserListEntityService } from '@/core/entities/UserListEntityService.js';
import { DI } from '@/di-symbols.js';
import { ApiError } from '@/server/api/error';
import { RoleService } from '@/core/RoleService.js';
export const meta = {
tags: ['lists'],
@@ -20,6 +22,14 @@ export const meta = {
optional: false, nullable: false,
ref: 'UserList',
},
errors: {
tooManyUserLists: {
message: 'You cannot create user list any more.',
code: 'TOO_MANY_USERLISTS',
id: '0cf21a28-7715-4f39-a20d-777bfdb8d138',
},
},
} as const;
export const paramDef = {
@@ -39,8 +49,16 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
private userListEntityService: UserListEntityService,
private idService: IdService,
private roleService: RoleService,
) {
super(meta, paramDef, async (ps, me) => {
const currentCount = await this.userListsRepository.countBy({
userId: me.id,
});
if (currentCount > (await this.roleService.getUserRoleOptions(me.id)).userListLimit) {
throw new ApiError(meta.errors.tooManyUserLists);
}
const userList = await this.userListsRepository.insert({
id: this.idService.genId(),
createdAt: new Date(),

View File

@@ -111,7 +111,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
}
// Push the user
await this.userListService.push(user, userList);
await this.userListService.push(user, userList, me);
});
}
}