mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 22:47:15 +01:00
send mail when booking is confirmed or rejected
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
import { BookingDocument } from '../../../../../db/booking'
|
||||
import { getBookingByUUID } from '../../../../../db/index'
|
||||
import withSession, { isAdminSession } from '../../../../../lib/session'
|
||||
import {
|
||||
sendBookingConfirmed,
|
||||
sendBookingRejected,
|
||||
} from '../../../../../helpers/mail'
|
||||
import { BOOKING_STATUS } from '../../../../../db/enums'
|
||||
|
||||
export default withSession(async function bookingHandler(req, res) {
|
||||
if (!isAdminSession(req, res)) {
|
||||
@@ -22,11 +27,25 @@ export default withSession(async function bookingHandler(req, res) {
|
||||
|
||||
// FIXME: validate all the things
|
||||
booking.set(req.body)
|
||||
|
||||
const bookingStatusChanged = booking.isModified('status')
|
||||
|
||||
await booking.save()
|
||||
|
||||
await booking.populate('booker').execPopulate()
|
||||
|
||||
res.status(200).json(booking.toJSON())
|
||||
|
||||
if (!bookingStatusChanged) {
|
||||
return
|
||||
}
|
||||
|
||||
if (booking.status === BOOKING_STATUS.CONFIRMED) {
|
||||
sendBookingConfirmed(booking)
|
||||
} else if (booking.status === BOOKING_STATUS.REJECTED) {
|
||||
sendBookingRejected(booking)
|
||||
}
|
||||
|
||||
break
|
||||
default:
|
||||
res.setHeader('Allow', ['PATCH'])
|
||||
|
||||
Reference in New Issue
Block a user