task(E6-backend): guests CRUD - schema, adapter, routes
This commit is contained in:
@@ -11,6 +11,7 @@ import type {
|
||||
DBElement, DBBlock, DBSetting, DBUser, DBSession,
|
||||
DBNotification, DBProjectShare,
|
||||
DBGlobalBlockFolder, DBGlobalBlock,
|
||||
DBGuest,
|
||||
DBProjectFolder,
|
||||
} from './DatabaseInterface.js';
|
||||
|
||||
@@ -459,4 +460,37 @@ export class SqliteAdapter implements DatabaseInterface {
|
||||
deleteGlobalBlock(id: string): boolean {
|
||||
return this.db.prepare('DELETE FROM global_blocks WHERE id = ?').run(id).changes > 0;
|
||||
}
|
||||
|
||||
// ─── Guests (Task E6) ──────────────────────────────────
|
||||
|
||||
listGuests(drawingId: string): DBGuest[] {
|
||||
return this.db.prepare('SELECT * FROM guests WHERE drawing_id = ? ORDER BY created_at').all(drawingId) as DBGuest[];
|
||||
}
|
||||
|
||||
getGuest(id: string): DBGuest | null {
|
||||
return (this.db.prepare('SELECT * FROM guests WHERE id = ?').get(id) as DBGuest) ?? null;
|
||||
}
|
||||
|
||||
createGuest(data: Partial<DBGuest>): DBGuest {
|
||||
const id = data.id ?? randomUUID();
|
||||
const created_at = new Date().toISOString();
|
||||
this.db.prepare(
|
||||
'INSERT INTO guests (id, drawing_id, name, email, category, seat_element_id, notes, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)'
|
||||
).run(id, data.drawing_id!, data.name!, data.email ?? null, data.category ?? 'standard', data.seat_element_id ?? null, data.notes ?? null, created_at);
|
||||
return this.getGuest(id)!;
|
||||
}
|
||||
|
||||
updateGuest(id: string, data: Partial<DBGuest>): DBGuest | null {
|
||||
const existing = this.getGuest(id);
|
||||
if (!existing) return null;
|
||||
const merged = { ...existing, ...data, id: existing.id, drawing_id: existing.drawing_id, created_at: existing.created_at };
|
||||
this.db.prepare(
|
||||
'UPDATE guests SET name=?, email=?, category=?, seat_element_id=?, notes=? WHERE id=?'
|
||||
).run(merged.name, merged.email ?? null, merged.category, merged.seat_element_id ?? null, merged.notes ?? null, id);
|
||||
return this.getGuest(id);
|
||||
}
|
||||
|
||||
deleteGuest(id: string): boolean {
|
||||
return this.db.prepare('DELETE FROM guests WHERE id = ?').run(id).changes > 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user