Merged in chore/refactor-hotel-trpc-routes (pull request #2891)

Chore/refactor hotel trpc routes

* chore(SW-3519): refactor trpc hotel routers

* chore(SW-3519): refactor trpc hotel routers

* refactor

* merge

* Merge branch 'master' of bitbucket.org:scandic-swap/web into chore/refactor-hotel-trpc-routes


Approved-by: Linus Flood
This commit is contained in:
Joakim Jäderberg
2025-10-01 12:55:45 +00:00
parent 332abdfba0
commit 8498026189
52 changed files with 2338 additions and 1794 deletions

View File

@@ -0,0 +1,69 @@
import "server-only"
import { myStay } from "@scandic-hotels/common/constants/routes/myStay"
import { env } from "../../../../env/server"
import { encrypt } from "../../../utils/encryption"
import { getVerifiedUser } from "./getVerifiedUser"
import type { Lang } from "@scandic-hotels/common/constants/language"
import type { Session } from "next-auth"
import type { FriendTransaction, Stay } from "../output"
export async function updateStaysBookingUrl(
data: Stay[],
session: Session,
lang: Lang
): Promise<Stay[]>
export async function updateStaysBookingUrl(
data: FriendTransaction[],
session: Session,
lang: Lang
): Promise<FriendTransaction[]>
export async function updateStaysBookingUrl(
data: Stay[] | FriendTransaction[],
session: Session,
lang: Lang
) {
const user = await getVerifiedUser({
session,
})
if (user && !("error" in user)) {
return data.map((d) => {
const originalString =
d.attributes.confirmationNumber.toString() + "," + user.data.lastName
const encryptedBookingValue = encrypt(originalString)
// Get base URL with fallback for ephemeral environments (like deploy previews).
const baseUrl = env.PUBLIC_URL || "https://www.scandichotels.com"
// Construct Booking URL.
const bookingUrl = new URL(myStay[lang], baseUrl)
// Add search parameters.
if (encryptedBookingValue) {
bookingUrl.searchParams.set("RefId", encryptedBookingValue)
} else {
bookingUrl.searchParams.set("lastName", user.data.lastName)
bookingUrl.searchParams.set(
"bookingId",
d.attributes.confirmationNumber.toString()
)
}
return {
...d,
attributes: {
...d.attributes,
bookingUrl: bookingUrl.toString(),
},
}
})
}
return data
}