Skip to content

Commit

Permalink
store invitee too
Browse files Browse the repository at this point in the history
  • Loading branch information
Juanito98 committed Nov 4, 2024
1 parent d7f1719 commit df458c9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
12 changes: 6 additions & 6 deletions src/lib/calendly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,12 @@ export async function getAvailabilities({
}
}

export async function getEvent({
export async function getEventOrInvitee({
token,
eventUri,
url,
}: {
token: string;
eventUri: string;
url: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
}): Promise<any> {
const options = {
Expand All @@ -216,14 +216,14 @@ export async function getEvent({
Authorization: `Bearer ${token}`,
},
};
const response = await fetch(eventUri, options);
const response = await fetch(url, options);
if (response.status === 429) {
throw Error("Calendly RareLimit");
}
const json = await response.json();
if (response.status !== 200) {
console.error("calendly.getEvent", json);
throw Error("calendly.getEvent");
console.error("calendly.getEventOrInvitee", json);
throw Error("calendly.getEventOrInvitee");
}

return json.resource;
Expand Down
14 changes: 10 additions & 4 deletions src/pages/api/mentoria/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ScheduleMentoriaResponse,
ScheduleMentoriaRequestSchema,
} from "@/types/mentorias.schema";
import { getEvent } from "@/lib/calendly";
import { getEventOrInvitee } from "@/lib/calendly";
import { getAccessToken } from "@/lib/oauth";
import { OauthProvider } from "@prisma/client";

Expand All @@ -28,14 +28,20 @@ async function scheduleMentoriaHandler(

let meetingTime = meetingTimeOpt || null;
try {
const eventPayload = await getEvent({
token: await getAccessToken(volunteerAuthId, OauthProvider.CALENDLY),
eventUri: calendlyPayload.event.uri,
const token = await getAccessToken(volunteerAuthId, OauthProvider.CALENDLY);
const eventPayload = await getEventOrInvitee({
token,
url: calendlyPayload.event.uri,
});
calendlyPayload.event = eventPayload;
if (eventPayload.start_time) {
meetingTime = eventPayload.start_time;
}
const inviteePayload = await getEventOrInvitee({
token,
url: calendlyPayload.invitee.uri,
});
calendlyPayload.invitee = inviteePayload;
} catch (e) {
console.error(e);
}
Expand Down

0 comments on commit df458c9

Please sign in to comment.