enhance: クリップおよびクリップ内のノートの作成可能数を設定可能に

This commit is contained in:
syuilo
2023-01-14 16:14:24 +09:00
parent 46d2a8726e
commit c2009acb2d
7 changed files with 90 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ import { IdService } from '@/core/IdService.js';
import { DI } from '@/di-symbols.js';
import type { ClipNotesRepository, ClipsRepository } from '@/models/index.js';
import { GetterService } from '@/server/api/GetterService.js';
import { RoleService } from '@/core/RoleService.js';
import { ApiError } from '../../error.js';
export const meta = {
@@ -37,6 +38,12 @@ export const meta = {
code: 'ALREADY_CLIPPED',
id: '734806c4-542c-463a-9311-15c512803965',
},
tooManyClipNotes: {
message: 'You cannot add notes to the clip any more.',
code: 'TOO_MANY_CLIP_NOTES',
id: 'f0dba960-ff73-4615-8df4-d6ac5d9dc118',
},
},
} as const;
@@ -60,6 +67,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
private clipNotesRepository: ClipNotesRepository,
private idService: IdService,
private roleService: RoleService,
private getterService: GetterService,
) {
super(meta, paramDef, async (ps, me) => {
@@ -86,6 +94,13 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
throw new ApiError(meta.errors.alreadyClipped);
}
const currentCount = await this.clipNotesRepository.countBy({
clipId: clip.id,
});
if (currentCount > (await this.roleService.getUserRoleOptions(me.id)).noteEachClipsLimit) {
throw new ApiError(meta.errors.tooManyClipNotes);
}
await this.clipNotesRepository.insert({
id: this.idService.genId(),
noteId: note.id,