The minimalistic document archiving platform.
fix(demo): tag uniq constraint in demo (#854)
Corentin Thomassetcb8b4bb5217b
diff --git a/apps/papra-client/src/modules/demo/demo-api-mock.ts b/apps/papra-client/src/modules/demo/demo-api-mock.tsindex 043c1b67..1ef14109 100644--- a/apps/papra-client/src/modules/demo/demo-api-mock.ts+++ b/apps/papra-client/src/modules/demo/demo-api-mock.ts@@ -353,10 +353,20 @@ const inMemoryApiMock: Record<string, { handler: any }> = {assert(organization, { status: 403 });+ const name = get(body, ['name']) as string;+ const existingTagsWithSameName = await findMany(tagStorage, tag => tag.organizationId === organizationId && tag.name.toLowerCase() === name.toLowerCase());++ if (existingTagsWithSameName.length > 0) {+ throw Object.assign(new FetchError('Tag already exists'), {+ status: 400,+ data: { error: { code: 'tags.already_exists' } },+ });+ }+const tag = {id: createId({ prefix: 'tag' }),organizationId,- name: get(body, ['name']) as string,+ name,color: get(body, ['color']) as string,description: (get(body, ['description']) ?? null) as string | null,createdAt: new Date(),@@ -381,6 +391,24 @@ const inMemoryApiMock: Record<string, { handler: any }> = {assert(tag, { status: 404 });+ const newName = get(body, ['name']) as string | undefined;+ if (newName) {+ const existingTagsWithSameName = await findMany(+ tagStorage,+ t =>+ t.organizationId === organizationId+ && t.id !== tagId+ && t.name.toLowerCase() === newName.toLowerCase(),+ );++ if (existingTagsWithSameName.length > 0) {+ throw Object.assign(new FetchError('Tag already exists'), {+ status: 400,+ data: { error: { code: 'tags.already_exists' } },+ });+ }+ }+await tagStorage.setItem(tagId, Object.assign(tag, body, { updatedAt: new Date() }));return { tag };