The minimalistic document archiving platform.
fix(tags): add explicit error for duplicate tag updates (#852)
Corentin Thomasset71872db36783
diff --git a/.changeset/cool-cougars-stop.md b/.changeset/cool-cougars-stop.mdnew file mode 100644index 00000000..008b24b4--- /dev/null+++ b/.changeset/cool-cougars-stop.md@@ -0,0 +1,5 @@+---+"@papra/app": patch+---++Added explicit error when trying to update a tag with a name that already existsdiff --git a/apps/papra-server/src/modules/tags/tags.repository.ts b/apps/papra-server/src/modules/tags/tags.repository.tsindex 6eb441fa..1ded8668 100644--- a/apps/papra-server/src/modules/tags/tags.repository.ts+++ b/apps/papra-server/src/modules/tags/tags.repository.ts@@ -87,20 +87,32 @@ async function deleteTag({ tagId, db }: { tagId: string; db: Database }) {}async function updateTag({ tagId, name, description, color, db }: { tagId: string; name?: string; description?: string; color?: string; db: Database }) {- const [tag] = await db- .update(tagsTable)- .set(- omitUndefined({- name,- description,- color,- normalizedName: isDefined(name) ? normalizeTagName({ name }) : undefined,- }),- )- .where(- eq(tagsTable.id, tagId),- )- .returning();+ const [result, error] = await safely(+ db+ .update(tagsTable)+ .set(+ omitUndefined({+ name,+ description,+ color,+ normalizedName: isDefined(name) ? normalizeTagName({ name }) : undefined,+ }),+ )+ .where(+ eq(tagsTable.id, tagId),+ )+ .returning(),+ );++ if (isUniqueConstraintError({ error })) {+ throw createTagAlreadyExistsError();+ }++ if (error) {+ throw error;+ }++ const [tag] = result;return { tag };}