Files
TREK/server/tests/helpers/factories/reservations.ts
T
Maurice 724c88c201 style: format server and shared with prettier
A mechanical prettier --write over server/src, server/tests, server/scripts
and shared/src with the workspaces' .prettierrc; nothing but layout and
import order changes, and every file keeps the same set of imports. shared
is formatted throughout and its format baseline is empty. The server
baseline keeps the 35 files that Prettier would grow past their lint:size
limit (they need a split first, which is not a formatting change), and the
generated entity files stay as their generator writes them.
2026-10-10 21:23:37 +02:00

55 lines
1.7 KiB
TypeScript

import { ReservationEndpoints } from '../../../src/db/entities/ReservationEndpoints.entity';
import { ReservationTravelers } from '../../../src/db/entities/ReservationTravelers.entity';
import { Reservations } from '../../../src/db/entities/Reservations.entity';
import type { FactoryOrm } from './context';
import { createRow } from './rows';
import type { EntityData, EntityDTO } from '@mikro-orm/core';
export type ReservationRow = EntityDTO<Reservations>;
export type ReservationEndpointRow = EntityDTO<ReservationEndpoints>;
/** A booking on the trip: a flight titled "Test Reservation" unless told otherwise. */
export function makeReservation(
orm: FactoryOrm,
tripId: number,
overrides: EntityData<Reservations> = {},
): Promise<ReservationRow> {
return createRow(orm, Reservations, {
trip: tripId,
title: 'Test Reservation',
type: 'flight',
day: null,
...overrides,
});
}
/**
* One end of a transport booking (`role` 'from' or 'to'), at Paris CDG
* unless told otherwise.
*/
export function makeReservationEndpoint(
orm: FactoryOrm,
reservationId: number,
overrides: EntityData<ReservationEndpoints> = {},
): Promise<ReservationEndpointRow> {
return createRow(orm, ReservationEndpoints, {
reservation: reservationId,
role: 'from',
sequence: 0,
name: 'Paris Charles de Gaulle',
code: 'CDG',
lat: 49.0097,
lng: 2.5479,
...overrides,
});
}
/** Puts the user on the booking's traveller list. */
export function addReservationTraveler(
orm: FactoryOrm,
reservationId: number,
userId: number,
): Promise<EntityDTO<ReservationTravelers>> {
return createRow(orm, ReservationTravelers, { reservation: reservationId, user: userId });
}