feat: WEB-210 Fixed API response
This commit is contained in:
@@ -9,12 +9,12 @@ import { countries } from "@/components/TempDesignSystem/Form/Country/countries"
|
||||
import * as maskValue from "@/utils/maskValue"
|
||||
import { getMembership, getMembershipCards } from "@/utils/user"
|
||||
|
||||
import encryptValue from "../utils/encryptValue"
|
||||
import {
|
||||
friendTransactionsInput,
|
||||
getUserInputSchema,
|
||||
staysInput,
|
||||
} from "./input"
|
||||
import encryptValue from "../utils/encryptValue"
|
||||
import {
|
||||
getCreditCardsSchema,
|
||||
getFriendTransactionsSchema,
|
||||
@@ -222,52 +222,22 @@ export const userQueryRouter = router({
|
||||
},
|
||||
})
|
||||
|
||||
if (!apiResponseUser.ok) {
|
||||
// switch (apiResponseUser.status) {
|
||||
// case 400:
|
||||
// throw badRequestError(apiResponseUser)
|
||||
// case 401:
|
||||
// throw unauthorizedError(apiResponseUser)
|
||||
// case 403:
|
||||
// throw forbiddenError(apiResponseUser)
|
||||
// default:
|
||||
// throw internalServerError(apiResponseUser)
|
||||
// }
|
||||
console.info(`API Response Failed - Getting User`)
|
||||
console.info(`User: (${JSON.stringify(ctx.session.user)})`)
|
||||
console.error(apiResponse)
|
||||
return null
|
||||
}
|
||||
|
||||
const apiJsonUser = await apiResponse.json()
|
||||
if (!apiJson.data?.attributes) {
|
||||
// throw notFound(apiJson)
|
||||
console.error(
|
||||
`User has no data - (user: ${JSON.stringify(ctx.session.user)})`
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
||||
const verifiedDataUser = getUserSchema.safeParse(apiJsonUser.data.attributes)
|
||||
if (!verifiedDataUser.success) {
|
||||
console.info(
|
||||
`Failed to validate User - (User: ${JSON.stringify(ctx.session.user)})`
|
||||
)
|
||||
console.error(verifiedDataUser.error)
|
||||
return null
|
||||
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
|
||||
})
|
||||
}
|
||||
}
|
||||
// ------------------
|
||||
|
||||
verifiedData.data.data.forEach((stay) => {
|
||||
const originalString =
|
||||
stay.attributes.confirmationNumber.toString() +
|
||||
"," +
|
||||
verifiedDataUser.data.lastName
|
||||
let bookingUrl = encryptValue(originalString)
|
||||
stay.attributes.bookingUrl =
|
||||
"/hotelreservation/my-booking?RefId=" + bookingUrl
|
||||
})
|
||||
|
||||
return {
|
||||
data: verifiedData.data.data,
|
||||
nextCursor,
|
||||
@@ -337,52 +307,22 @@ export const userQueryRouter = router({
|
||||
},
|
||||
})
|
||||
|
||||
if (!apiResponseUser.ok) {
|
||||
// switch (apiResponseUser.status) {
|
||||
// case 400:
|
||||
// throw badRequestError(apiResponseUser)
|
||||
// case 401:
|
||||
// throw unauthorizedError(apiResponseUser)
|
||||
// case 403:
|
||||
// throw forbiddenError(apiResponseUser)
|
||||
// default:
|
||||
// throw internalServerError(apiResponseUser)
|
||||
// }
|
||||
console.info(`API Response Failed - Getting Upcoming Stays`)
|
||||
console.info(`User: (${JSON.stringify(ctx.session.user)})`)
|
||||
console.error(apiResponse)
|
||||
return null
|
||||
}
|
||||
|
||||
const apiJsonUser = await apiResponse.json()
|
||||
if (!apiJson.data?.attributes) {
|
||||
// throw notFound(apiJson)
|
||||
console.error(
|
||||
`User has no data - (user: ${JSON.stringify(ctx.session.user)})`
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
||||
const verifiedDataUser = getUserSchema.safeParse(apiJsonUser.data.attributes)
|
||||
if (!verifiedDataUser.success) {
|
||||
console.info(
|
||||
`Failed to validate User - (User: ${JSON.stringify(ctx.session.user)})`
|
||||
)
|
||||
console.error(verifiedDataUser.error)
|
||||
return null
|
||||
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
|
||||
})
|
||||
}
|
||||
}
|
||||
// ------------------
|
||||
|
||||
verifiedData.data.data.forEach((stay) => {
|
||||
const originalString =
|
||||
stay.attributes.confirmationNumber.toString() +
|
||||
"," +
|
||||
verifiedDataUser.data.lastName
|
||||
let bookingUrl = encryptValue(originalString)
|
||||
stay.attributes.bookingUrl =
|
||||
"/hotelreservation/my-booking?RefId=" + bookingUrl
|
||||
})
|
||||
|
||||
return {
|
||||
data: verifiedData.data.data,
|
||||
nextCursor,
|
||||
|
||||
@@ -19,5 +19,5 @@ export default function encryptValue(originalString: string) {
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
return result
|
||||
return result.toString()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user