fix: update friendTransaction model according to API
This commit is contained in:
@@ -75,9 +75,12 @@ function EarnAndBurn({ lang }: EarnAndBurnProps) {
|
||||
}
|
||||
|
||||
function Row({ transaction, lang }: RowProps) {
|
||||
const description = `${_(transaction.hotelName)}, ${transaction.city} ${transaction.nights} ${_("nights")}`
|
||||
const arrival = dt(transaction.checkInDate).locale(lang).format("DD MMM YYYY")
|
||||
const departure = dt(transaction.checkOutDate)
|
||||
const description =
|
||||
transaction.hotelName && transaction.city
|
||||
? `${_(transaction.hotelName)}, ${transaction.city} ${transaction.nights} ${_("nights")}`
|
||||
: `${transaction.nights} ${_("nights")}`
|
||||
const arrival = dt(transaction.checkinDate).locale(lang).format("DD MMM YYYY")
|
||||
const departure = dt(transaction.checkoutDate)
|
||||
.locale(lang)
|
||||
.format("DD MMM YYYY")
|
||||
const values = [
|
||||
|
||||
@@ -100,42 +100,47 @@ export const getFriendTransactionsSchema = z.object({
|
||||
attributes: z.object({
|
||||
hotelOperaId: z.string(),
|
||||
confirmationNumber: z.string(),
|
||||
checkInDate: z.string(),
|
||||
checkOutDate: z.string(),
|
||||
checkinDate: z.string(),
|
||||
checkoutDate: z.string(),
|
||||
nights: z.number(),
|
||||
awardPoints: z.number(),
|
||||
pointsCalculated: z.boolean(),
|
||||
hotelInformation: z.object({
|
||||
hotelName: z.string(),
|
||||
city: z.string(),
|
||||
hotelContent: z.object({
|
||||
images: z.object({
|
||||
metaData: z.object({
|
||||
title: z.string(),
|
||||
altText: z.string(),
|
||||
altText_En: z.string(),
|
||||
copyRight: z.string(),
|
||||
}),
|
||||
imageSizes: z.object({
|
||||
tiny: z.string(),
|
||||
small: z.string(),
|
||||
medium: z.string(),
|
||||
large: z.string(),
|
||||
hotelInformation: z
|
||||
.object({
|
||||
hotelName: z.string(),
|
||||
city: z.string(),
|
||||
hotelContent: z.object({
|
||||
images: z.object({
|
||||
metaData: z.object({
|
||||
title: z.string(),
|
||||
altText: z.string(),
|
||||
altText_En: z.string(),
|
||||
copyRight: z.string(),
|
||||
}),
|
||||
imageSizes: z.object({
|
||||
tiny: z.string(),
|
||||
small: z.string(),
|
||||
medium: z.string(),
|
||||
large: z.string(),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
.optional(),
|
||||
}),
|
||||
relationships: z.object({
|
||||
hotel: z.object({
|
||||
links: z.object({
|
||||
related: z.string(),
|
||||
}),
|
||||
data: z.object({
|
||||
id: z.string(),
|
||||
type: z.string(),
|
||||
}),
|
||||
}),
|
||||
hotel: z
|
||||
.object({
|
||||
links: z.object({
|
||||
related: z.string(),
|
||||
}),
|
||||
|
||||
data: z.object({
|
||||
id: z.string(),
|
||||
type: z.string(),
|
||||
}),
|
||||
})
|
||||
.optional(),
|
||||
booking: z.object({
|
||||
links: z.object({
|
||||
related: z.string(),
|
||||
|
||||
@@ -195,33 +195,32 @@ export const userQueryRouter = router({
|
||||
if (cursor) {
|
||||
params.set("offset", cursor.toString())
|
||||
}
|
||||
// TODO: att these once API data is confirmed to be available
|
||||
// const apiResponse = await api.get(
|
||||
// api.endpoints.v1.friendTransactions,
|
||||
// {
|
||||
// headers: {
|
||||
// Authorization: `Bearer ${opts.ctx.session.token.access_token}`,
|
||||
// },
|
||||
// },
|
||||
// params
|
||||
// )
|
||||
|
||||
// if (!apiResponse.ok) {
|
||||
// switch (apiResponse.status) {
|
||||
// case 400:
|
||||
// throw badRequestError()
|
||||
// case 401:
|
||||
// throw unauthorizedError()
|
||||
// case 403:
|
||||
// throw forbiddenError()
|
||||
// default:
|
||||
// throw internalServerError()
|
||||
// }
|
||||
// }
|
||||
const apiResponse = await api.get(
|
||||
api.endpoints.v1.friendTransactions,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${opts.ctx.session.token.access_token}`,
|
||||
},
|
||||
},
|
||||
params
|
||||
)
|
||||
|
||||
// const apiJson = await apiResponse.json()
|
||||
const apiJson = friendTransactionsMockJson
|
||||
debugger
|
||||
if (!apiResponse.ok) {
|
||||
switch (apiResponse.status) {
|
||||
case 400:
|
||||
throw badRequestError()
|
||||
case 401:
|
||||
throw unauthorizedError()
|
||||
case 403:
|
||||
throw forbiddenError()
|
||||
default:
|
||||
throw internalServerError()
|
||||
}
|
||||
}
|
||||
|
||||
const apiJson = await apiResponse.json()
|
||||
// const apiJson = friendTransactionsMockJson
|
||||
|
||||
if (!apiJson.data?.length) {
|
||||
// throw internalServerError()
|
||||
@@ -243,15 +242,14 @@ export const userQueryRouter = router({
|
||||
|
||||
return {
|
||||
data: verifiedData.data.data.map(({ attributes }) => ({
|
||||
checkInDate: attributes.checkInDate,
|
||||
checkOutDate: attributes.checkOutDate,
|
||||
checkinDate: attributes.checkinDate,
|
||||
checkoutDate: attributes.checkoutDate,
|
||||
awardPoints: attributes.awardPoints,
|
||||
hotelName: attributes.hotelInformation.hotelName,
|
||||
city: attributes.hotelInformation.city,
|
||||
hotelName: attributes.hotelInformation?.hotelName,
|
||||
city: attributes.hotelInformation?.city,
|
||||
nights: attributes.nights,
|
||||
confirmationNumber: attributes.confirmationNumber,
|
||||
})),
|
||||
|
||||
nextCursor,
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -5,11 +5,11 @@ export type EarnAndBurnProps = {
|
||||
}
|
||||
|
||||
type Transaction = {
|
||||
checkInDate: string
|
||||
checkOutDate: string
|
||||
checkinDate: string
|
||||
checkoutDate: string
|
||||
awardPoints: number
|
||||
hotelName: string
|
||||
city: string
|
||||
hotelName?: string
|
||||
city?: string
|
||||
nights: number
|
||||
confirmationNumber: string
|
||||
}
|
||||
@@ -22,11 +22,11 @@ export type Page = {
|
||||
export type RowProps = {
|
||||
lang: Lang
|
||||
transaction: {
|
||||
checkInDate: string
|
||||
checkOutDate: string
|
||||
checkinDate: string
|
||||
checkoutDate: string
|
||||
awardPoints: number
|
||||
hotelName: string
|
||||
city: string
|
||||
hotelName?: string
|
||||
city?: string
|
||||
nights: number
|
||||
confirmationNumber: string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user