mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
send mail when booking is confirmed or rejected
This commit is contained in:
199
helpers/mail.ts
199
helpers/mail.ts
@@ -18,7 +18,138 @@ if (!FROM_EMAIL) {
|
||||
throw new Error('No FROM_EMAIL set!')
|
||||
}
|
||||
|
||||
async function sendMail(data: object) {
|
||||
const footer = `
|
||||
|
||||
Viele Grüße
|
||||
|
||||
Thomas Ruoff
|
||||
Pfadi Bussle Wart
|
||||
|
||||
Tel. 0151/212 253 62
|
||||
`
|
||||
|
||||
function getReceivedBookingBookerText(booking: BookingDocument) {
|
||||
return `Hallo liebe/r ${booking.booker.name},
|
||||
|
||||
Vielen Dank für Deine Buchung. Nach Prüfung bestätigen wir die Buchung bald per E-Mail!
|
||||
|
||||
Du kannst sie jederzeit unter
|
||||
|
||||
${getBaseURL()}/booking/${booking.uuid}
|
||||
|
||||
einsehen und auch stornieren.
|
||||
|
||||
${footer}
|
||||
`
|
||||
}
|
||||
|
||||
function getBookingConfirmedText(booking: BookingDocument) {
|
||||
return `Hallo liebe/r ${booking.booker.name},
|
||||
|
||||
deine Buchung ist bestätigt!
|
||||
|
||||
Bitte melde dich spätestens 7 Tage vor dem Buchungstermin per E-Mail oder Telefon
|
||||
um eine Schlüsselübergabe zu vereinbaren.
|
||||
|
||||
Du kannst deine Buchung weiterhin unter ${getBaseURL()}/booking/${booking.uuid}
|
||||
einsehen und stornieren.
|
||||
|
||||
${footer}
|
||||
`
|
||||
}
|
||||
function getBookingRejectedText(booking: BookingDocument) {
|
||||
return `Hallo liebe/r ${booking.booker.name},
|
||||
|
||||
deine Buchung konnte leider nicht bestätigt werden.
|
||||
|
||||
Du kannst versuchen einen anderen Termin auf ${getBaseURL} zu buchen.
|
||||
|
||||
${footer}
|
||||
`
|
||||
}
|
||||
|
||||
function getReceivedBookingAdminText(booking: { uuid: string }) {
|
||||
return `Hallo lieber Admin,
|
||||
|
||||
es ging folgende Buchung ein: ${getBaseURL()}/admin/booking/${booking.uuid}
|
||||
|
||||
MfG`
|
||||
}
|
||||
|
||||
export async function sendReceivedBookingAdminMail(booking: BookingDocument) {
|
||||
try {
|
||||
await sendMail({
|
||||
to: [{ email: ADMIN_EMAIL }],
|
||||
from: { email: FROM_EMAIL, name: 'Pfadi-Bussle Wart' },
|
||||
subject: `Buchung für ${booking.days} eingegangen!`,
|
||||
textPlainContent: getReceivedBookingAdminText(booking),
|
||||
})
|
||||
} catch (error) {
|
||||
console.error(`Failed in sendReceivedBookingMail for ${booking.uuid}`)
|
||||
}
|
||||
}
|
||||
|
||||
export async function sendReceivedBookingBookerMail(booking: BookingDocument) {
|
||||
try {
|
||||
await sendMail({
|
||||
to: [{ email: booking.booker.email, name: booking.booker.name }],
|
||||
from: { email: FROM_EMAIL, name: 'Pfadi-Bussle Wart' },
|
||||
subject: `Deine Pfadi-Bussle Buchung ist eingegangen!`,
|
||||
textPlainContent: getReceivedBookingBookerText(booking),
|
||||
})
|
||||
} catch (error) {
|
||||
console.error(`Failed in sendReceivedBookingMail for ${booking.uuid}`)
|
||||
}
|
||||
}
|
||||
|
||||
export async function sendBookingConfirmed(booking: BookingDocument) {
|
||||
try {
|
||||
await sendMail({
|
||||
to: [{ email: booking.booker.email, name: booking.booker.name }],
|
||||
from: { email: FROM_EMAIL, name: 'Pfadi-Bussle Wart' },
|
||||
subject: `Deine Pfadi-Bussle Buchung wurde bestätigt!`,
|
||||
textPlainContent: getBookingConfirmedText(booking),
|
||||
})
|
||||
} catch (error) {
|
||||
console.error(`Failed in sendBookingConfirmedMail for ${booking.uuid}`)
|
||||
}
|
||||
}
|
||||
|
||||
export async function sendBookingRejected(booking: BookingDocument) {
|
||||
try {
|
||||
await sendMail({
|
||||
to: [{ email: booking.booker.email, name: booking.booker.name }],
|
||||
from: { email: FROM_EMAIL, name: 'Pfadi-Bussle Wart' },
|
||||
subject: `Deine Pfadi-Bussle Buchung wurde abgelehnt!`,
|
||||
textPlainContent: getBookingRejectedText(booking),
|
||||
})
|
||||
} catch (error) {
|
||||
console.error(`Failed in sendBookingRejectedMail for ${booking.uuid}`)
|
||||
}
|
||||
}
|
||||
|
||||
async function sendMail({
|
||||
to,
|
||||
from,
|
||||
subject,
|
||||
textPlainContent,
|
||||
}: {
|
||||
to: { email: string; name?: string }[]
|
||||
from: { email: string; name?: string }
|
||||
subject: string
|
||||
textPlainContent: string
|
||||
}) {
|
||||
const data = {
|
||||
personalizations: [
|
||||
{
|
||||
to,
|
||||
},
|
||||
],
|
||||
from,
|
||||
subject,
|
||||
content: [{ type: 'text/plain', value: textPlainContent }],
|
||||
}
|
||||
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@@ -33,69 +164,3 @@ async function sendMail(data: object) {
|
||||
throw new Error(`Unable to send mail`)
|
||||
}
|
||||
}
|
||||
|
||||
function getReceivedBookingAdminText(booking: { uuid: string }) {
|
||||
return `Hallo lieber Admin,
|
||||
|
||||
es ging folgende Buchung ein: ${getBaseURL()}/booking/${booking.uuid}
|
||||
|
||||
MfG`
|
||||
}
|
||||
|
||||
export async function sendReceivedBookingAdminMail(booking: BookingDocument) {
|
||||
const data = {
|
||||
personalizations: [
|
||||
{
|
||||
to: [{ email: ADMIN_EMAIL }],
|
||||
},
|
||||
],
|
||||
from: { email: FROM_EMAIL, name: "Pfadi-Bussle Wart" },
|
||||
subject: `Buchung für ${booking.days} eingegangen!`,
|
||||
content: [{ type: 'text/plain', value: getReceivedBookingAdminText(booking) }],
|
||||
}
|
||||
|
||||
try {
|
||||
await sendMail(data)
|
||||
} catch (error) {
|
||||
console.error(`Failed in sendReceivedBookingMail for ${booking.uuid}`)
|
||||
}
|
||||
}
|
||||
|
||||
function getReceivedBookingBookerText(booking: BookingDocument) {
|
||||
return `Hallo liebe/r ${booking.booker.name},
|
||||
|
||||
Vielen Dank für Deine Buchung. Nach Prüfung bestätigen wir die Buchung bald per E-Mail!
|
||||
|
||||
Du kannst sie jederzeit unter
|
||||
|
||||
${getBaseURL()}/booking/${booking.uuid}
|
||||
|
||||
einsehen und auch stornieren.
|
||||
|
||||
Viele Grüße
|
||||
|
||||
Thomas Ruoff
|
||||
Pfadi Bussle Wart
|
||||
|
||||
Tel. 0151/212 253 62
|
||||
`
|
||||
}
|
||||
|
||||
export async function sendReceivedBookingBookerMail(booking: BookingDocument) {
|
||||
const data = {
|
||||
personalizations: [
|
||||
{
|
||||
to: [{ email: booking.booker.email, name: booking.booker.name }],
|
||||
},
|
||||
],
|
||||
from: { email: FROM_EMAIL, name: "Pfadi-Bussle Wart" },
|
||||
subject: `Deine Buchung ist eingegangen!`,
|
||||
content: [{ type: 'text/plain', value: getReceivedBookingBookerText(booking) }],
|
||||
}
|
||||
|
||||
try {
|
||||
await sendMail(data)
|
||||
} catch (error) {
|
||||
console.error(`Failed in sendReceivedBookingMail for ${booking.uuid}`)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user