Add a remark column to the bookings table for management-only notes. Include UI to view and edit remarks directly from the bookings list. Create API endpoint and database queries to support remark updates.
30 lines
901 B
TypeScript
30 lines
901 B
TypeScript
import type { PublicBooking } from '~~/shared/booking'
|
|
|
|
import { requireAuth } from '../../../utils/auth'
|
|
import { updateBookingRemark } from '../../../utils/booking-repository'
|
|
import { parseBookingRemarkInput } from '../../../utils/bookings'
|
|
import { getRequiredRouteParam, httpError } from '../../../utils/http'
|
|
|
|
export default defineEventHandler(async (event): Promise<{ booking: PublicBooking }> => {
|
|
const auth = await requireAuth(event)
|
|
const bookingId = getRequiredRouteParam(event, 'id', 'Booking ID')
|
|
const body = await readBody<{
|
|
remark?: string | null
|
|
}>(event)
|
|
|
|
const input = parseBookingRemarkInput(body)
|
|
const booking = await updateBookingRemark({
|
|
bookingId,
|
|
remark: input.remark,
|
|
personInChargeId: auth.user.role === 'super_admin' ? undefined : auth.user.id
|
|
})
|
|
|
|
if (!booking) {
|
|
httpError(404, 'Booking not found')
|
|
}
|
|
|
|
return {
|
|
booking
|
|
}
|
|
})
|