Skip to content

Comments

:sparkles feat(sub-calendars): use event schema WIP#1163

Closed
victor-enogwe wants to merge 5 commits intomainfrom
feat-use-new-event-schema-1138
Closed

:sparkles feat(sub-calendars): use event schema WIP#1163
victor-enogwe wants to merge 5 commits intomainfrom
feat-use-new-event-schema-1138

Conversation

@victor-enogwe
Copy link
Contributor

What does this PR do?

This PR migrates the codebase to use the new event's schema with sub-calendar support.

Use Case

closes #1135

Copilot AI review requested due to automatic review settings October 24, 2025 05:38
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR migrates the codebase to use a new event schema that supports sub-calendars, moving away from user-based event organization to a calendar-based approach. The changes consolidate event-related types and update import paths to reflect the new schema structure.

Key changes:

  • Migrated Categories_Event and related enums from @core/types/event.types to @web/common/types/web.event.types
  • Updated event date handling to use native Date objects instead of string-based date formats
  • Removed several deprecated types and utility functions related to the old event schema
  • Updated import paths across the codebase to reflect the new type locations

Reviewed Changes

Copilot reviewed 168 out of 168 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/web/src/common/types/web.event.types.ts Defined Categories_Event enum and updated schema definitions for web events
packages/core/src/types/event.types.ts Removed Categories_Event enum and consolidated event schemas with calendar support
packages/web/src/views/Forms/EventForm/DateControlsSection/RecurrenceSection/useRecurrence/useRecurrence.ts Updated to use Date objects instead of string-based dates
packages/core/src/util/event/event.util.ts Removed deprecated date parsing functions and updated event categorization logic
packages/core/src/mappers/map.event.ts Simplified mapper to remove provider data methods and consolidate metadata handling
packages/backend/src/user/services/user.service.ts Updated user service methods to use ObjectId instead of strings
packages/scripts/src/migrations/*.ts Updated migration scripts to use new event schema

Event_Core,
Schema_Event,
} from "@core/types/event.types";
import { Event_Core, Schema_Event } from "@core/types/event.types";
Copy link

Copilot AI Oct 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function references EventSchema but it's not imported. This will cause a runtime error. Import EventSchema from @core/types/event.types.

Suggested change
import { Event_Core, Schema_Event } from "@core/types/event.types";
import { Event_Core, Schema_Event, EventSchema } from "@core/types/event.types";

Copilot uses AI. Check for mistakes.
Comment on lines +138 to 139
const dbUser = await mongoService.user.findOne({ _id });
const events = this.#generateEvents(userId);
Copy link

Copilot AI Oct 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable userId is used but never defined. It should be _id.toString() or the result should be assigned to a userId variable after line 138.

Copilot uses AI. Check for mistakes.
);

await userService.saveTimeFor("lastLoggedInAt", userId);
await userService.updateLastLoggedInTime("lastLoggedInAt", userId);
Copy link

Copilot AI Oct 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method signature appears incorrect. Based on the changes in user.service.ts, updateLastLoggedInTime now takes only one parameter (userId as ObjectId), but here it's called with two string parameters.

Suggested change
await userService.updateLastLoggedInTime("lastLoggedInAt", userId);
await userService.updateLastLoggedInTime(mongoService.objectId(userId));

Copilot uses AI. Check for mistakes.
for (const user of users) {
const userId = user?._id.toString();
const summary = await userService.deleteCompassDataForUser(userId);
const summary = await userService.deleteCompassDataForUser(user._id);
Copy link

Copilot AI Oct 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user._id field is already an ObjectId from the database query, but the iteration variable user shadows the outer scope user parameter (which is a string). This creates confusion. Consider renaming the loop variable to dbUser for clarity.

Copilot uses AI. Check for mistakes.
@victor-enogwe victor-enogwe force-pushed the feat-use-new-event-schema-1138 branch 2 times, most recently from 9bafc94 to 085f0ae Compare October 26, 2025 08:44
Copilot AI review requested due to automatic review settings October 26, 2025 08:44
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 184 out of 184 changed files in this pull request and generated 29 comments.

Comments suppressed due to low confidence (1)

packages/backend/src/sync/services/sync/tests/compass.sync.processor.all-event.test.ts:1

  • More references to removed properties: gRecurringEventId, gEventId, and user that need to be updated to use the new metadata structure (metadata.recurringEventId, metadata.id) and calendar-based associations.
import { ObjectId } from "mongodb";


const userId = (await this.#findUserOrThrow(user!))._id.toString();
const dbUser = await mongoService.user.findOne({ _id });
const events = this.#generateEvents(userId);
Copy link

Copilot AI Oct 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable userId is used on line 139 but is no longer defined after the changes. The code now uses _id and dbUser, but userId needs to be extracted from one of these. This will cause a ReferenceError.

Suggested change
const events = this.#generateEvents(userId);
const events = this.#generateEvents(dbUser._id.toString());

Copilot uses AI. Check for mistakes.
summary: "New Standalone Event",
});
const processor = new GcalSyncProcessor(user._id.toString());
const processor = new GcalEventsSyncProcessor(user._id.toString());
Copy link

Copilot AI Oct 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constructor signature changed to accept a calendar object instead of a user ID string. This call should pass a calendar object but is still passing user._id.toString(). This will cause a type error.

Copilot uses AI. Check for mistakes.

/* Act */
const processor = new GcalSyncProcessor(user._id.toString());
const processor = new GcalEventsSyncProcessor(user._id.toString());
Copy link

Copilot AI Oct 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constructor signature changed to accept a calendar object, but this is still passing a user ID string. This needs to be updated to pass a calendar object consistent with the new architecture.

Suggested change
const processor = new GcalEventsSyncProcessor(user._id.toString());
const processor = new GcalEventsSyncProcessor(calendar);

Copilot uses AI. Check for mistakes.

/* Act */
const processor = new GcalSyncProcessor(user._id.toString());
const processor = new GcalEventsSyncProcessor(user._id.toString());
Copy link

Copilot AI Oct 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiple instances where GcalEventsSyncProcessor is constructed with a user ID string instead of a calendar object. All these need to be updated to match the new constructor signature.

Copilot uses AI. Check for mistakes.
};

const processor = new GcalSyncProcessor(user._id.toString());
const processor = new GcalEventsSyncProcessor(user._id.toString());
Copy link

Copilot AI Oct 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiple instances where GcalEventsSyncProcessor is constructed with a user ID string instead of a calendar object. All these need to be updated to match the new constructor signature.

Suggested change
const processor = new GcalEventsSyncProcessor(user._id.toString());
const calendar = await CalendarDriver.getByUserId(user._id);
const processor = new GcalEventsSyncProcessor(calendar);

Copilot uses AI. Check for mistakes.
_getGcal(user, instanceUpdate!.gRecurringEventId!),
EventDriver.getGCalEvent(
user,
instanceUpdate!.gRecurringEventId!,
Copy link

Copilot AI Oct 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More references to removed properties: gRecurringEventId, gEventId, and user that need to be updated to use the new metadata structure (metadata.recurringEventId, metadata.id) and calendar-based associations.

Copilot uses AI. Check for mistakes.
newInstances.map((instance) =>
expect(_getGcal(user, instance.gEventId!)).rejects.toThrow(
expect(
EventDriver.getGCalEvent(user, instance.gEventId!),
Copy link

Copilot AI Oct 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More references to removed properties: gRecurringEventId, gEventId, and user that need to be updated to use the new metadata structure (metadata.recurringEventId, metadata.id) and calendar-based associations.

Copilot uses AI. Check for mistakes.
gcalInstances.map(() =>
expect.objectContaining({
recurringEventId: event!.gEventId,
recurringEventId: event.metadata?.id,
Copy link

Copilot AI Oct 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More references to removed properties: gRecurringEventId, gEventId, and user that need to be updated to use the new metadata structure (metadata.recurringEventId, metadata.id) and calendar-based associations.

Suggested change
recurringEventId: event.metadata?.id,
recurringEventId: event.metadata?.recurringEventId,

Copilot uses AI. Check for mistakes.
_getGcal(updatedPayload.user!, updatedPayload.gEventId!),
EventDriver.getGCalEvent(
updatedPayload.user!,
updatedPayload.gEventId!,
Copy link

Copilot AI Oct 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More references to removed properties: gRecurringEventId, gEventId, and user that need to be updated to use the new metadata structure (metadata.recurringEventId, metadata.id) and calendar-based associations.

Copilot uses AI. Check for mistakes.
instances.map((instance) =>
expect(
_getGcal(instance.user!, instance.gEventId!),
EventDriver.getGCalEvent(instance.user!, instance.gEventId!),
Copy link

Copilot AI Oct 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More references to removed properties: gRecurringEventId, gEventId, and user that need to be updated to use the new metadata structure (metadata.recurringEventId, metadata.id) and calendar-based associations.

Copilot uses AI. Check for mistakes.
@victor-enogwe victor-enogwe force-pushed the feat-use-new-event-schema-1138 branch from 085f0ae to d0b6831 Compare October 29, 2025 01:53
Copilot AI review requested due to automatic review settings October 30, 2025 13:24
@victor-enogwe victor-enogwe force-pushed the feat-use-new-event-schema-1138 branch from d0b6831 to 36abb72 Compare October 30, 2025 13:24
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 104 out of 194 changed files in this pull request and generated 9 comments.

const events = await getEventsInDb({ calendar: calendar._id, isSomeday });
const typeFilter = type === "ALLDAY" ? isAllDay : isInstance;
const instanceEvents = events.filter(isInstance).filter(typeFilter);
console.log("Events:", events.filter(isInstance));
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove debug console.log statement from production code

Suggested change
console.log("Events:", events.filter(isInstance));

Copilot uses AI. Check for mistakes.
const updateChanges = await CompassSyncProcessor.processEvents([
{
payload: updatedPayload as CompassThisEvent["payload"],
payload,
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The payload should be updatedPayload instead of the original payload to match the test's intent of updating the priority field

Suggested change
payload,
payload: updatedPayload,

Copilot uses AI. Check for mistakes.
const updateChanges = await CompassSyncProcessor.processEvents([
{
payload: updatedPayload as CompassThisEvent["payload"],
payload,
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The payload should be updatedPayload instead of the original payload to match the test's intent of updating the endDate field

Suggested change
payload,
payload: updatedPayload,

Copilot uses AI. Check for mistakes.
const calendar = await CalendarDriver.getRandomUserCalendar(_user._id);
const isSomeday = false;
const recurrence = { rule: ["RRULE:FREQ=WEEKLY;COUNT=10"] };
const payload = createMockBaseEvent({ isSomeday, user, recurrence });
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter should be calendar: calendar._id instead of user to match the updated API signature

Suggested change
const payload = createMockBaseEvent({ isSomeday, user, recurrence });
const payload = createMockBaseEvent({ isSomeday, calendar: calendar._id, recurrence });

Copilot uses AI. Check for mistakes.
// check that event is deleted in db
await expect(
eventService.readById(user, deletedInstanceId),
eventService.readById(calendar, deletedInstanceId),
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first parameter should be calendar._id instead of calendar to match the service's expected signature

Suggested change
eventService.readById(calendar, deletedInstanceId),
eventService.readById(calendar._id, deletedInstanceId),

Copilot uses AI. Check for mistakes.
const updateChanges = await CompassSyncProcessor.processEvents([
{
payload: updatedPayload as CompassAllEvents["payload"],
user: _user._id,
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This field should not be present in the event payload as it's now handled through the calendar parameter

Suggested change
user: _user._id,

Copilot uses AI. Check for mistakes.
const status = CompassEventStatus.CONFIRMED;
const _user = await AuthDriver.googleSignup();
const calendar = await CalendarDriver.getRandomUserCalendar(user._id);
const status = EventStatus.CONFIRMED;
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The status variable is declared but not used in the test. Either use it or remove the declaration

Suggested change
const status = EventStatus.CONFIRMED;

Copilot uses AI. Check for mistakes.
const user = _user._id.toString();
const status = CompassEventStatus.CONFIRMED;
const _user = await AuthDriver.googleSignup();
const calendar = await CalendarDriver.getRandomUserCalendar(user._id);
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable should be _user._id instead of user._id to match the declared variable name

Suggested change
const calendar = await CalendarDriver.getRandomUserCalendar(user._id);
const calendar = await CalendarDriver.getRandomUserCalendar(_user._id);

Copilot uses AI. Check for mistakes.
Comment on lines 1788 to 1791
const calendar = await CalendarDriver.getRandomUserCalendar(user._id);
const status = EventStatus.CONFIRMED;
const recurrence = { rule: ["RRULE:FREQ=WEEKLY;COUNT=10"] };
const payload = createMockBaseEvent({ recurrence, user });
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter should be calendar: calendar._id instead of user to match the updated API signature

Suggested change
const calendar = await CalendarDriver.getRandomUserCalendar(user._id);
const status = EventStatus.CONFIRMED;
const recurrence = { rule: ["RRULE:FREQ=WEEKLY;COUNT=10"] };
const payload = createMockBaseEvent({ recurrence, user });
const calendar = await CalendarDriver.getRandomUserCalendar(_user._id);
const status = EventStatus.CONFIRMED;
const recurrence = { rule: ["RRULE:FREQ=WEEKLY;COUNT=10"] };
const payload = createMockBaseEvent({ recurrence, calendar: calendar._id });

Copilot uses AI. Check for mistakes.
@victor-enogwe victor-enogwe force-pushed the feat-use-new-event-schema-1138 branch from 36abb72 to d27d482 Compare November 2, 2025 22:22
Copilot AI review requested due to automatic review settings November 3, 2025 13:11
@victor-enogwe victor-enogwe force-pushed the feat-use-new-event-schema-1138 branch from d27d482 to 20e53cb Compare November 3, 2025 13:11
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 103 out of 256 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

packages/backend/src/sync/services/sync/tests/compass-sync-processor-this-event/instance.test.ts:1

  • Debug console.log statement should be removed from production code. This appears to be leftover debug code that should be cleaned up.
import { faker } from "@faker-js/faker";

Comment on lines +423 to +424
`
ImportAllEvents completed for calendar(${calendar._id.toString()}).
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The template literal has an unnecessary leading newline character. The backtick should be placed directly after the opening parenthesis for better code formatting.

Suggested change
`
ImportAllEvents completed for calendar(${calendar._id.toString()}).
`ImportAllEvents completed for calendar(${calendar._id.toString()}).

Copilot uses AI. Check for mistakes.
@victor-enogwe
Copy link
Contributor Author

Closing PR until we pick it up again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update Event Schema and Collection for Multi-Calendar & Multi-Provider Support

1 participant