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:
36
server/api/bookings/[id]/pic.patch.ts
Normal file
36
server/api/bookings/[id]/pic.patch.ts
Normal 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
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user