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;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user