mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-19 21:46:49 +00:00
e3471e2dc8
The booking form wrote the stay row itself, so it was the one door that left the day stop out. A hotel entered there stayed invisible to road trip mode, which is the same complaint as before with a different way in: enter the place twice or it is not on the route. It writes the stop now, through AccommodationsService rather than a second copy of its SQL. The permission argument for not doing so does not hold: the night already shows in the day header the moment the booking is saved, and the stop is that same night in the other view, not a second edit to the plan. Two holes go with it. Moving the booking left the stop on a day nobody sleeps there any more, and deleting it left the stop behind entirely — in both cases still carrying the booking's id, which is what the day list hides on, so nobody could reach it to remove it. The stop now follows the stay and goes with it, and only once the trip_id guard has confirmed the stay was this trip's to delete.
40 lines
1.9 KiB
TypeScript
40 lines
1.9 KiB
TypeScript
import type { Database } from 'better-sqlite3';
|
|
import { AccommodationsService } from '../../src/nest/accommodations/accommodations.service';
|
|
import { AssignmentsService } from '../../src/nest/assignments/assignments.service';
|
|
import { DatabaseService } from '../../src/nest/database/database.service';
|
|
import { JourneyDomainService } from '../../src/nest/journey/journey-domain.service';
|
|
import { PermissionsService } from '../../src/nest/permissions/permissions.service';
|
|
import { QueryHelpersService } from '../../src/nest/query-helpers/query-helpers.service';
|
|
import { RealtimeService } from '../../src/nest/realtime/realtime.service';
|
|
import { TrekPhotosRepository } from '../../src/nest/photos/trek-photos.repository';
|
|
|
|
/**
|
|
* AccommodationsService over a test connection.
|
|
*
|
|
* Booking a night also writes the day stop that puts it on the route, through a
|
|
* real AssignmentsService rather than a stub: the stop is a row these cases read
|
|
* back, and it has to come out of the same connection. Five collaborators deep is
|
|
* why this is a helper and not five copies across the suites.
|
|
*/
|
|
export function makeAccommodationsService(conn: Database): AccommodationsService {
|
|
return accommodationsOver(new DatabaseService(conn));
|
|
}
|
|
|
|
/**
|
|
* The same, for a suite that already holds the DatabaseService.
|
|
*
|
|
* ReservationsService takes one now, because a hotel booking owes the day plan
|
|
* the same stop a night entered under Days does, and every suite that builds
|
|
* that service by hand needs one to hand it.
|
|
*/
|
|
export function accommodationsOver(dbs: DatabaseService): AccommodationsService {
|
|
const permissions = new PermissionsService(dbs);
|
|
const realtime = new RealtimeService();
|
|
const assignments = new AssignmentsService(
|
|
dbs, permissions, realtime,
|
|
new QueryHelpersService(dbs),
|
|
new JourneyDomainService(dbs, realtime, new TrekPhotosRepository(dbs)),
|
|
);
|
|
return new AccommodationsService(dbs, permissions, realtime, assignments);
|
|
}
|