Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
jubnl
2026-08-11 23:26:36 +02:00
57 changed files with 1631 additions and 157 deletions
+9
View File
@@ -3856,6 +3856,15 @@ function runMigrations(db: Database.Database): void {
WHERE note LIKE 'TICKETJSON:%'
`);
},
// Note colours (#1629). A day note is a label as much as a reminder — "watch
// out", "must see", "already booked" — and a wall of identical grey cards
// makes that impossible to see at a glance. NULL keeps the neutral card
// every existing note has today.
() => {
const hasColor = db.prepare("SELECT 1 FROM pragma_table_info('day_notes') WHERE name = 'color'").get();
if (!hasColor) db.exec('ALTER TABLE day_notes ADD COLUMN color TEXT');
},
];
if (currentVersion < migrations.length) {
@@ -57,7 +57,7 @@ export class DayNotesController {
if (!body.text?.trim()) {
throw new HttpException({ error: 'Text required' }, 400);
}
const note = this.notes.create(dayId, tripId, body.text, body.time, body.icon, body.sort_order);
const note = this.notes.create(dayId, tripId, body.text, body.time, body.icon, body.sort_order, body.color);
this.notes.broadcast(tripId, 'dayNote:created', { dayId: Number(dayId), note }, socketId);
return { note };
}
@@ -76,7 +76,7 @@ export class DayNotesController {
if (!current) {
throw new HttpException({ error: 'Note not found' }, 404);
}
const note = this.notes.update(id, current as never, { text: body.text, time: body.time, icon: body.icon, sort_order: body.sort_order });
const note = this.notes.update(id, current as never, { text: body.text, time: body.time, icon: body.icon, sort_order: body.sort_order, color: body.color });
this.notes.broadcast(tripId, 'dayNote:updated', { dayId: Number(dayId), note }, socketId);
return { note };
}
+21 -6
View File
@@ -1,5 +1,5 @@
import { Injectable } from '@nestjs/common';
import type { TrekWsPayload, TrekWsTripEventName } from '@trek/shared';
import { NOTE_COLORS, type TrekWsPayload, type TrekWsTripEventName } from '@trek/shared';
import { RealtimeService } from '../realtime/realtime.service';
import { PermissionsService } from '../permissions/permissions.service';
import type { DayNote, User } from '../../types';
@@ -11,6 +11,20 @@ import { DatabaseService, type TripAccess } from '../database/database.service';
* coercions). Trip access rides DatabaseService.canAccessTrip; the 'day_edit'
* permission reuses the legacy check.
*/
/**
* Only a colour the palette actually offers reaches the column (#1629).
*
* The Zod contract can only say "a short string" — it has no way to express the
* palette without pinning the UI's choices into the wire format — so the check
* that matters lives here. Anything else is stored as "no colour", which is the
* neutral card, rather than being rejected: a bad colour is not a reason to lose
* the note someone just wrote.
*/
export function normalizeNoteColor(color: string | null | undefined): string | null {
if (!color) return null;
return (NOTE_COLORS as readonly string[]).includes(color) ? color : null;
}
@Injectable()
export class DayNotesService {
constructor(
@@ -46,21 +60,22 @@ export class DayNotesService {
return this.dbs.get<DayNote>('SELECT * FROM day_notes WHERE id = ? AND day_id = ? AND trip_id = ?', id, dayId, tripId);
}
create(dayId: string | number, tripId: string | number, text: string, time?: string | null, icon?: string | null, sortOrder?: number) {
create(dayId: string | number, tripId: string | number, text: string, time?: string | null, icon?: string | null, sortOrder?: number, color?: string | null) {
const result = this.dbs.run(
'INSERT INTO day_notes (day_id, trip_id, text, time, icon, sort_order) VALUES (?, ?, ?, ?, ?, ?)',
dayId, tripId, text.trim(), time || null, icon || '📝', sortOrder ?? 9999,
'INSERT INTO day_notes (day_id, trip_id, text, time, icon, sort_order, color) VALUES (?, ?, ?, ?, ?, ?, ?)',
dayId, tripId, text.trim(), time || null, icon || '📝', sortOrder ?? 9999, normalizeNoteColor(color),
);
return this.dbs.get('SELECT * FROM day_notes WHERE id = ?', result.lastInsertRowid);
}
update(id: string | number, current: DayNote, fields: { text?: string; time?: string | null; icon?: string | null; sort_order?: number }) {
update(id: string | number, current: DayNote, fields: { text?: string; time?: string | null; icon?: string | null; sort_order?: number; color?: string | null }) {
this.dbs.run(
'UPDATE day_notes SET text = ?, time = ?, icon = ?, sort_order = ? WHERE id = ?',
'UPDATE day_notes SET text = ?, time = ?, icon = ?, sort_order = ?, color = ? WHERE id = ?',
fields.text !== undefined ? fields.text.trim() : current.text,
fields.time !== undefined ? fields.time : current.time,
fields.icon !== undefined ? fields.icon : current.icon,
fields.sort_order !== undefined ? fields.sort_order : current.sort_order,
fields.color !== undefined ? normalizeNoteColor(fields.color) : (current.color ?? null),
id,
);
return this.dbs.get('SELECT * FROM day_notes WHERE id = ?', id);
+2
View File
@@ -238,6 +238,8 @@ export interface DayNote {
text: string;
time?: string | null;
icon: string;
/** One of NOTE_COLORS, or null for the neutral card (#1629). */
color?: string | null;
sort_order: number;
created_at?: string;
}