Files
dticket.tootaio.com/server/api/bookings/[id]/pic.patch.ts
xiaomai f77f4390b6 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
2026-05-08 14:36:01 +08:00

37 lines
1.2 KiB
TypeScript

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
}
})