mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-02 17:26:24 +00:00
style(server): satisfy accommodation confirmation lint
Keep ordered writes for one linked booking in a single method. Check that each test fixture exists before using the reservation.
This commit is contained in:
@@ -841,6 +841,16 @@ export class AccommodationsService {
|
||||
return await this.dayAccommodationsRepo.findInTrip(idNum, tripIdNum);
|
||||
}
|
||||
|
||||
private async syncLinkedReservation(
|
||||
id: number,
|
||||
metadata: string,
|
||||
confirmation: string | null | undefined,
|
||||
shouldConfirm: boolean,
|
||||
): Promise<void> {
|
||||
await this.reservationsRepo.setMetadataAndConfirmation(id, metadata, confirmation);
|
||||
if (shouldConfirm) await this.reservationsRepo.confirmIfPending(id);
|
||||
}
|
||||
|
||||
async updateAccommodation(
|
||||
id: string | number,
|
||||
existing: DayAccommodation,
|
||||
@@ -897,12 +907,7 @@ export class AccommodationsService {
|
||||
if (newCheckIn) meta.check_in_time = newCheckIn;
|
||||
if (newCheckInEnd) meta.check_in_end_time = newCheckInEnd;
|
||||
if (newCheckOut) meta.check_out_time = newCheckOut;
|
||||
await this.reservationsRepo.setMetadataAndConfirmation(
|
||||
res.id,
|
||||
encodeJson(RESERVATION_METADATA, meta),
|
||||
confirmation,
|
||||
);
|
||||
if (shouldConfirm) await this.reservationsRepo.confirmIfPending(res.id);
|
||||
await this.syncLinkedReservation(res.id, encodeJson(RESERVATION_METADATA, meta), confirmation, shouldConfirm);
|
||||
}
|
||||
return moved;
|
||||
});
|
||||
|
||||
@@ -1275,8 +1275,8 @@ describe('ReservationsService — legacy branch parity (coverage of the folded c
|
||||
const acc = createDayAccommodation(testDb, trip.id, place.id, days[0].id, days[1].id, { confirmation: 'ABC123' });
|
||||
const res = createReservation(testDb, trip.id, { title: 'Hotel', type: 'hotel' });
|
||||
await updateRows(orm, Reservations, { id: res.id }, { accommodation_id: String(acc.id), confirmation_number: 'ABC123' });
|
||||
const current = (await svc.getReservation(String(res.id), String(trip.id)))!;
|
||||
|
||||
const current = await svc.getReservation(String(res.id), String(trip.id));
|
||||
if (!current) throw new Error('Booking was not found');
|
||||
const { reservation, accommodationChanged } = await svc.update(String(res.id), String(trip.id), {
|
||||
confirmation_number: null, status: 'confirmed',
|
||||
}, current);
|
||||
@@ -1293,8 +1293,8 @@ describe('ReservationsService — legacy branch parity (coverage of the folded c
|
||||
const acc = createDayAccommodation(testDb, trip.id, place.id, days[0].id, days[1].id, { confirmation: 'ABC123' });
|
||||
const res = createReservation(testDb, trip.id, { title: 'Hotel', type: 'hotel' });
|
||||
await updateRows(orm, Reservations, { id: res.id }, { accommodation_id: String(acc.id) });
|
||||
const current = (await svc.getReservation(String(res.id), String(trip.id)))!;
|
||||
|
||||
const current = await svc.getReservation(String(res.id), String(trip.id));
|
||||
if (!current) throw new Error('Booking was not found');
|
||||
await svc.update(String(res.id), String(trip.id), {
|
||||
type: 'hotel',
|
||||
create_accommodation: { place_id: place.id, start_day_id: days[0].id, end_day_id: days[1].id, check_in: '14:00' },
|
||||
|
||||
Reference in New Issue
Block a user