From 88a7f57349e31325e88d068fef584e69a21dd66a Mon Sep 17 00:00:00 2001 From: Hrishikesh Vaipurkar Date: Mon, 8 Jul 2024 16:37:36 +0200 Subject: [PATCH] feat: WEB-210 Fallback booking URL if encryption fails --- server/routers/user/query.ts | 11 +++++++++-- server/routers/utils/encryptValue.ts | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/server/routers/user/query.ts b/server/routers/user/query.ts index 3e350322b..a4ca6c0ce 100644 --- a/server/routers/user/query.ts +++ b/server/routers/user/query.ts @@ -116,12 +116,19 @@ const updateStaysBookingUrl = async ( stay.attributes.confirmationNumber.toString() + "," + apiJson.data.attributes.lastName - let encryptedBookingValue = encryptValue(originalString) + const encryptedBookingValue = encryptValue(originalString) + const bookingUrl = !!encryptedBookingValue + ? fullBookingUrl + "?RefId=" + encryptedBookingValue + : fullBookingUrl + + "?lastName=" + + apiJson.data.attributes.lastName + + "&bookingId=" + + stay.attributes.confirmationNumber return { ...stay, attributes: { ...stay.attributes, - bookingUrl: fullBookingUrl + "?RefId=" + encryptedBookingValue, + bookingUrl: bookingUrl, }, } }) diff --git a/server/routers/utils/encryptValue.ts b/server/routers/utils/encryptValue.ts index 16a8ce819..a2f24c9c4 100644 --- a/server/routers/utils/encryptValue.ts +++ b/server/routers/utils/encryptValue.ts @@ -3,7 +3,7 @@ import crypto from "crypto" import { env } from "@/env/server" export default function encryptValue(originalString: string) { - let result = "" + let result: String = "" try { const encryptionKey = env.BOOKING_ENCRYPTION_KEY const bufferKey = Buffer.from(encryptionKey, "utf8") @@ -20,5 +20,5 @@ export default function encryptValue(originalString: string) { } catch (e) { console.log(e) } - return result.toString() + return result }