feat: WEB-210 Updated as per review comments
This commit is contained in:
@@ -61,7 +61,7 @@ export const getStaysSchema = z.object({
|
||||
checkinDate: z.string(),
|
||||
checkoutDate: z.string(),
|
||||
isWebAppOrigin: z.boolean(),
|
||||
bookingUrl: z.string().optional(),
|
||||
bookingUrl: z.string().default(""),
|
||||
}),
|
||||
relationships: z.object({
|
||||
hotel: z.object({
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { env } from "process"
|
||||
|
||||
import * as api from "@/lib/api"
|
||||
import {
|
||||
protectedProcedure,
|
||||
@@ -63,6 +65,60 @@ function fakingRequest<T>(payload: T): Promise<T> {
|
||||
})
|
||||
}
|
||||
|
||||
const updateStaysBookingUrl = async (verifiedData: any, ctx: any) => {
|
||||
// Tenporary API call needed till we have user name in ctx session data
|
||||
const apiResponse = await api.get(api.endpoints.v1.profile, {
|
||||
cache: "no-store",
|
||||
headers: {
|
||||
Authorization: `Bearer ${ctx.session.token.access_token}`,
|
||||
},
|
||||
})
|
||||
|
||||
// Temporary domain and lang support for current web
|
||||
let localeDomain = env.PUBLIC_URL
|
||||
let fullBookingUrl = localeDomain + "/hotelreservation/my-booking"
|
||||
switch (ctx.lang) {
|
||||
case "sv":
|
||||
localeDomain = localeDomain?.replace(".com", ".se")
|
||||
fullBookingUrl = localeDomain + "/hotelreservation/din-bokning"
|
||||
break
|
||||
case "no":
|
||||
localeDomain = localeDomain?.replace(".com", ".no")
|
||||
fullBookingUrl = localeDomain + "/hotelreservation/my-booking"
|
||||
break
|
||||
case "da":
|
||||
localeDomain = localeDomain?.replace(".com", ".dk")
|
||||
fullBookingUrl = localeDomain + "/hotelreservation/min-booking"
|
||||
break
|
||||
case "fi":
|
||||
localeDomain = localeDomain?.replace(".com", ".fi")
|
||||
fullBookingUrl = localeDomain + "/varaa-hotelli/varauksesi"
|
||||
break
|
||||
case "de":
|
||||
localeDomain = localeDomain?.replace(".com", ".de")
|
||||
fullBookingUrl = localeDomain + "/hotelreservation/my-booking"
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
if (apiResponse.ok) {
|
||||
const apiJson = await apiResponse.json()
|
||||
if (apiJson.data?.attributes) {
|
||||
verifiedData.data.data.forEach((stay: any) => {
|
||||
const originalString =
|
||||
stay.attributes.confirmationNumber.toString() +
|
||||
"," +
|
||||
apiJson.data.attributes.lastName
|
||||
let encryptedBookingValue = encryptValue(originalString)
|
||||
stay.attributes.bookingUrl =
|
||||
fullBookingUrl + "?RefId=" + encryptedBookingValue
|
||||
})
|
||||
}
|
||||
}
|
||||
return verifiedData
|
||||
}
|
||||
|
||||
export const userQueryRouter = router({
|
||||
get: protectedProcedure
|
||||
.input(getUserInputSchema)
|
||||
@@ -213,33 +269,10 @@ export const userQueryRouter = router({
|
||||
? verifiedData.data.links.offset
|
||||
: undefined
|
||||
|
||||
// Tenporary till we have user name in ctx session data
|
||||
// ----
|
||||
const apiResponseUser = await api.get(api.endpoints.v1.profile, {
|
||||
cache: "no-store",
|
||||
headers: {
|
||||
Authorization: `Bearer ${ctx.session.token.access_token}`,
|
||||
},
|
||||
})
|
||||
|
||||
if (apiResponseUser.ok) {
|
||||
const apiJsonUser = await apiResponseUser.json()
|
||||
if (apiJsonUser.data?.attributes) {
|
||||
verifiedData.data.data.forEach((stay) => {
|
||||
const originalString =
|
||||
stay.attributes.confirmationNumber.toString() +
|
||||
"," +
|
||||
apiJsonUser.data.attributes.lastName
|
||||
let bookingUrl = encryptValue(originalString)
|
||||
stay.attributes.bookingUrl =
|
||||
"/hotelreservation/my-booking?RefId=" + bookingUrl
|
||||
})
|
||||
}
|
||||
}
|
||||
// ------------------
|
||||
const updatedData = await updateStaysBookingUrl(verifiedData, ctx)
|
||||
|
||||
return {
|
||||
data: verifiedData.data.data,
|
||||
data: updatedData.data.data,
|
||||
nextCursor,
|
||||
}
|
||||
}),
|
||||
@@ -298,33 +331,10 @@ export const userQueryRouter = router({
|
||||
? verifiedData.data.links.offset
|
||||
: undefined
|
||||
|
||||
// Tenporary till we have user name in ctx session data
|
||||
// ----
|
||||
const apiResponseUser = await api.get(api.endpoints.v1.profile, {
|
||||
cache: "no-store",
|
||||
headers: {
|
||||
Authorization: `Bearer ${ctx.session.token.access_token}`,
|
||||
},
|
||||
})
|
||||
|
||||
if (apiResponseUser.ok) {
|
||||
const apiJsonUser = await apiResponseUser.json()
|
||||
if (apiJsonUser.data?.attributes) {
|
||||
verifiedData.data.data.forEach((stay) => {
|
||||
const originalString =
|
||||
stay.attributes.confirmationNumber.toString() +
|
||||
"," +
|
||||
apiJsonUser.data.attributes.lastName
|
||||
let bookingUrl = encryptValue(originalString)
|
||||
stay.attributes.bookingUrl =
|
||||
"/hotelreservation/my-booking?RefId=" + bookingUrl
|
||||
})
|
||||
}
|
||||
}
|
||||
// ------------------
|
||||
const updatedData = await updateStaysBookingUrl(verifiedData, ctx)
|
||||
|
||||
return {
|
||||
data: verifiedData.data.data,
|
||||
data: updatedData.data.data,
|
||||
nextCursor,
|
||||
}
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user