-
Notifications
You must be signed in to change notification settings - Fork 0
fix: handle collective multiple host on destinationCalendar #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: enhance-collective-scheduling-foundation
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -84,7 +84,7 @@ export default class GoogleCalendarService implements Calendar { | |||||||||||||
| }; | ||||||||||||||
| }; | ||||||||||||||
|
|
||||||||||||||
| async createEvent(calEventRaw: CalendarEvent): Promise<NewCalendarEventType> { | ||||||||||||||
| async createEvent(calEventRaw: CalendarEvent, credentialId: number): Promise<NewCalendarEventType> { | ||||||||||||||
| const eventAttendees = calEventRaw.attendees.map(({ id: _id, ...rest }) => ({ | ||||||||||||||
| ...rest, | ||||||||||||||
| responseStatus: "accepted", | ||||||||||||||
|
|
@@ -97,6 +97,10 @@ export default class GoogleCalendarService implements Calendar { | |||||||||||||
| responseStatus: "accepted", | ||||||||||||||
| })) || []; | ||||||||||||||
| return new Promise(async (resolve, reject) => { | ||||||||||||||
| const [mainHostDestinationCalendar] = | ||||||||||||||
| calEventRaw?.destinationCalendar && calEventRaw?.destinationCalendar.length > 0 | ||||||||||||||
| ? calEventRaw.destinationCalendar | ||||||||||||||
| : []; | ||||||||||||||
| const myGoogleAuth = await this.auth.getToken(); | ||||||||||||||
| const payload: calendar_v3.Schema$Event = { | ||||||||||||||
| summary: calEventRaw.title, | ||||||||||||||
|
|
@@ -115,8 +119,8 @@ export default class GoogleCalendarService implements Calendar { | |||||||||||||
| id: String(calEventRaw.organizer.id), | ||||||||||||||
| responseStatus: "accepted", | ||||||||||||||
| organizer: true, | ||||||||||||||
| email: calEventRaw.destinationCalendar?.externalId | ||||||||||||||
| ? calEventRaw.destinationCalendar.externalId | ||||||||||||||
| email: mainHostDestinationCalendar?.externalId | ||||||||||||||
| ? mainHostDestinationCalendar.externalId | ||||||||||||||
| : calEventRaw.organizer.email, | ||||||||||||||
| }, | ||||||||||||||
| ...eventAttendees, | ||||||||||||||
|
|
@@ -138,13 +142,16 @@ export default class GoogleCalendarService implements Calendar { | |||||||||||||
| const calendar = google.calendar({ | ||||||||||||||
| version: "v3", | ||||||||||||||
| }); | ||||||||||||||
| const selectedCalendar = calEventRaw.destinationCalendar?.externalId | ||||||||||||||
| ? calEventRaw.destinationCalendar.externalId | ||||||||||||||
| : "primary"; | ||||||||||||||
| // Find in calEventRaw.destinationCalendar the one with the same credentialId | ||||||||||||||
|
|
||||||||||||||
| const selectedCalendar = calEventRaw.destinationCalendar?.find( | ||||||||||||||
| (cal) => cal.credentialId === credentialId | ||||||||||||||
| )?.externalId; | ||||||||||||||
|
|
||||||||||||||
| calendar.events.insert( | ||||||||||||||
| { | ||||||||||||||
| auth: myGoogleAuth, | ||||||||||||||
| calendarId: selectedCalendar, | ||||||||||||||
| calendarId: selectedCalendar || "primary", | ||||||||||||||
| requestBody: payload, | ||||||||||||||
| conferenceDataVersion: 1, | ||||||||||||||
| sendUpdates: "none", | ||||||||||||||
|
|
@@ -188,6 +195,8 @@ export default class GoogleCalendarService implements Calendar { | |||||||||||||
|
|
||||||||||||||
| async updateEvent(uid: string, event: CalendarEvent, externalCalendarId: string): Promise<any> { | ||||||||||||||
| return new Promise(async (resolve, reject) => { | ||||||||||||||
| const [mainHostDestinationCalendar] = | ||||||||||||||
| event?.destinationCalendar && event?.destinationCalendar.length > 0 ? event.destinationCalendar : []; | ||||||||||||||
| const myGoogleAuth = await this.auth.getToken(); | ||||||||||||||
| const eventAttendees = event.attendees.map(({ ...rest }) => ({ | ||||||||||||||
| ...rest, | ||||||||||||||
|
|
@@ -216,8 +225,8 @@ export default class GoogleCalendarService implements Calendar { | |||||||||||||
| id: String(event.organizer.id), | ||||||||||||||
| organizer: true, | ||||||||||||||
| responseStatus: "accepted", | ||||||||||||||
| email: event.destinationCalendar?.externalId | ||||||||||||||
| ? event.destinationCalendar.externalId | ||||||||||||||
| email: mainHostDestinationCalendar?.externalId | ||||||||||||||
| ? mainHostDestinationCalendar.externalId | ||||||||||||||
| : event.organizer.email, | ||||||||||||||
| }, | ||||||||||||||
| ...(eventAttendees as any), | ||||||||||||||
|
|
@@ -244,7 +253,7 @@ export default class GoogleCalendarService implements Calendar { | |||||||||||||
|
|
||||||||||||||
| const selectedCalendar = externalCalendarId | ||||||||||||||
| ? externalCalendarId | ||||||||||||||
| : event.destinationCalendar?.externalId; | ||||||||||||||
| : event.destinationCalendar?.find((cal) => cal.externalId === externalCalendarId)?.externalId; | ||||||||||||||
|
|
||||||||||||||
| calendar.events.update( | ||||||||||||||
| { | ||||||||||||||
|
|
@@ -303,7 +312,9 @@ export default class GoogleCalendarService implements Calendar { | |||||||||||||
| }); | ||||||||||||||
|
|
||||||||||||||
| const defaultCalendarId = "primary"; | ||||||||||||||
| const calendarId = externalCalendarId ? externalCalendarId : event.destinationCalendar?.externalId; | ||||||||||||||
| const calendarId = externalCalendarId | ||||||||||||||
| ? externalCalendarId | ||||||||||||||
| : event.destinationCalendar?.find((cal) => cal.externalId === externalCalendarId)?.externalId; | ||||||||||||||
|
Comment on lines
+315
to
+317
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: Same circular logic bug as in
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: packages/app-store/googlecalendar/lib/CalendarService.ts
Line: 315:317
Comment:
**logic:** Same circular logic bug as in `updateEvent` - searching by `externalCalendarId` in the find condition will never match
```suggestion
const calendarId = externalCalendarId
? externalCalendarId
: event.destinationCalendar?.[0]?.externalId;
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||||||||||
|
|
||||||||||||||
| calendar.events.delete( | ||||||||||||||
| { | ||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -125,7 +125,8 @@ export default class LarkCalendarService implements Calendar { | |||||
| async createEvent(event: CalendarEvent): Promise<NewCalendarEventType> { | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. syntax: Missing
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: packages/app-store/larkcalendar/lib/CalendarService.ts
Line: 125:125
Comment:
**syntax:** Missing `credentialId` parameter - signature doesn't match the interface `Calendar.createEvent(event, credentialId)` defined in `packages/types/Calendar.d.ts:221`
```suggestion
async createEvent(event: CalendarEvent, credentialId: number): Promise<NewCalendarEventType> {
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||
| let eventId = ""; | ||||||
| let eventRespData; | ||||||
| const calendarId = event.destinationCalendar?.externalId; | ||||||
| const [mainHostDestinationCalendar] = event.destinationCalendar ?? []; | ||||||
| const calendarId = mainHostDestinationCalendar?.externalId; | ||||||
| if (!calendarId) { | ||||||
| throw new Error("no calendar id"); | ||||||
| } | ||||||
|
|
@@ -160,7 +161,8 @@ export default class LarkCalendarService implements Calendar { | |||||
| } | ||||||
|
|
||||||
| private createAttendees = async (event: CalendarEvent, eventId: string) => { | ||||||
| const calendarId = event.destinationCalendar?.externalId; | ||||||
| const [mainHostDestinationCalendar] = event.destinationCalendar ?? []; | ||||||
| const calendarId = mainHostDestinationCalendar?.externalId; | ||||||
| if (!calendarId) { | ||||||
| this.log.error("no calendar id provided in createAttendees"); | ||||||
| throw new Error("no calendar id provided in createAttendees"); | ||||||
|
|
@@ -187,7 +189,8 @@ export default class LarkCalendarService implements Calendar { | |||||
| async updateEvent(uid: string, event: CalendarEvent, externalCalendarId?: string) { | ||||||
| const eventId = uid; | ||||||
| let eventRespData; | ||||||
| const calendarId = externalCalendarId || event.destinationCalendar?.externalId; | ||||||
| const [mainHostDestinationCalendar] = event.destinationCalendar ?? []; | ||||||
| const calendarId = externalCalendarId || mainHostDestinationCalendar?.externalId; | ||||||
| if (!calendarId) { | ||||||
| this.log.error("no calendar id provided in updateEvent"); | ||||||
| throw new Error("no calendar id provided in updateEvent"); | ||||||
|
|
@@ -231,7 +234,8 @@ export default class LarkCalendarService implements Calendar { | |||||
| * @returns | ||||||
| */ | ||||||
| async deleteEvent(uid: string, event: CalendarEvent, externalCalendarId?: string) { | ||||||
| const calendarId = externalCalendarId || event.destinationCalendar?.externalId; | ||||||
| const [mainHostDestinationCalendar] = event.destinationCalendar ?? []; | ||||||
| const calendarId = externalCalendarId || mainHostDestinationCalendar?.externalId; | ||||||
| if (!calendarId) { | ||||||
| this.log.error("no calendar id provided in deleteEvent"); | ||||||
| throw new Error("no calendar id provided in deleteEvent"); | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -70,9 +70,10 @@ export default class Office365CalendarService implements Calendar { | |||||
| } | ||||||
|
|
||||||
| async createEvent(event: CalendarEvent): Promise<NewCalendarEventType> { | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. syntax: Missing
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: packages/app-store/office365calendar/lib/CalendarService.ts
Line: 72:72
Comment:
**syntax:** Missing `credentialId` parameter - signature doesn't match the interface `Calendar.createEvent(event, credentialId)` defined in `packages/types/Calendar.d.ts:221`
```suggestion
async createEvent(event: CalendarEvent, credentialId: number): Promise<NewCalendarEventType> {
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||
| const [mainHostDestinationCalendar] = event.destinationCalendar ?? []; | ||||||
| try { | ||||||
| const eventsUrl = event.destinationCalendar?.externalId | ||||||
| ? `/me/calendars/${event.destinationCalendar?.externalId}/events` | ||||||
| const eventsUrl = mainHostDestinationCalendar?.externalId | ||||||
| ? `/me/calendars/${mainHostDestinationCalendar?.externalId}/events` | ||||||
| : "/me/calendar/events"; | ||||||
|
|
||||||
| const response = await this.fetcher(eventsUrl, { | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Circular logic bug - when
externalCalendarIdis provided, the fallback searches for a calendar with the sameexternalCalendarId, which will never match. Should search bycredentialIdinstead or just use the provided valuePrompt To Fix With AI