fix most type errors

still have a few things outstanding
This commit is contained in:
Thomas Ruoff
2020-08-28 00:29:20 +02:00
committed by Thomas Ruoff
parent c3d8c6f3e0
commit 90ac05a907
16 changed files with 279 additions and 96 deletions

View File

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