diff --git a/server/src/services/managed-list-service.ts b/server/src/services/managed-list-service.ts index a8ae6ddf..0aa84c94 100644 --- a/server/src/services/managed-list-service.ts +++ b/server/src/services/managed-list-service.ts @@ -100,14 +100,19 @@ export class ManagedListService { /** * Create a new item */ - async create(input: Omit): Promise { + async create(input: Omit & { id?: string }): Promise { await this.init(); const now = new Date().toISOString(); - // T extends ManagedListItem which has 'label'; Omit preserves it - const slug = this.slugify((input as Pick).label); - const shortId = nanoid(6); - const id = `${slug}-${shortId}`; + // Use provided id if given (clean, deterministic), otherwise generate one + const id = + (input as { id?: string }).id || + `${this.slugify((input as Pick).label)}-${nanoid(6)}`; + + // Reject duplicate IDs + if (this.items.some((item) => item.id === id)) { + throw new Error(`Item with id '${id}' already exists`); + } // Calculate order as max + 1 const maxOrder = this.items.length > 0 ? Math.max(...this.items.map((item) => item.order)) : -1;