From 795fd788e2263d872edd9095d8f9887ca7674ff8 Mon Sep 17 00:00:00 2001 From: Somay Chauhan Date: Fri, 20 Jun 2025 12:53:18 +0530 Subject: [PATCH] feat: add response status to calendar event host details (#21934) * feat: add response status to calendar event host details * docs: update calendar event response status description from attendee to host --- .../outputs/get-unified-calendar-event.ts | 12 ++++++ .../get-calendar-event-details-output-pipe.ts | 40 +++++++++---------- apps/api/v2/swagger/documentation.json | 7 +++- docs/api-reference/v2/openapi.json | 7 +++- 4 files changed, 44 insertions(+), 22 deletions(-) diff --git a/apps/api/v2/src/modules/cal-unified-calendars/outputs/get-unified-calendar-event.ts b/apps/api/v2/src/modules/cal-unified-calendars/outputs/get-unified-calendar-event.ts index a5846a08da..273cbcb76e 100644 --- a/apps/api/v2/src/modules/cal-unified-calendars/outputs/get-unified-calendar-event.ts +++ b/apps/api/v2/src/modules/cal-unified-calendars/outputs/get-unified-calendar-event.ts @@ -211,6 +211,18 @@ export class CalendarEventHost { description: "Display name of the event host", }) name?: string; + + @IsString() + @IsOptional() + @IsEnum(CalendarEventResponseStatus) + @ApiPropertyOptional({ + enum: CalendarEventResponseStatus, + nullable: true, + enumName: "CalendarEventResponseStatus", + description: "Host's response to the invitation", + example: CalendarEventResponseStatus.ACCEPTED, + }) + responseStatus!: CalendarEventResponseStatus | null; } export class CalendarEventAttendee { diff --git a/apps/api/v2/src/modules/cal-unified-calendars/pipes/get-calendar-event-details-output-pipe.ts b/apps/api/v2/src/modules/cal-unified-calendars/pipes/get-calendar-event-details-output-pipe.ts index 3bdddcfb66..906dcc8b3d 100644 --- a/apps/api/v2/src/modules/cal-unified-calendars/pipes/get-calendar-event-details-output-pipe.ts +++ b/apps/api/v2/src/modules/cal-unified-calendars/pipes/get-calendar-event-details-output-pipe.ts @@ -159,28 +159,28 @@ export class GoogleCalendarEventOutputPipe } } - private transformHosts(googleEvent: GoogleCalendarEventResponse): Array<{ email: string; name?: string }> { - if (googleEvent.organizer) { - return [ - { - email: googleEvent.organizer.email, - name: googleEvent.organizer.displayName, - }, - ]; - } else if (googleEvent.attendees) { - // If no explicit organizer, find the first attendee with organizer flag - const organizerAttendee = googleEvent.attendees.find((attendee) => attendee.organizer); - if (organizerAttendee) { - return [ - { - email: organizerAttendee.email, - name: organizerAttendee.displayName, - }, - ]; - } + private transformHosts(googleEvent: GoogleCalendarEventResponse) { + const hosts: Array<{ email: string; name?: string; responseStatus: CalendarEventResponseStatus | null }> = + []; + + const organizerAttendees = googleEvent?.attendees?.filter((attendee) => attendee.organizer); + if (organizerAttendees?.length) { + organizerAttendees.forEach((organizer) => { + hosts.push({ + email: organizer.email, + name: organizer.displayName, + responseStatus: this.transformAttendeeResponseStatus(organizer.responseStatus), + }); + }); + } else { + hosts.push({ + email: googleEvent.organizer.email, + name: googleEvent.organizer.displayName, + responseStatus: null, + }); } - return []; + return hosts; } private transformLocations( diff --git a/apps/api/v2/swagger/documentation.json b/apps/api/v2/swagger/documentation.json index ea2ed740b6..995193fcbd 100644 --- a/apps/api/v2/swagger/documentation.json +++ b/apps/api/v2/swagger/documentation.json @@ -26400,7 +26400,7 @@ }, "CalendarEventResponseStatus": { "type": "string", - "description": "Attendee's response to the invitation", + "description": "Host's response to the invitation", "enum": [ "accepted", "pending", @@ -26460,6 +26460,11 @@ "type": "string", "nullable": true, "description": "Display name of the event host" + }, + "responseStatus": { + "nullable": true, + "example": "accepted", + "$ref": "#/components/schemas/CalendarEventResponseStatus" } }, "required": [ diff --git a/docs/api-reference/v2/openapi.json b/docs/api-reference/v2/openapi.json index 89e56c494c..80418c4e06 100644 --- a/docs/api-reference/v2/openapi.json +++ b/docs/api-reference/v2/openapi.json @@ -24102,7 +24102,7 @@ }, "CalendarEventResponseStatus": { "type": "string", - "description": "Attendee's response to the invitation", + "description": "Host's response to the invitation", "enum": ["accepted", "pending", "declined", "needsAction"] }, "CalendarEventAttendee": { @@ -24150,6 +24150,11 @@ "type": "string", "nullable": true, "description": "Display name of the event host" + }, + "responseStatus": { + "nullable": true, + "example": "accepted", + "$ref": "#/components/schemas/CalendarEventResponseStatus" } }, "required": ["email"]