mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-04 06:57:12 +01:00
add email to customer as well
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
import { BookingDocument } from '../db/booking'
|
||||||
|
import { getBaseURL } from '../helpers/url'
|
||||||
|
|
||||||
const SENDGRID_API_KEY = process.env.SENDGRID_API_KEY
|
const SENDGRID_API_KEY = process.env.SENDGRID_API_KEY
|
||||||
const ADMIN_EMAIL = process.env.ADMIN_EMAIL
|
const ADMIN_EMAIL = process.env.ADMIN_EMAIL
|
||||||
const FROM_EMAIL = process.env.FROM_EMAIL
|
const FROM_EMAIL = process.env.FROM_EMAIL
|
||||||
@@ -31,24 +34,63 @@ async function sendMail(data: object) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getReceivedBookingText(booking: { uuid: string }) {
|
function getReceivedBookingAdminText(booking: { uuid: string }) {
|
||||||
return `Hallo lieber Admin,
|
return `Hallo lieber Admin,
|
||||||
|
|
||||||
es ging folgende Buchung ein: {getBaseURL()}/booking/${booking.uuid}
|
es ging folgende Buchung ein: ${getBaseURL()}/booking/${booking.uuid}
|
||||||
|
|
||||||
MfG`
|
MfG`
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function sendReceivedBookingMail(booking: { uuid: string }) {
|
export async function sendReceivedBookingAdminMail(booking: BookingDocument) {
|
||||||
const data = {
|
const data = {
|
||||||
personalizations: [
|
personalizations: [
|
||||||
{
|
{
|
||||||
to: [{ email: ADMIN_EMAIL }],
|
to: [{ email: ADMIN_EMAIL }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
from: { email: FROM_EMAIL },
|
from: { email: FROM_EMAIL, name: "Pfadi-Bussle Wart" },
|
||||||
subject: `Pfadi Bussle - Buchung ${booking.uuid} eingegangen!`,
|
subject: `Buchung für ${booking.days} eingegangen!`,
|
||||||
content: [{ type: 'text/plain', value: getReceivedBookingText(booking) }],
|
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 {
|
try {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Error } from 'mongoose'
|
|||||||
import { NextApiRequest, NextApiResponse } from 'next'
|
import { NextApiRequest, NextApiResponse } from 'next'
|
||||||
import { BookingDocument } from '../../../db/booking'
|
import { BookingDocument } from '../../../db/booking'
|
||||||
import { createBooking } from '../../../db/index'
|
import { createBooking } from '../../../db/index'
|
||||||
import { sendReceivedBookingMail } from '../../../helpers/mail'
|
import { sendReceivedBookingAdminMail, sendReceivedBookingBookerMail } from '../../../helpers/mail'
|
||||||
|
|
||||||
export default async function userHandler(
|
export default async function userHandler(
|
||||||
req: NextApiRequest,
|
req: NextApiRequest,
|
||||||
@@ -27,8 +27,9 @@ export default async function userHandler(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
await sendReceivedBookingMail(booking)
|
console.log(`received booking ${booking.uuid}`)
|
||||||
console.log('sent receivedBookingMail')
|
await sendReceivedBookingAdminMail(booking)
|
||||||
|
await sendReceivedBookingBookerMail(booking)
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
res.setHeader('Allow', ['POST'])
|
res.setHeader('Allow', ['POST'])
|
||||||
|
|||||||
Reference in New Issue
Block a user