From ee70ad52fcb1d97b14b2ee0ac5790bf47f3dab5c Mon Sep 17 00:00:00 2001 From: Johann150 Date: Wed, 19 Oct 2022 21:54:37 +0200 Subject: [PATCH] server: error when trying to unclip note that is not clipped When a note is not added to a clip and an API call tries to remove the note from that clip, the API will now raise an error. Changelog: Changed --- .../src/server/api/endpoints/clips/remove-note.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/server/api/endpoints/clips/remove-note.ts b/packages/backend/src/server/api/endpoints/clips/remove-note.ts index a6a5eeca2..3762cbb37 100644 --- a/packages/backend/src/server/api/endpoints/clips/remove-note.ts +++ b/packages/backend/src/server/api/endpoints/clips/remove-note.ts @@ -22,6 +22,13 @@ export const meta = { code: 'NO_SUCH_NOTE', id: 'aff017de-190e-434b-893e-33a9ff5049d8', }, + + notClipped: { + message: 'That note is not added to this clip.', + code: 'NOT_CLIPPED', + id: '6b20c697-6e51-4120-b340-0e47899c7a20', + httpStatusCode: 409, + }, }, } as const; @@ -50,8 +57,12 @@ export default define(meta, paramDef, async (ps, user) => { throw e; }); - await ClipNotes.delete({ + const { affected } = await ClipNotes.delete({ noteId: note.id, clipId: clip.id, }); + + if (affected == 0) { + throw new ApiError(meta.errors.notClipped); + } });