Update CalendarService.ts

feat/calendar-cache-inbound
zomars 2023-10-20 16:27:32 -07:00
parent 7282557358
commit 5c14a23b36
1 changed files with 4 additions and 11 deletions

View File

@ -557,13 +557,15 @@ export default class GoogleCalendarService implements Calendar {
return res.data;
}
async unwatchCalendar({ calendarId }: { calendarId: string }) {
const credentialId = this.credential.id;
const sc = await prisma.selectedCalendar.findFirst({
where: {
credentialId: this.credential.id,
credentialId,
externalId: calendarId,
},
});
await handleCacheClear(sc?.credentialId);
// Delete the calendar cache to force a fresh cache
await prisma.calendarCache.deleteMany({ where: { credentialId } });
const parsedData = watchCalendarSchema.safeParse(sc?.metadata);
if (!parsedData.success) {
logger.info("Skipped unwatchCalendar due to missing metadata");
@ -596,12 +598,3 @@ class MyGoogleAuth extends google.auth.OAuth2 {
return super.refreshToken(token);
}
}
async function handleCacheClear(credentialId?: number | null) {
if (!credentialId) {
logger.info(`Skipped unwatchCalendar due to missing credentialId in selectedCalendar`);
return;
}
// Delete the cache for this calendar to force a fresh cache
await prisma.calendarCache.deleteMany({ where: { credentialId } });
}