Skip to content

Commit

Permalink
Sending email on successful appointment booking requests
Browse files Browse the repository at this point in the history
  • Loading branch information
ad956 committed Jun 6, 2024
1 parent 0b055bb commit b9b5bf3
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions app/api/patient/appointment/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit b9b5bf3

Please sign in to comment.