fix: handle collective multiple host on destinationCalendar#3
Conversation
|
Claude finished @ShashankFC's task in 2m 58s —— View job Code Review CompleteI've reviewed the PR changes that refactor Critical Issues1. Potential Null Pointer Exception in EventManager.ts:119Location: const [mainHostDestinationCalendar] = evt.destinationCalendar ?? [];
if (evt.location === MeetLocationType && mainHostDestinationCalendar.integration !== "google_calendar") {Issue: When Fix: Add a null check: if (evt.location === MeetLocationType && mainHostDestinationCalendar?.integration !== "google_calendar") {2. Incorrect Logic in Google Calendar Service deleteEventLocation: const calendarId = externalCalendarId
? externalCalendarId
: event.destinationCalendar?.find((cal) => cal.externalId === externalCalendarId)?.externalId;Issue: This logic is circular - if Fix: Should likely be: const calendarId = externalCalendarId
? externalCalendarId
: event.destinationCalendar?.[0]?.externalId;3. Similar Issue in updateEventLocation: Same circular logic problem exists in High Priority Issues4. Type Safety Issue with destinationCalendarLocation: destinationCalendar?: DestinationCalendar[] | null;Issue: Using both Recommendation: Standardize to either 5. Missing Null Safety in handleNewBooking.tsLocation: if (isTeamEventType && eventType.schedulingType === "COLLECTIVE") {
evt.destinationCalendar?.push(...teamDestinationCalendars);
}Issue: If Fix: Ensure destinationCalendar is initialized: if (isTeamEventType && eventType.schedulingType === "COLLECTIVE") {
if (!evt.destinationCalendar) evt.destinationCalendar = [];
evt.destinationCalendar.push(...teamDestinationCalendars);
}Medium Priority Issues6. Inconsistent credentialId ParameterLocation: async createEvent(calEventRaw: CalendarEvent, credentialId: number): Promise<NewCalendarEventType>Issue: The createEvent(event: CalendarEvent, credentialId: number): Promise<NewCalendarEventType>;Concern: This signature change affects all calendar integrations. Verify that:
7. Database Query in LoopLocation: for (const destination of event.destinationCalendar) {
if (destination.credentialId) {
let credential = this.calendarCredentials.find((c) => c.id === destination.credentialId);
if (!credential) {
const credentialFromDB = await prisma.credential.findUnique({ ... });
// ...
}
}
}Issue: This queries the database inside a loop, which is inefficient for collective events with many hosts. Recommendation: Batch fetch all missing credentials: const missingCredentialIds = event.destinationCalendar
.map(d => d.credentialId)
.filter(id => id && !this.calendarCredentials.find(c => c.id === id));
const credentialsFromDB = await prisma.credential.findMany({
where: { id: { in: missingCredentialIds } },
include: { app: { select: { slug: true } } }
});Code Quality Issues8. Typo Fix Already IncludedLocation: Good catch fixing 9. Empty firstName/lastName FieldsLocation: firstName: "",
lastName: "",Issue: These fields are added but always set to empty strings. Either populate them properly or remove them. 10. Duplicate Check RemovedLocation: The duplicate Testing RecommendationsThis is a significant refactoring that touches critical booking flows. Ensure testing covers:
SummaryPositives:
Must Fix Before Merge:
Recommend Addressing: | Branch |
|
This PR is being marked as stale due to inactivity. |
Test 4nn---nReplicated from ai-code-review-evaluation/cal.com-greptile#4