mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
fix most type errors
still have a few things outstanding
This commit is contained in:
committed by
Thomas Ruoff
parent
c3d8c6f3e0
commit
90ac05a907
@@ -12,7 +12,7 @@ if (!SENDGRID_API_KEY) {
|
||||
throw new Error('NO SENDGRID_API_KEY set!')
|
||||
}
|
||||
|
||||
async function sendMail(data) {
|
||||
async function sendMail(data: object) {
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@@ -24,13 +24,11 @@ async function sendMail(data) {
|
||||
const response = await fetch(SENDGRID_URL, fetchOptions)
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`Failed to send booking ${data._id} to booking admin with status ${response.status}: ${response.statusText}`
|
||||
)
|
||||
throw new Error(`Unable to send mail`)
|
||||
}
|
||||
}
|
||||
|
||||
function getReceivedBookingText(booking) {
|
||||
function getReceivedBookingText(booking: { uuid: string }) {
|
||||
return `Hallo lieber Admin,
|
||||
|
||||
es ging folgende Buchung ein: https://${process.env.VERCEL_URL}/booking/${booking.uuid}
|
||||
@@ -38,7 +36,7 @@ function getReceivedBookingText(booking) {
|
||||
MfG`
|
||||
}
|
||||
|
||||
export async function sendReceivedBookingMail(booking) {
|
||||
export async function sendReceivedBookingMail(booking: { uuid: string }) {
|
||||
const data = {
|
||||
personalizations: [
|
||||
{
|
||||
@@ -46,9 +44,13 @@ export async function sendReceivedBookingMail(booking) {
|
||||
},
|
||||
],
|
||||
from: { email: FROM_EMAIL },
|
||||
subject: 'Pfadi Bussle - Buchung eingegangen!',
|
||||
subject: `Pfadi Bussle - Buchung ${booking.uuid} eingegangen!`,
|
||||
content: [{ type: 'text/plain', value: getReceivedBookingText(booking) }],
|
||||
}
|
||||
|
||||
await sendMail(data)
|
||||
try {
|
||||
await sendMail(data)
|
||||
} catch (error) {
|
||||
console.error(`Failed in sendReceivedBookingMail for ${booking.uuid}`)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user