Skip to content

Commit 570520f

Browse files
committed
fix(calendar): use events.patch instead of events.update to preserve all event fields
The updateEvent method used events.update (PUT), which replaces the entire event resource. Any field not explicitly included in the request body gets wiped -- including summary, description, reminders, colorId, visibility, recurrence, attachments, and conferenceData. Critically, it also rejects non-default eventTypes (Focus Time, Out of Office, Working Location) with Event type cannot be changed because omitting eventType is interpreted as changing it to default. Switch to events.patch (PATCH), which only modifies the fields present in the request body and preserves everything else. This is the correct HTTP semantics for partial updates and matches the methods documented intent (patch semantics comment was already in the code). Fixes updating Focus Time, Out of Office, and Working Location events. Also fixes data loss when updating any event with only a subset of fields (e.g., changing only the time without re-specifying the title). Ref: https://developers.google.com/calendar/api/v3/reference/events/patch
1 parent d84d394 commit 570520f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

workspace-server/src/services/CalendarService.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ export class CalendarService {
724724
try {
725725
const calendar = await this.getCalendar();
726726

727-
// Build request body with only the fields to update (patch semantics)
727+
// Build request body with only the fields to update (true patch semantics)
728728
const requestBody: calendar_v3.Schema$Event = {};
729729
if (summary !== undefined) requestBody.summary = summary;
730730
if (description !== undefined) requestBody.description = description;
@@ -733,19 +733,24 @@ export class CalendarService {
733733
if (attendees)
734734
requestBody.attendees = attendees.map((email) => ({ email }));
735735

736-
const updateParams: calendar_v3.Params$Resource$Events$Update = {
736+
const patchParams: calendar_v3.Params$Resource$Events$Patch = {
737737
calendarId: finalCalendarId,
738738
eventId,
739739
requestBody,
740740
};
741741
this.applyMeetAndAttachments(
742742
requestBody,
743-
updateParams,
743+
patchParams as calendar_v3.Params$Resource$Events$Update,
744744
addGoogleMeet,
745745
attachments,
746746
);
747747

748-
const res = await calendar.events.update(updateParams);
748+
// Use events.patch (not events.update) so only specified fields are modified.
749+
// events.update (PUT) replaces the entire event, which wipes unspecified fields
750+
// like summary, description, reminders, colorId, visibility, and — critically —
751+
// rejects non-default eventTypes (Focus Time, Out of Office, Working Location)
752+
// with "Event type cannot be changed."
753+
const res = await calendar.events.patch(patchParams);
749754

750755
logToFile(`Successfully updated event: ${res.data.id}`);
751756
return {

0 commit comments

Comments
 (0)