refactor(db): JSON columns are decoded through one declared schema per column

decodeJson/decodeJsonResult/encodeJson read and write a JSON-in-TEXT column against the schema and fallback declared for it in db/json-columns.ts, and log a row that does not decode. reservations.metadata, the OAuth scope and redirect lists, consents, API token scopes, MFA backup codes, journey entry tags and pros/cons and poll options go through it. Readers that used to throw on a broken row (a hotel update, the ICS export, the price mirror, the OAuth token and session reads, a consent, a journey entry, a poll) now take the tolerant fallback the other readers of the same column already used.
This commit is contained in:
Maurice
2026-10-10 12:13:56 +02:00
parent a926990e4a
commit 91deedae8b
26 changed files with 510 additions and 106 deletions
+4 -2
View File
@@ -28,6 +28,8 @@ import { CollabMessages } from '../../db/entities/CollabMessages.entity';
import type { CollabMessagesRepository, CollabMessageJoinRow } from '../../db/repositories/CollabMessages.repository';
import { Trips } from '../../db/entities/Trips.entity';
import type { TripsRepository } from '../../db/repositories/Trips.repository';
import { COLLAB_POLL_OPTIONS } from '../../db/json-columns';
import { decodeJson } from '../../utils/json-column';
type Trip = TripAccess;
@@ -366,7 +368,7 @@ export class CollabService {
const poll = await this.pollsRepo.findWithUser(pollId);
if (!poll) return null;
const options: (string | { label: string })[] = JSON.parse(poll.options);
const options = decodeJson(COLLAB_POLL_OPTIONS, poll.options, `poll ${poll.id}`) as (string | { label: string })[];
const votes = await this.pollVotesRepo.listForPoll(poll.id);
@@ -419,7 +421,7 @@ export class CollabService {
if (!poll) return { error: 'not_found' };
if (poll.closed) return { error: 'closed' };
const options = JSON.parse(poll.options);
const options = decodeJson(COLLAB_POLL_OPTIONS, poll.options, `poll ${poll.id}`);
if (!Number.isInteger(optionIndex) || optionIndex < 0 || optionIndex >= options.length) {
return { error: 'invalid_index' };
}