Files
TREK/server/tests/helpers/factories/user-places.ts
T
Maurice f69a4c1a24 feat(places): own place identities, duplicate merging and lists linked to a trip
- A user can group the uses of one place (trip places and saved places) into a
  place identity of their own (user_places, user_place_links). It is personal:
  it groups their "All places" and is never written into a shared trip or list
  row. An identity without a use they can still reach is not shown, and one
  left without links is pruned on their next write and nightly.
- Possible duplicates are suggested server side (same provider id, or the same
  name at the same spot), each pair with what differs and whether the user may
  merge it. A merge joins two identities in one transaction and can be undone;
  a dismissed pair does not come back. No trip or list row is deleted or changed.
- A trip can link lists (trip_collection_links, needs place_edit and access to
  the list). A member sees a linked list only with their own access to it; the
  map layer lists its places and whether each is already in the trip.
  tripCollections:changed tells the members to read their view again.
- REST, MCP tools and client data layer for all of it; migrations on both
  engines, additive only.
- CI: the stage 1 to 2 places-library helper types, and the await-in-loop and
  non-null counts it had raised.
2026-11-29 15:57:05 +01:00

44 lines
1.5 KiB
TypeScript

import { TripCollectionLinks } from '../../../src/db/entities/TripCollectionLinks.entity';
import { UserPlaceLinks } from '../../../src/db/entities/UserPlaceLinks.entity';
import { UserPlaces } from '../../../src/db/entities/UserPlaces.entity';
import { nextSeq, type FactoryOrm } from './context';
import { createRow } from './rows';
import type { EntityData, EntityDTO } from '@mikro-orm/core';
export type UserPlaceRow = EntityDTO<UserPlaces>;
export type UserPlaceLinkRow = EntityDTO<UserPlaceLinks>;
/** An own place (D5) of `userId`. */
export function makeUserPlace(
orm: FactoryOrm,
userId: number,
overrides: EntityData<UserPlaces> = {},
): Promise<UserPlaceRow> {
return createRow(orm, UserPlaces, { user: userId, name: `Own place ${nextSeq('user-place')}` }, overrides);
}
/** Links one use (a trip place or a saved place) of `userId` to the own place. */
export function linkUserPlace(
orm: FactoryOrm,
userId: number,
userPlaceId: number,
use: { place?: number; collectionPlace?: number },
): Promise<UserPlaceLinkRow> {
return createRow(orm, UserPlaceLinks, {
userPlace: userPlaceId,
user: userId,
place: use.place ?? null,
collectionPlace: use.collectionPlace ?? null,
});
}
/** Links a list to a trip (PLC-15). */
export function linkTripCollection(
orm: FactoryOrm,
tripId: number,
collectionId: number,
linkedBy: number | null = null,
): Promise<EntityDTO<TripCollectionLinks>> {
return createRow(orm, TripCollectionLinks, { trip: tripId, collection: collectionId, linkedByRef: linkedBy });
}