mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 18:54:17 +00:00
fix(ci): remove unused copy and split trip tag persistence
Remove unused dialog and upload strings from all locales. Move tag encoding and tag updates out of the largest trip files to meet the server size limits.
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { QueryFlag } from '@mikro-orm/core';
|
||||
import { tripTagNamesSchema, uniqueTripTags } from '@trek/shared';
|
||||
import type { TTripsCostsMode, Trips } from '../entities/Trips.entity';
|
||||
import { coalesceParam, currentTimestamp, ilike, nowDateOffset } from '../dialect/sql-functions';
|
||||
import type { AssertRowKeys } from './_shared/rows';
|
||||
@@ -7,6 +6,9 @@ import { TrekRepository } from './_shared/trek-repository';
|
||||
import { tripAccessExpr } from './_shared/trip-access';
|
||||
import type { DB } from '../kysely/db';
|
||||
import { toRowId } from '../row-id';
|
||||
import { decodeTags, encodeTags, type TripDatabaseRow, type TripRawRow } from './tripRows';
|
||||
|
||||
export type { TripRawRow } from './tripRows';
|
||||
|
||||
/** What a trip-scoped request learns about the trip once access is verified. */
|
||||
export interface TripAccess {
|
||||
@@ -15,56 +17,6 @@ export interface TripAccess {
|
||||
currency: string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* `SELECT * FROM trips WHERE id = ?`, every scalar column — the row
|
||||
* `TripReadModelService.getTripSummary` (TR-B) and, once Task 7 lands,
|
||||
* `TripsService.getRaw` (TP22) both need, `feed_token` included: the
|
||||
* `withoutFeedToken()` JS strip that guards the credential stays in the
|
||||
* SERVICE (TR-B's ruling), so this repository method must hand the column
|
||||
* back intact for that strip to have something to delete.
|
||||
*/
|
||||
interface TripDatabaseRow {
|
||||
id: number;
|
||||
user_id: number;
|
||||
title: string;
|
||||
description: string | null;
|
||||
tags_json: string | null;
|
||||
start_date: string | null;
|
||||
end_date: string | null;
|
||||
currency: string | null;
|
||||
cover_image: string | null;
|
||||
is_archived: number | null;
|
||||
reminder_days: number | null;
|
||||
feed_token: string | null;
|
||||
created_at: string | null;
|
||||
updated_at: string | null;
|
||||
reminder_sent_for: string | null;
|
||||
costs_mode: TTripsCostsMode;
|
||||
}
|
||||
|
||||
const _tripRawRowKeys: AssertRowKeys<TripDatabaseRow, Trips> = true;
|
||||
|
||||
export type TripRawRow = Omit<TripDatabaseRow, 'tags_json'> & { tags?: string[] };
|
||||
|
||||
function decodeTags<T extends { tags_json: string | null }>({ tags_json, ...row }: T) {
|
||||
let tags: string[] = [];
|
||||
if (tags_json) {
|
||||
try {
|
||||
const parsed = tripTagNamesSchema.safeParse(JSON.parse(tags_json));
|
||||
if (parsed.success) tags = parsed.data;
|
||||
} catch {
|
||||
// Older import tools may have written invalid JSON. Keep the trip readable.
|
||||
}
|
||||
}
|
||||
return { ...row, tags };
|
||||
}
|
||||
|
||||
function encodeTags(tags: string[] | undefined): { tags_json?: string | null } {
|
||||
if (tags === undefined) return {};
|
||||
const unique = uniqueTripTags(tags);
|
||||
return { tags_json: unique.length ? JSON.stringify(unique) : null };
|
||||
}
|
||||
|
||||
/**
|
||||
* `TRIP_SELECT`'s output row (inventory §11a) — every `TripRawRow` column
|
||||
* plus the four computed/joined columns the projection adds. `feed_token`
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import { tripTagNamesSchema, uniqueTripTags } from '@trek/shared';
|
||||
import type { TTripsCostsMode, Trips } from '../entities/Trips.entity';
|
||||
import type { AssertRowKeys } from './_shared/rows';
|
||||
|
||||
/**
|
||||
* `SELECT * FROM trips WHERE id = ?`, every scalar column — the row
|
||||
* `TripReadModelService.getTripSummary` (TR-B) and, once Task 7 lands,
|
||||
* `TripsService.getRaw` (TP22) both need, `feed_token` included: the
|
||||
* `withoutFeedToken()` JS strip that guards the credential stays in the
|
||||
* SERVICE (TR-B's ruling), so this repository method must hand the column
|
||||
* back intact for that strip to have something to delete.
|
||||
*/
|
||||
export interface TripDatabaseRow {
|
||||
id: number;
|
||||
user_id: number;
|
||||
title: string;
|
||||
description: string | null;
|
||||
tags_json: string | null;
|
||||
start_date: string | null;
|
||||
end_date: string | null;
|
||||
currency: string | null;
|
||||
cover_image: string | null;
|
||||
is_archived: number | null;
|
||||
reminder_days: number | null;
|
||||
feed_token: string | null;
|
||||
created_at: string | null;
|
||||
updated_at: string | null;
|
||||
reminder_sent_for: string | null;
|
||||
costs_mode: TTripsCostsMode;
|
||||
}
|
||||
|
||||
const _tripRawRowKeys: AssertRowKeys<TripDatabaseRow, Trips> = true;
|
||||
|
||||
export type TripRawRow = Omit<TripDatabaseRow, 'tags_json'> & { tags?: string[] };
|
||||
|
||||
export function decodeTags<T extends { tags_json: string | null }>({ tags_json, ...row }: T) {
|
||||
let tags: string[] = [];
|
||||
if (tags_json) {
|
||||
try {
|
||||
const parsed = tripTagNamesSchema.safeParse(JSON.parse(tags_json));
|
||||
if (parsed.success) tags = parsed.data;
|
||||
} catch {
|
||||
// Older import tools may have written invalid JSON. Keep the trip readable.
|
||||
}
|
||||
}
|
||||
return { ...row, tags };
|
||||
}
|
||||
|
||||
export function encodeTags(tags: string[] | undefined): { tags_json?: string | null } {
|
||||
if (tags === undefined) return {};
|
||||
const unique = uniqueTripTags(tags);
|
||||
return { tags_json: unique.length ? JSON.stringify(unique) : null };
|
||||
}
|
||||
Reference in New Issue
Block a user