feat: (Web-210) Added encryption for my-booking Urls
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
getUserInputSchema,
|
||||
staysInput,
|
||||
} from "./input"
|
||||
import encryptValue from "../utils/encryptValue"
|
||||
import {
|
||||
getCreditCardsSchema,
|
||||
getFriendTransactionsSchema,
|
||||
@@ -212,6 +213,61 @@ export const userQueryRouter = router({
|
||||
? verifiedData.data.links.offset
|
||||
: undefined
|
||||
|
||||
// Tenporary till we have user name in ctx session data
|
||||
// ----
|
||||
const apiResponseUser = await api.get(api.endpoints.v1.profile, {
|
||||
cache: "no-store",
|
||||
headers: {
|
||||
Authorization: `Bearer ${ctx.session.token.access_token}`,
|
||||
},
|
||||
})
|
||||
|
||||
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
|
||||
}
|
||||
// ------------------
|
||||
|
||||
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,
|
||||
@@ -272,6 +328,61 @@ export const userQueryRouter = router({
|
||||
? verifiedData.data.links.offset
|
||||
: undefined
|
||||
|
||||
// Tenporary till we have user name in ctx session data
|
||||
// ----
|
||||
const apiResponseUser = await api.get(api.endpoints.v1.profile, {
|
||||
cache: "no-store",
|
||||
headers: {
|
||||
Authorization: `Bearer ${ctx.session.token.access_token}`,
|
||||
},
|
||||
})
|
||||
|
||||
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
|
||||
}
|
||||
// ------------------
|
||||
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user