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

@@ -26,7 +26,7 @@ export default async function SoonestStays({
<SectionHeader title={title} subtitle={subtitle} link={link} /> <SectionHeader title={title} subtitle={subtitle} link={link} />
{response.data.length ? ( {response.data.length ? (
<Grids.Stackable> <Grids.Stackable>
{response.data.map((stay: any) => ( {response.data.map((stay) => (
<StayCard <StayCard
key={stay.attributes.confirmationNumber} key={stay.attributes.confirmationNumber}
lang={lang} lang={lang}

View File

@@ -23,6 +23,7 @@ import {
getMembershipCardsSchema, getMembershipCardsSchema,
getStaysSchema, getStaysSchema,
getUserSchema, getUserSchema,
Stay,
} from "./output" } from "./output"
import { benefits, extendedUser, nextLevelPerks } from "./temp" 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 // Tenporary API call needed till we have user name in ctx session data
const apiResponse = await api.get(api.endpoints.v1.profile, { const apiResponse = await api.get(api.endpoints.v1.profile, {
cache: "no-store", cache: "no-store",
headers: { headers: {
Authorization: `Bearer ${ctx.session.token.access_token}`, Authorization: `Bearer ${token}`,
}, },
}) })
// Temporary domain and lang support for current web // Temporary domain and lang support for current web
let localeDomain = env.PUBLIC_URL let localeDomain = env.PUBLIC_URL
let fullBookingUrl = localeDomain + "/hotelreservation/my-booking" let fullBookingUrl = localeDomain + "/hotelreservation/my-booking"
switch (ctx.lang) { switch (lang) {
case "sv": case "sv":
localeDomain = localeDomain?.replace(".com", ".se") localeDomain = localeDomain?.replace(".com", ".se")
fullBookingUrl = localeDomain + "/hotelreservation/din-bokning" fullBookingUrl = localeDomain + "/hotelreservation/din-bokning"
@@ -105,7 +110,7 @@ const updateStaysBookingUrl = async (verifiedData: any, ctx: any) => {
if (apiResponse.ok) { if (apiResponse.ok) {
const apiJson = await apiResponse.json() const apiJson = await apiResponse.json()
if (apiJson.data?.attributes) { if (apiJson.data?.attributes) {
verifiedData.data.data.forEach((stay: any) => { data.map((stay: Stay) => {
const originalString = const originalString =
stay.attributes.confirmationNumber.toString() + stay.attributes.confirmationNumber.toString() +
"," + "," +
@@ -116,7 +121,7 @@ const updateStaysBookingUrl = async (verifiedData: any, ctx: any) => {
}) })
} }
} }
return verifiedData return data
} }
export const userQueryRouter = router({ export const userQueryRouter = router({
@@ -269,10 +274,14 @@ export const userQueryRouter = router({
? verifiedData.data.links.offset ? verifiedData.data.links.offset
: undefined : undefined
const updatedData = await updateStaysBookingUrl(verifiedData, ctx) const updatedData = await updateStaysBookingUrl(
verifiedData.data.data,
ctx.session.token.access_token,
ctx.lang
)
return { return {
data: updatedData.data.data, data: updatedData,
nextCursor, nextCursor,
} }
}), }),
@@ -331,10 +340,14 @@ export const userQueryRouter = router({
? verifiedData.data.links.offset ? verifiedData.data.links.offset
: undefined : undefined
const updatedData = await updateStaysBookingUrl(verifiedData, ctx) const updatedData = await updateStaysBookingUrl(
verifiedData.data.data,
ctx.session.token.access_token,
ctx.lang
)
return { return {
data: updatedData.data.data, data: updatedData,
nextCursor, nextCursor,
} }
}), }),