-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sending email on successful appointment booking requests
- Loading branch information
Showing
1 changed file
with
33 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,15 @@ import dbConfig from "@lib/db"; | |
import { bookingAppointment } from "@/types"; | ||
import { decrypt } from "@sessions/sessionUtils"; | ||
import { ObjectId } from "mongodb"; | ||
import { sendEmail } from "@lib/email"; | ||
import { render } from "@react-email/render"; | ||
import { AppointmentBookedTemplate } from "@lib/emails/templates"; | ||
|
||
interface BookingAppointmentType { | ||
bookingAppointment: bookingAppointment; | ||
transaction_id: string | null; | ||
appointment_charge: string; | ||
} | ||
|
||
// getting patients approved appointments | ||
export async function GET(request: Request) { | ||
|
@@ -78,9 +87,13 @@ export async function POST(req: Request) { | |
} | ||
|
||
try { | ||
const body: bookingAppointment = await req.json(); | ||
const { | ||
bookingAppointment, | ||
transaction_id, | ||
appointment_charge, | ||
}: BookingAppointmentType = await req.json(); | ||
|
||
const { date, state, city, hospital, disease, note } = body; | ||
const { date, state, city, hospital, disease, note } = bookingAppointment; | ||
|
||
const token = session.split("Bearer ")[1]; | ||
const decryptedUser = await decrypt(token); | ||
|
@@ -119,6 +132,24 @@ export async function POST(req: Request) { | |
error: "Error saving appointment info", | ||
}); | ||
|
||
await sendEmail({ | ||
to: email || "[email protected]", | ||
subject: `Your Appointment Request Has Been Received`, | ||
html: render( | ||
AppointmentBookedTemplate({ | ||
name: `${patient.firstname} ${patient.lastname}`, | ||
email, | ||
bookingAppointment, | ||
transaction_id, | ||
appointment_charge, | ||
}) | ||
), | ||
from: { | ||
name: "Patient Fitness Tracker", | ||
address: "[email protected]", | ||
}, | ||
}); | ||
|
||
return Response.json( | ||
{ | ||
msg: "Appointment request added successfully", | ||
|