|
3 | 3 | BookingReferenceRepository, |
4 | 4 | buildCalEventFromBooking, |
5 | 5 | CredentialRepository, |
| 6 | + sendLocationChangeEmailsAndSMS, |
6 | 7 | updateEvent, |
7 | 8 | } from "@calcom/platform-libraries"; |
8 | 9 | import { makeUserActor } from "@calcom/platform-libraries/bookings"; |
@@ -171,14 +172,40 @@ export class BookingLocationService_2024_08_13 { |
171 | 172 | }); |
172 | 173 | } |
173 | 174 |
|
| 175 | + /** |
| 176 | + * sends location change email and SMS notifications. |
| 177 | + * fetches eventType metadata from the booking for email settings. |
| 178 | + */ |
| 179 | + private async sendLocationChangeNotifications( |
| 180 | + evt: CalendarEvent, |
| 181 | + bookingId: number, |
| 182 | + bookingUid: string, |
| 183 | + newLocation: string |
| 184 | + ): Promise<void> { |
| 185 | + const bookingWithEventType = |
| 186 | + await this.bookingsRepository.getBookingByIdWithUserAndEventDetails(bookingId); |
| 187 | + try { |
| 188 | + await sendLocationChangeEmailsAndSMS( |
| 189 | + { ...evt, location: newLocation }, |
| 190 | + bookingWithEventType?.eventType?.metadata as Record<string, unknown> | undefined |
| 191 | + ); |
| 192 | + } catch (error) { |
| 193 | + this.logger.error( |
| 194 | + `Failed to send location change emails for booking uid=${bookingUid}`, |
| 195 | + error instanceof Error ? error.message : String(error) |
| 196 | + ); |
| 197 | + } |
| 198 | + } |
| 199 | + |
174 | 200 | /** |
175 | 201 | * updates booking with video location data and emits location changed event. |
176 | 202 | * returns the updated booking response. |
177 | 203 | */ |
178 | 204 | private async updateBookingWithVideoLocation( |
179 | 205 | ctx: IntegrationHandlerContext, |
180 | 206 | videoCallUrl: string | undefined, |
181 | | - bookingLocation: string |
| 207 | + bookingLocation: string, |
| 208 | + evt: CalendarEvent |
182 | 209 | ): Promise<BookingLocationResponse> { |
183 | 210 | const existingMetadata = (ctx.existingBooking.metadata || {}) as Record<string, unknown>; |
184 | 211 | const updatedMetadata = { |
@@ -217,6 +244,13 @@ export class BookingLocationService_2024_08_13 { |
217 | 244 | }, |
218 | 245 | }); |
219 | 246 |
|
| 247 | + await this.sendLocationChangeNotifications( |
| 248 | + evt, |
| 249 | + ctx.existingBooking.id, |
| 250 | + ctx.existingBooking.uid, |
| 251 | + bookingLocation |
| 252 | + ); |
| 253 | + |
220 | 254 | return this.bookingsService.getBooking(updatedBooking.uid, ctx.user); |
221 | 255 | } |
222 | 256 |
|
@@ -340,6 +374,25 @@ export class BookingLocationService_2024_08_13 { |
340 | 374 | }, |
341 | 375 | }); |
342 | 376 |
|
| 377 | + if (bookingLocation) { |
| 378 | + const bookingWithDetails = await this.bookingsRepository.getBookingByIdWithUserAndEventDetails( |
| 379 | + existingBooking.id |
| 380 | + ); |
| 381 | + if (bookingWithDetails?.user) { |
| 382 | + const evt = await this.buildCalEventForIntegration( |
| 383 | + bookingWithDetails as BookingWithDetails, |
| 384 | + bookingLocation, |
| 385 | + null |
| 386 | + ); |
| 387 | + await this.sendLocationChangeNotifications( |
| 388 | + evt, |
| 389 | + existingBooking.id, |
| 390 | + existingBooking.uid, |
| 391 | + bookingLocation |
| 392 | + ); |
| 393 | + } |
| 394 | + } |
| 395 | + |
343 | 396 | return this.bookingsService.getBooking(updatedBooking.uid, user); |
344 | 397 | } |
345 | 398 |
|
@@ -471,7 +524,7 @@ export class BookingLocationService_2024_08_13 { |
471 | 524 | await this.syncCalendarEvent(ctx.existingBooking.id, bookingLocation); |
472 | 525 | } |
473 | 526 |
|
474 | | - return this.updateBookingWithVideoLocation(ctx, videoCallUrl, bookingLocation); |
| 527 | + return this.updateBookingWithVideoLocation(ctx, videoCallUrl, bookingLocation, evt); |
475 | 528 | } |
476 | 529 |
|
477 | 530 | /** |
@@ -529,7 +582,7 @@ export class BookingLocationService_2024_08_13 { |
529 | 582 | await this.syncCalendarEvent(ctx.existingBooking.id, bookingLocation); |
530 | 583 | } |
531 | 584 |
|
532 | | - return this.updateBookingWithVideoLocation(ctx, videoCallUrl, bookingLocation); |
| 585 | + return this.updateBookingWithVideoLocation(ctx, videoCallUrl, bookingLocation, evt); |
533 | 586 | } |
534 | 587 |
|
535 | 588 | /** |
@@ -622,6 +675,13 @@ export class BookingLocationService_2024_08_13 { |
622 | 675 | }, |
623 | 676 | }); |
624 | 677 |
|
| 678 | + await this.sendLocationChangeNotifications( |
| 679 | + evt, |
| 680 | + ctx.existingBooking.id, |
| 681 | + ctx.existingBooking.uid, |
| 682 | + bookingLocation |
| 683 | + ); |
| 684 | + |
625 | 685 | return this.bookingsService.getBooking(updatedBooking.uid, ctx.user); |
626 | 686 | } |
627 | 687 |
|
|
0 commit comments