mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 07:30:04 +00:00
7ca7dfd555
Brings in the Tours addon and the MikroORM follow-ups. Conflicts were resolved to dev's content, then every file dev brought in was run through prettier and eslint --fix so the branch stays uniformly formatted.
45 lines
1.7 KiB
TypeScript
45 lines
1.7 KiB
TypeScript
import { TourWaypoints } from '../../src/db/entities/TourWaypoints.entity';
|
|
import { Tours } from '../../src/db/entities/Tours.entity';
|
|
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 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,
|
|
);
|
|
}
|