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 };
|
||||
}
|
||||
@@ -1,5 +1,14 @@
|
||||
import { ValidationError } from '../common/domain-errors';
|
||||
import { addIsoDays, MAX_TRIP_DAYS, tripSpanDays, type PermissionKey } from '@trek/shared';
|
||||
import {
|
||||
addIsoDays,
|
||||
MAX_TRIP_DAYS,
|
||||
MAX_TRIP_TAGS,
|
||||
tripSpanDays,
|
||||
tripTagKey,
|
||||
uniqueTripTags,
|
||||
type PermissionKey,
|
||||
type TripUpdateRequest,
|
||||
} from '@trek/shared';
|
||||
|
||||
/**
|
||||
* Pure helpers of the trips domain, moved out of trips.service.ts. Nothing
|
||||
@@ -7,6 +16,28 @@ import { addIsoDays, MAX_TRIP_DAYS, tripSpanDays, type PermissionKey } from '@tr
|
||||
* TripsService.
|
||||
*/
|
||||
|
||||
export interface CreateTripData {
|
||||
title: string;
|
||||
description?: string | null;
|
||||
tags?: string[];
|
||||
start_date?: string | null;
|
||||
end_date?: string | null;
|
||||
currency?: string;
|
||||
reminder_days?: number;
|
||||
day_count?: number;
|
||||
}
|
||||
|
||||
// The wire contract of PUT /api/trips/:id (tripUpdateRequestSchema), which
|
||||
// update_trip hands on as well; nullable where it is, as null always arrived.
|
||||
export type UpdateTripData = TripUpdateRequest & { add_tags?: string[]; remove_tags?: string[] };
|
||||
|
||||
export function patchTripTags(current: string[], add: string[] = [], remove: string[] = []): string[] {
|
||||
const removed = new Set(remove.map(tripTagKey));
|
||||
const tags = uniqueTripTags([...current.filter((tag) => !removed.has(tripTagKey(tag))), ...add]);
|
||||
if (tags.length > MAX_TRIP_TAGS) throw new ValidationError(`A trip can have up to ${MAX_TRIP_TAGS} tags.`);
|
||||
return tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* The date range is refused, not cut short: generateDays used to clip the day
|
||||
* rows at the limit while the trip kept its full end date, so everything past
|
||||
|
||||
@@ -27,7 +27,6 @@ import { TourWaypoints } from '../../db/entities/TourWaypoints.entity';
|
||||
import type { TourWaypointRow } from '../../db/repositories/TourWaypoints.repository';
|
||||
import {
|
||||
addIsoDays,
|
||||
MAX_TRIP_TAGS,
|
||||
planDayGrid,
|
||||
resolveDayGridRange,
|
||||
type ActiveTrip,
|
||||
@@ -36,8 +35,6 @@ import {
|
||||
type RoadtripDayBoundary,
|
||||
type TrekWsPayload,
|
||||
type TrekWsTripEventName,
|
||||
type TripUpdateRequest,
|
||||
tripTagKey,
|
||||
uniqueTripTags,
|
||||
} from '@trek/shared';
|
||||
import { RealtimeService } from '../realtime/realtime.service';
|
||||
@@ -57,22 +54,7 @@ import { inOrder } from '../common/in-order';
|
||||
import { UnitOfWork } from '../database/unit-of-work';
|
||||
import { legacyBoundIntegerText } from '../common/row-id';
|
||||
import { appClock } from '../common/timezoneService';
|
||||
import { assertTripSpan, leaveStartFor } from './trips.helpers';
|
||||
|
||||
interface CreateTripData {
|
||||
title: string;
|
||||
description?: string | null;
|
||||
tags?: string[];
|
||||
start_date?: string | null;
|
||||
end_date?: string | null;
|
||||
currency?: string;
|
||||
reminder_days?: number;
|
||||
day_count?: number;
|
||||
}
|
||||
|
||||
// The wire contract of PUT /api/trips/:id (tripUpdateRequestSchema), which
|
||||
// update_trip hands on as well; nullable where it is, as null always arrived.
|
||||
type UpdateTripData = TripUpdateRequest & { add_tags?: string[]; remove_tags?: string[] };
|
||||
import { assertTripSpan, leaveStartFor, patchTripTags, type CreateTripData, type UpdateTripData } from './trips.helpers';
|
||||
|
||||
export interface UpdateTripResult {
|
||||
updatedTrip: any;
|
||||
@@ -481,9 +463,7 @@ export class TripsService {
|
||||
// Read within the serialized write transaction so concurrent tag edits
|
||||
// merge against the latest tags and keep each other's changes.
|
||||
const current = (await this.tripsRepo.findRaw(tripIdNum))?.tags ?? [];
|
||||
const removed = new Set(remove_tags?.map(tripTagKey));
|
||||
tags = uniqueTripTags([...current.filter(tag => !removed.has(tripTagKey(tag))), ...(add_tags ?? [])]);
|
||||
if (tags.length > MAX_TRIP_TAGS) throw new ValidationError(`A trip can have up to ${MAX_TRIP_TAGS} tags.`);
|
||||
tags = patchTripTags(current, add_tags, remove_tags);
|
||||
}
|
||||
|
||||
// Before the row: the rebase reads the outgoing currency off it (#1543).
|
||||
|
||||
Reference in New Issue
Block a user