refactor(collections): parsing and writing a list's links moves into collections helpers

This commit is contained in:
Maurice
2026-10-12 21:13:57 +00:00
parent 5b6f76c98a
commit 4984e8f5eb
3 changed files with 54 additions and 17 deletions
@@ -0,0 +1,22 @@
import type { CollectionLink } from '@trek/shared';
/**
* Pure helpers of the collections domain, moved verbatim out of
* collections.service.ts. Nothing here touches the DB, so they stay plain
* exports rather than methods on CollectionsService.
*/
/** Links are stored as a JSON TEXT column; parse on read, stringify on write. */
export function parseLinks(raw: unknown): CollectionLink[] | undefined {
if (typeof raw !== 'string' || !raw) return undefined;
try {
const v = JSON.parse(raw);
return Array.isArray(v) ? (v as CollectionLink[]) : undefined;
} catch {
return undefined;
}
}
export function serializeLinks(links: CollectionLink[] | undefined): string | null {
return links && links.length ? JSON.stringify(links) : null;
}
@@ -62,7 +62,6 @@ import type {
CollectionMember,
CollectionMembership,
CollectionPlace,
CollectionLink,
CollectionCreateRequest,
CollectionUpdateRequest,
CollectionSavePlaceRequest,
@@ -76,22 +75,7 @@ import type {
import { NotificationsService } from '../notifications/notifications.service';
import { PlaceImportService, type ExportedCollectionFile } from '../place-import/place-import.service';
import { UnitOfWork } from '../database/unit-of-work';
/** Links are stored as a JSON TEXT column; parse on read, stringify on write. */
function parseLinks(raw: unknown): CollectionLink[] | undefined {
if (typeof raw !== 'string' || !raw) return undefined;
try {
const v = JSON.parse(raw);
return Array.isArray(v) ? (v as CollectionLink[]) : undefined;
} catch {
return undefined;
}
}
function serializeLinks(links: CollectionLink[] | undefined): string | null {
return links && links.length ? JSON.stringify(links) : null;
}
import { parseLinks, serializeLinks } from './collections.helpers';
// ---------------------------------------------------------------------------
// Errors — thrown as plain Errors carrying a status; TrekExceptionFilter maps