mirror of
https://github.com/BradGroux/veritas-kanban.git
synced 2026-10-05 11:17:50 +00:00
fix: allow explicit IDs when creating managed list items
ManagedListService.create() now accepts an optional 'id' field. If provided, it uses the explicit ID instead of generating slug-nanoid. Also adds duplicate ID check to prevent conflicts. This fixes the corrupted task-type IDs (e.g., 'bug-GdN5rT' instead of 'bug') that were caused by always appending random suffixes.
This commit is contained in:
parent
762f7fa23a
commit
bb453ab6e9
1 changed files with 10 additions and 5 deletions
|
|
@ -100,14 +100,19 @@ export class ManagedListService<T extends ManagedListItem> {
|
|||
/**
|
||||
* Create a new item
|
||||
*/
|
||||
async create(input: Omit<T, 'id' | 'order' | 'created' | 'updated'>): Promise<T> {
|
||||
async create(input: Omit<T, 'order' | 'created' | 'updated'> & { id?: string }): Promise<T> {
|
||||
await this.init();
|
||||
|
||||
const now = new Date().toISOString();
|
||||
// T extends ManagedListItem which has 'label'; Omit preserves it
|
||||
const slug = this.slugify((input as Pick<ManagedListItem, 'label'>).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<ManagedListItem, 'label'>).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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue