mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-06-19 13:21:46 +00:00
fix: clear stale accommodation_id on reservation update (#522)
When a place/accommodation is deleted, existing reservations still reference the now-gone accommodation_id. Validate that the linked accommodation exists before updating; clear to null if it doesn't.
This commit is contained in:
@@ -200,6 +200,10 @@ export function updateReservation(id: string | number, tripId: string | number,
|
||||
|
||||
// Update or create accommodation for hotel reservations
|
||||
let resolvedAccId: number | null = accommodation_id !== undefined ? (accommodation_id || null) : (current.accommodation_id ?? null);
|
||||
if (resolvedAccId) {
|
||||
const accExists = db.prepare('SELECT id FROM day_accommodations WHERE id = ?').get(resolvedAccId);
|
||||
if (!accExists) resolvedAccId = null;
|
||||
}
|
||||
if (type === 'hotel' && create_accommodation) {
|
||||
const { place_id: accPlaceId, start_day_id, end_day_id, check_in, check_out, confirmation: accConf } = create_accommodation;
|
||||
if (accPlaceId && start_day_id && end_day_id) {
|
||||
|
||||
Reference in New Issue
Block a user