feat: WEB-210 Updated types as review comments

This commit is contained in:
Hrishikesh Vaipurkar
2024-07-02 14:20:42 +02:00
parent d33e038703
commit cbd634144e
2 changed files with 23 additions and 10 deletions

View File

@@ -23,6 +23,7 @@ import {
getMembershipCardsSchema,
getStaysSchema,
getUserSchema,
Stay,
} from "./output"
import { benefits, extendedUser, nextLevelPerks } from "./temp"
@@ -65,19 +66,23 @@ function fakingRequest<T>(payload: T): Promise<T> {
})
}
const updateStaysBookingUrl = async (verifiedData: any, ctx: any) => {
const updateStaysBookingUrl = async (
data: Stay[],
token: string,
lang: string
) => {
// 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}`,
Authorization: `Bearer ${token}`,
},
})
// Temporary domain and lang support for current web
let localeDomain = env.PUBLIC_URL
let fullBookingUrl = localeDomain + "/hotelreservation/my-booking"
switch (ctx.lang) {
switch (lang) {
case "sv":
localeDomain = localeDomain?.replace(".com", ".se")
fullBookingUrl = localeDomain + "/hotelreservation/din-bokning"
@@ -105,7 +110,7 @@ const updateStaysBookingUrl = async (verifiedData: any, ctx: any) => {
if (apiResponse.ok) {
const apiJson = await apiResponse.json()
if (apiJson.data?.attributes) {
verifiedData.data.data.forEach((stay: any) => {
data.map((stay: Stay) => {
const originalString =
stay.attributes.confirmationNumber.toString() +
"," +
@@ -116,7 +121,7 @@ const updateStaysBookingUrl = async (verifiedData: any, ctx: any) => {
})
}
}
return verifiedData
return data
}
export const userQueryRouter = router({
@@ -269,10 +274,14 @@ export const userQueryRouter = router({
? verifiedData.data.links.offset
: undefined
const updatedData = await updateStaysBookingUrl(verifiedData, ctx)
const updatedData = await updateStaysBookingUrl(
verifiedData.data.data,
ctx.session.token.access_token,
ctx.lang
)
return {
data: updatedData.data.data,
data: updatedData,
nextCursor,
}
}),
@@ -331,10 +340,14 @@ export const userQueryRouter = router({
? verifiedData.data.links.offset
: undefined
const updatedData = await updateStaysBookingUrl(verifiedData, ctx)
const updatedData = await updateStaysBookingUrl(
verifiedData.data.data,
ctx.session.token.access_token,
ctx.lang
)
return {
data: updatedData.data.data,
data: updatedData,
nextCursor,
}
}),