use nodemailer instead of sendgrid

This commit is contained in:
Thomas Ruoff
2022-12-22 23:00:44 +01:00
parent e0fe762c80
commit 28b3b03279
5 changed files with 130 additions and 211 deletions

View File

@@ -63,12 +63,16 @@ export default async function userHandler(
const { current, previous } = await patchBooking(uuid, req.body)
// TODO: this should really go into the schema
if (wasRejected(previous, current)) {
sendBookingRejected(current)
} else if (wasConfirmed(previous, current)) {
sendBookingConfirmed(current)
} else if (wasCanceled(previous, current)) {
sendBookingCanceled(current)
try {
if (wasRejected(previous, current)) {
sendBookingRejected(current)
} else if (wasConfirmed(previous, current)) {
sendBookingConfirmed(current)
} else if (wasCanceled(previous, current)) {
sendBookingCanceled(current)
}
} catch (error) {
log.error(`Failed to send booking ${current} for booking ${uuid}`)
}
res.status(200).json(current)
@@ -81,4 +85,4 @@ export default async function userHandler(
res.setHeader('Allow', ['PATCH'])
res.status(405).end(`Method ${method} Not Allowed`)
}
}
}

View File

@@ -34,17 +34,29 @@ export default async function userHandler(
`received booking ${booking.uuid} from ${booking.email}`,
booking
)
await sendReceivedBookingAdminMail(booking)
log.info(`send booking ${booking.uuid} received to admin`, booking)
await sendReceivedBookingBookerMail(booking)
log.info(
`send booking ${booking.uuid} received to {booking.email}`,
booking
)
try {
await sendReceivedBookingAdminMail(booking)
log.info(`send booking ${booking.uuid} received to admin`, booking)
} catch (error) {
log.error(`failed to send booking ${booking.uuid} received to admin`, booking)
}
try {
await sendReceivedBookingBookerMail(booking)
log.info(
`send booking ${booking.uuid} received to {booking.email}`,
booking
)
} catch (error) {
log.error(
`failed to send booking ${booking.uuid} received to {booking.email}`,
booking
)
}
res.status(200).json(booking)
break
default:
res.setHeader('Allow', ['POST'])
res.status(405).end(`Method ${method} Not Allowed`)
}
}
}