feat(bookings): allow cancelling booking confirmations
Add API endpoint to revert confirmed bookings to pending status Add unconfirm buttons to the bookings list and confirmation page Update inventory summary when a confirmation is cancelled
This commit is contained in:
@@ -859,3 +859,30 @@ export async function confirmBookingByConfirmationToken(confirmationToken: strin
|
||||
|
||||
return await getBookingByConfirmationToken(confirmationToken)
|
||||
}
|
||||
|
||||
export async function cancelBookingConfirmationByConfirmationToken(confirmationToken: string): Promise<PublicBooking | null> {
|
||||
await ensureDatabaseReady()
|
||||
const sql = getSqlClient()
|
||||
|
||||
const [row] = await sql<DbBookingRow[]>`
|
||||
with updated_booking as (
|
||||
update bookings
|
||||
set
|
||||
status = 'pending',
|
||||
confirmed_at = null,
|
||||
updated_at = now()
|
||||
where confirmation_token = ${confirmationToken}
|
||||
and status = 'confirmed'
|
||||
returning *
|
||||
)
|
||||
select ${bookingSelectColumns(sql)}
|
||||
from updated_booking as bookings
|
||||
${bookingJoins(sql)}
|
||||
`
|
||||
|
||||
if (row) {
|
||||
return mapBooking(row)
|
||||
}
|
||||
|
||||
return await getBookingByConfirmationToken(confirmationToken)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user