mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-24 07:53:09 +00:00
fix(reservations): link a cost created on a booking update on its insert
syncBudgetOnUpdate created the expense and then set its reservation_id in a second statement, inside a try that logs and swallows the failure. Running inside updateWithCost, a failed back-link committed an expense that was not linked to its booking. The expense is now created through linkBudgetItemToReservation, which writes the link on the insert, the same way syncBudgetOnCreate does.
This commit is contained in:
@@ -1192,9 +1192,8 @@ export class ReservationsService {
|
||||
const updated = await this.budget.updateBudgetItem(existing.id, tripId, { name: itemName, category, total_price: entry.total_price });
|
||||
this.sendCost(tripId, { event: 'budget:updated', payload: { item: updated } }, socketId, collect);
|
||||
} else {
|
||||
const item = await this.budget.createBudgetItem(tripId, { name: itemName, category, total_price: entry.total_price });
|
||||
await this.budgetItemsRepo.setReservationId(item.id, id);
|
||||
item.reservation_id = Number(id);
|
||||
// The link travels on the insert, so a cost is never written without its booking.
|
||||
const item = await this.budget.linkBudgetItemToReservation(tripId, Number(id), { name: itemName, category, total_price: entry.total_price! });
|
||||
this.sendCost(tripId, { event: 'budget:created', payload: { item } }, socketId, collect);
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user