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 * as maskValue from "@/utils/maskValue"
|
||||||
import { getMembership, getMembershipCards } from "@/utils/user"
|
import { getMembership, getMembershipCards } from "@/utils/user"
|
||||||
|
|
||||||
|
import encryptValue from "../utils/encryptValue"
|
||||||
import {
|
import {
|
||||||
friendTransactionsInput,
|
friendTransactionsInput,
|
||||||
getUserInputSchema,
|
getUserInputSchema,
|
||||||
staysInput,
|
staysInput,
|
||||||
} from "./input"
|
} from "./input"
|
||||||
import encryptValue from "../utils/encryptValue"
|
|
||||||
import {
|
import {
|
||||||
getCreditCardsSchema,
|
getCreditCardsSchema,
|
||||||
getFriendTransactionsSchema,
|
getFriendTransactionsSchema,
|
||||||
@@ -222,52 +222,22 @@ export const userQueryRouter = router({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!apiResponseUser.ok) {
|
if (apiResponseUser.ok) {
|
||||||
// switch (apiResponseUser.status) {
|
const apiJsonUser = await apiResponseUser.json()
|
||||||
// case 400:
|
if (apiJsonUser.data?.attributes) {
|
||||||
// throw badRequestError(apiResponseUser)
|
verifiedData.data.data.forEach((stay) => {
|
||||||
// case 401:
|
const originalString =
|
||||||
// throw unauthorizedError(apiResponseUser)
|
stay.attributes.confirmationNumber.toString() +
|
||||||
// case 403:
|
"," +
|
||||||
// throw forbiddenError(apiResponseUser)
|
apiJsonUser.data.attributes.lastName
|
||||||
// default:
|
let bookingUrl = encryptValue(originalString)
|
||||||
// throw internalServerError(apiResponseUser)
|
stay.attributes.bookingUrl =
|
||||||
// }
|
"/hotelreservation/my-booking?RefId=" + bookingUrl
|
||||||
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
|
|
||||||
}
|
}
|
||||||
// ------------------
|
// ------------------
|
||||||
|
|
||||||
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 {
|
return {
|
||||||
data: verifiedData.data.data,
|
data: verifiedData.data.data,
|
||||||
nextCursor,
|
nextCursor,
|
||||||
@@ -337,52 +307,22 @@ export const userQueryRouter = router({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!apiResponseUser.ok) {
|
if (apiResponseUser.ok) {
|
||||||
// switch (apiResponseUser.status) {
|
const apiJsonUser = await apiResponseUser.json()
|
||||||
// case 400:
|
if (apiJsonUser.data?.attributes) {
|
||||||
// throw badRequestError(apiResponseUser)
|
verifiedData.data.data.forEach((stay) => {
|
||||||
// case 401:
|
const originalString =
|
||||||
// throw unauthorizedError(apiResponseUser)
|
stay.attributes.confirmationNumber.toString() +
|
||||||
// case 403:
|
"," +
|
||||||
// throw forbiddenError(apiResponseUser)
|
apiJsonUser.data.attributes.lastName
|
||||||
// default:
|
let bookingUrl = encryptValue(originalString)
|
||||||
// throw internalServerError(apiResponseUser)
|
stay.attributes.bookingUrl =
|
||||||
// }
|
"/hotelreservation/my-booking?RefId=" + bookingUrl
|
||||||
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
|
|
||||||
}
|
}
|
||||||
// ------------------
|
// ------------------
|
||||||
|
|
||||||
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 {
|
return {
|
||||||
data: verifiedData.data.data,
|
data: verifiedData.data.data,
|
||||||
nextCursor,
|
nextCursor,
|
||||||
|
|||||||
@@ -19,5 +19,5 @@ export default function encryptValue(originalString: string) {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e)
|
console.log(e)
|
||||||
}
|
}
|
||||||
return result
|
return result.toString()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user