mirror of
https://github.com/hanzoai/calendar.git
synced 2026-09-24 22:42:24 +00:00
Co-authored-by: Alex van Andel <[email protected]> Co-authored-by: Morgan <[email protected]> Co-authored-by: Morgan Vernay <[email protected]> Co-authored-by: Omar López <[email protected]>
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import prisma from "@calcom/prisma";
|
|
|
|
/**
|
|
* Will update all the selected calendars with the same userId, integration and externalId including user-level and event-type-level calendars with new credentialId
|
|
*/
|
|
export async function renewSelectedCalendarCredentialId(
|
|
selectedCalendarWhereUnique: {
|
|
userId: number;
|
|
integration: string;
|
|
externalId: string;
|
|
},
|
|
credentialId: number
|
|
): Promise<boolean> /* True if renewed, false if not */ {
|
|
// There could be multiple calendars because same combination could be used across multiple events as event-type-level calendars
|
|
const selectedCalendars = await prisma.selectedCalendar.findMany({
|
|
where: {
|
|
...selectedCalendarWhereUnique,
|
|
credentialId: null,
|
|
},
|
|
});
|
|
|
|
if (!selectedCalendars.length) return false;
|
|
|
|
await prisma.selectedCalendar.updateMany({
|
|
where: {
|
|
id: {
|
|
in: selectedCalendars.map((selectedCalendar) => selectedCalendar.id),
|
|
},
|
|
},
|
|
data: {
|
|
credentialId: credentialId,
|
|
},
|
|
});
|
|
|
|
return true;
|
|
}
|