mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-21 22:46:32 +00:00
724c88c201
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.
51 lines
2.0 KiB
TypeScript
51 lines
2.0 KiB
TypeScript
import { TourTypes } from '../../src/db/entities/TourTypes.entity';
|
|
import { TourWaypoints } from '../../src/db/entities/TourWaypoints.entity';
|
|
import { Tours } from '../../src/db/entities/Tours.entity';
|
|
import type { TourTypesRepository } from '../../src/db/repositories/TourTypes.repository';
|
|
import type { TourWaypointsRepository } from '../../src/db/repositories/TourWaypoints.repository';
|
|
import type { ToursRepository } from '../../src/db/repositories/Tours.repository';
|
|
import { sharedTestOrm } from './test-uow';
|
|
|
|
import type Database from 'better-sqlite3';
|
|
|
|
/**
|
|
* Tours test-only repository factories, bound to a suite's own better-sqlite3
|
|
* handle through the same memoised `sharedTestOrm` `test-uow.ts` exports, so
|
|
* a repository built here and a `UnitOfWork` from `createTestUnitOfWork`
|
|
* resolve the same `EntityManager` (the `todo-repos.ts` precedent).
|
|
*/
|
|
export function createTestToursRepo(db: Database.Database): Promise<ToursRepository> {
|
|
return sharedTestOrm(db).then((t) => t.repo(Tours));
|
|
}
|
|
|
|
export function createTestTourTypesRepo(db: Database.Database): Promise<TourTypesRepository> {
|
|
return sharedTestOrm(db).then((t) => t.repo(TourTypes));
|
|
}
|
|
|
|
export function createTestTourWaypointsRepo(db: Database.Database): Promise<TourWaypointsRepository> {
|
|
return sharedTestOrm(db).then((t) => t.repo(TourWaypoints));
|
|
}
|
|
|
|
/** A `tours` row for an existing place, with the defaults a GPX import writes. */
|
|
export function createTour(
|
|
db: Database.Database,
|
|
placeId: number,
|
|
overrides: Partial<{
|
|
distance: number | null;
|
|
match_confidence: number | null;
|
|
max_hiking_difficulty: number;
|
|
created_at: string;
|
|
}> = {},
|
|
): void {
|
|
db.prepare(
|
|
`INSERT INTO tours (place_id, tour_type, distance, match_confidence, max_hiking_difficulty, created_at)
|
|
VALUES (?, 'hike', ?, ?, ?, COALESCE(?, CURRENT_TIMESTAMP))`,
|
|
).run(
|
|
placeId,
|
|
overrides.distance ?? null,
|
|
overrides.match_confidence ?? null,
|
|
overrides.max_hiking_difficulty ?? 2,
|
|
overrides.created_at ?? null,
|
|
);
|
|
}
|