feat(bookings): allow transferring bookings to another PIC

Add UI modal and button to reassign bookings to different contacts
Create API endpoint and repository method to handle PIC transfers
This commit is contained in:
2026-05-08 14:36:01 +08:00
parent 13e85cfcd0
commit f77f4390b6
5 changed files with 277 additions and 2 deletions

View File

@@ -0,0 +1,36 @@
import type { TransferBookingPicResponse } from '~~/shared/booking'
import { requireAuth } from '../../../utils/auth'
import { updateBookingPersonInCharge } from '../../../utils/booking-repository'
import { parseBookingPicTransferInput } from '../../../utils/bookings'
import { getRequiredRouteParam, httpError } from '../../../utils/http'
import { getPublicContactById } from '../../../utils/user-repository'
export default defineEventHandler(async (event): Promise<TransferBookingPicResponse> => {
const auth = await requireAuth(event)
const bookingId = getRequiredRouteParam(event, 'id', 'Booking ID')
const body = await readBody<{
personInChargeId?: string | null
}>(event)
const input = parseBookingPicTransferInput(body)
const nextPersonInCharge = await getPublicContactById(input.personInChargeId)
if (!nextPersonInCharge) {
httpError(404, 'Selected person in charge is not available')
}
const booking = await updateBookingPersonInCharge({
bookingId,
nextPersonInChargeId: nextPersonInCharge.id,
currentPersonInChargeId: auth.user.role === 'super_admin' ? undefined : auth.user.id
})
if (!booking) {
httpError(404, 'Booking not found')
}
return {
booking
}
})