Skip to content

Commit

Permalink
more debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
abdulhdr1 committed Mar 14, 2024
1 parent fdb6463 commit 5ea95db
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 36 deletions.
38 changes: 21 additions & 17 deletions packages/api/src/appointments/getTherapistAndPatient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,25 @@ export async function getTherapistAndPatient({
prisma: TrpcContext["prisma"];
appointment: Appointment;
}): Promise<[Therapist & { address: Address | null }, Patient]> {
const [therapist, patient] = await Promise.all([
prisma.therapist.findUniqueOrThrow({
where: {
id: appointment.therapistId,
},
include: {
address: true,
},
}),
prisma.patient.findUniqueOrThrow({
where: {
id: appointment.patientId,
},
}),
]);

return [therapist, patient];
try {
const [therapist, patient] = await Promise.all([
prisma.therapist.findUniqueOrThrow({
where: {
id: appointment.therapistId,
},
include: {
address: true,
},
}),
prisma.patient.findUniqueOrThrow({
where: {
id: appointment.patientId,
},
}),
]);
return [therapist, patient];
} catch (error) {
console.error("Error fetching therapist and patient", error);
throw new Error("Error fetching therapist and patient");
}
}
42 changes: 24 additions & 18 deletions packages/api/src/helpers/createAppointmentInCalendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,34 @@ export const createAppointmentInCalendar = async ({
prisma,
appointment,
});
const therapistUser = await getUser(therapist.userId);

const modality =
appointment.modality === "ONLINE" ? "online" : "presencial";
const therapistPronoun = therapist.gender === "MALE" ? "o" : "a";
try {
const therapistUser = await getUser(therapist.userId);

const requestBody = makeRequestBody(
patient,
therapist,
modality,
therapistPronoun,
appointment,
String(therapistUser.emailAddresses[0]?.emailAddress),
);
const modality =
appointment.modality === "ONLINE" ? "online" : "presencial";
const therapistPronoun = therapist.gender === "MALE" ? "o" : "a";

const newAppointment = await calendar.events.insert({
calendarId: "primary",
conferenceDataVersion: 1,
requestBody,
});
const requestBody = makeRequestBody(
patient,
therapist,
modality,
therapistPronoun,
appointment,
String(therapistUser.emailAddresses[0]?.emailAddress),
);

const newAppointment = await calendar.events.insert({
calendarId: "primary",
conferenceDataVersion: 1,
requestBody,
});

return newAppointment;
return newAppointment;
} catch (error) {
console.error("Error fetching therapist user", error);
throw new Error("Error fetching therapist user");
}
};

const appointmentTypeToEmoji: {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/router/appointments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ export const appointmentsRouter = createTRPCRouter({
});
} catch (e) {
console.error("Error updating appointment");
console.error(JSON.stringify(e, null, 2));
console.error(e);
console.error(JSON.stringify(input, null, 2));
throw e;
}
Expand Down

0 comments on commit 5ea95db

Please sign in to comment.