Attach credential id to destinationCalendar records (#3197)
This commit is contained in:
1 parent
2cbf46a323
commit
201d17264c
8 files changed
+31
-1
No files matched your search
@@ -337,6 +337,7 @@ export default class GoogleCalendarService implements Calendar {
|
||||
integration: this.integrationName,
|
||||
name: cal.summary ?? "No name",
|
||||
primary: cal.primary ?? false,
|
||||
readOnly: !(cal.accessRole === "reader" || cal.accessRole === "owner") && true,
|
||||
};
|
||||
return calendar;
|
||||
}) || []
|
||||
|
||||
@@ -177,6 +177,7 @@ export default class Office365CalendarService implements Calendar {
|
||||
integration: this.integrationName,
|
||||
name: cal.name ?? "No calendar name",
|
||||
primary: cal.isDefaultCalendar ?? false,
|
||||
readOnly: !cal.canEdit && true,
|
||||
};
|
||||
return calendar;
|
||||
});
|
||||
|
||||
@@ -46,6 +46,7 @@ export const getConnectedCalendars = async (
|
||||
...cal,
|
||||
primary: cal.primary || null,
|
||||
isSelected: selectedCalendars.some((selected) => selected.externalId === cal.externalId),
|
||||
credentialId,
|
||||
}))
|
||||
.sortBy(["primary"])
|
||||
.value();
|
||||
|
||||
@@ -282,6 +282,18 @@ export default class EventManager {
|
||||
/** Can I use destinationCalendar here? */
|
||||
/* How can I link a DC to a cred? */
|
||||
if (event.destinationCalendar) {
|
||||
if (event.destinationCalendar.credentialId) {
|
||||
const credential = await prisma.credential.findFirst({
|
||||
where: {
|
||||
id: event.destinationCalendar.credentialId,
|
||||
},
|
||||
});
|
||||
|
||||
if (credential) {
|
||||
return [await createEvent(credential, event)];
|
||||
}
|
||||
}
|
||||
|
||||
const destinationCalendarCredentials = this.calendarCredentials.filter(
|
||||
(c) => c.type === event.destinationCalendar?.integration
|
||||
);
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "DestinationCalendar" ADD COLUMN "credentialId" INTEGER;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "DestinationCalendar" ADD CONSTRAINT "DestinationCalendar_credentialId_fkey" FOREIGN KEY ("credentialId") REFERENCES "Credential"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
@@ -89,6 +89,7 @@ model Credential {
|
||||
app App? @relation(fields: [appId], references: [slug], onDelete: Cascade)
|
||||
// How to make it a required column?
|
||||
appId String?
|
||||
destinationCalendars DestinationCalendar[]
|
||||
}
|
||||
|
||||
enum UserPlan {
|
||||
@@ -113,6 +114,8 @@ model DestinationCalendar {
|
||||
bookingId Int? @unique
|
||||
eventType EventType? @relation(fields: [eventTypeId], references: [id])
|
||||
eventTypeId Int? @unique
|
||||
credentialId Int?
|
||||
credential Credential? @relation(fields: [credentialId], references: [id])
|
||||
}
|
||||
|
||||
enum UserPermissionRole {
|
||||
|
||||
Vendored
+1
@@ -146,6 +146,7 @@ export interface AdditionalInformation {
|
||||
export interface IntegrationCalendar extends Ensure<Partial<SelectedCalendar>, "externalId"> {
|
||||
primary?: boolean;
|
||||
name?: string;
|
||||
readOnly?: boolean;
|
||||
}
|
||||
|
||||
export interface Calendar {
|
||||
|
||||
Reference in new issue
Block a user