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