From c2662638a58dabdb22583ebb3c46b52a2a0a948d Mon Sep 17 00:00:00 2001 From: Morgan <33722304+ThyMinimalDev@users.noreply.github.com> Date: Tue, 22 Oct 2024 11:44:09 +0300 Subject: [PATCH] fix: booking.controller clone req to avoid side effect apiv2 (#17239) --- .../2024-04-15/controllers/bookings.controller.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/apps/api/v2/src/ee/bookings/2024-04-15/controllers/bookings.controller.ts b/apps/api/v2/src/ee/bookings/2024-04-15/controllers/bookings.controller.ts index 069b1a52bf..cb48de9e5a 100644 --- a/apps/api/v2/src/ee/bookings/2024-04-15/controllers/bookings.controller.ts +++ b/apps/api/v2/src/ee/bookings/2024-04-15/controllers/bookings.controller.ts @@ -355,13 +355,14 @@ export class BookingsController_2024_04_15 { oAuthClientId?: string, platformBookingLocation?: string ): Promise { + const clone = { ...req }; const userId = (await this.getOwnerId(req)) ?? -1; const oAuthParams = oAuthClientId ? await this.getOAuthClientsParams(oAuthClientId) : DEFAULT_PLATFORM_PARAMS; - Object.assign(req, { userId, ...oAuthParams, platformBookingLocation }); - req.body = { ...req.body, noEmail: !oAuthParams.arePlatformEmailsEnabled }; - return req as unknown as NextApiRequest & { userId?: number } & OAuthRequestParams; + Object.assign(clone, { userId, ...oAuthParams, platformBookingLocation }); + clone.body = { ...clone.body, noEmail: !oAuthParams.arePlatformEmailsEnabled }; + return clone as unknown as NextApiRequest & { userId?: number } & OAuthRequestParams; } private async createNextApiRecurringBookingRequest( @@ -369,17 +370,18 @@ export class BookingsController_2024_04_15 { oAuthClientId?: string, platformBookingLocation?: string ): Promise { + const clone = { ...req }; const userId = (await this.getOwnerId(req)) ?? -1; const oAuthParams = oAuthClientId ? await this.getOAuthClientsParams(oAuthClientId) : DEFAULT_PLATFORM_PARAMS; - Object.assign(req, { + Object.assign(clone, { userId, ...oAuthParams, platformBookingLocation, noEmail: !oAuthParams.arePlatformEmailsEnabled, }); - return req as unknown as NextApiRequest & { userId?: number } & OAuthRequestParams; + return clone as unknown as NextApiRequest & { userId?: number } & OAuthRequestParams; } private handleBookingErrors(