Merged in feat/SW-3526-show-sas-eb-points-rate-in- (pull request #2933)
feat(SW-3526): Show EB points rate and label in booking flow * feat(SW-3526): Show EB points rate and label in booking flow * feat(SW-3526) Optimized points currency code * feat(SW-3526) Removed extra multiplication for token expiry after rebase * feat(SW-3526): Updated to exhaustive check and thow if type error Approved-by: Anton Gunnarsson
This commit is contained in:
@@ -9,7 +9,8 @@ import { SEARCH_TYPE_REDEMPTION } from "../../../constants/booking"
|
||||
import { AvailabilityEnum } from "../../../enums/selectHotel"
|
||||
import { unauthorizedError } from "../../../errors"
|
||||
import { safeProtectedServiceProcedure } from "../../../procedures"
|
||||
import { getVerifiedUser } from "../../user/utils/getVerifiedUser"
|
||||
import { getRedemptionTokenSafely } from "../../../utils/getRedemptionTokenSafely"
|
||||
import { getUserPointsBalance } from "../../../utils/getUserPointsBalance"
|
||||
import { baseBookingSchema, baseRoomSchema, selectedRoomSchema } from "../input"
|
||||
import { getHotel } from "../services/getHotel"
|
||||
import { getRoomsAvailability } from "../services/getRoomsAvailability"
|
||||
@@ -37,13 +38,15 @@ export const enterDetails = safeProtectedServiceProcedure
|
||||
.use(async ({ ctx, input, next }) => {
|
||||
if (input.booking.searchType === SEARCH_TYPE_REDEMPTION) {
|
||||
if (ctx.session?.token.access_token) {
|
||||
const verifiedUser = await getVerifiedUser({ session: ctx.session })
|
||||
if (!verifiedUser?.error) {
|
||||
const pointsValue = await getUserPointsBalance(ctx.session)
|
||||
const token = getRedemptionTokenSafely(ctx.session, ctx.serviceToken)
|
||||
if (pointsValue && token) {
|
||||
return next({
|
||||
ctx: {
|
||||
token: ctx.session.token.access_token,
|
||||
userPoints: verifiedUser?.data.membership?.currentPoints ?? 0,
|
||||
token: token,
|
||||
userPoints: pointsValue ?? 0,
|
||||
},
|
||||
input,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,8 @@ import { env } from "../../../../env/server"
|
||||
import { unauthorizedError } from "../../../errors"
|
||||
import { safeProtectedServiceProcedure } from "../../../procedures"
|
||||
import { toApiLang } from "../../../utils"
|
||||
import { getVerifiedUser } from "../../user/utils/getVerifiedUser"
|
||||
import { getRedemptionTokenSafely } from "../../../utils/getRedemptionTokenSafely"
|
||||
import { getUserPointsBalance } from "../../../utils/getUserPointsBalance"
|
||||
import { getHotelsAvailabilityByCity } from "../services/getHotelsAvailabilityByCity"
|
||||
|
||||
export type HotelsAvailabilityInputSchema = z.output<
|
||||
@@ -68,12 +69,13 @@ export const hotelsByCity = safeProtectedServiceProcedure
|
||||
.use(async ({ ctx, input, next }) => {
|
||||
if (input.redemption) {
|
||||
if (ctx.session?.token.access_token) {
|
||||
const verifiedUser = await getVerifiedUser({ session: ctx.session })
|
||||
if (!verifiedUser?.error) {
|
||||
const pointsValue = await getUserPointsBalance(ctx.session)
|
||||
const token = getRedemptionTokenSafely(ctx.session, ctx.serviceToken)
|
||||
if (pointsValue && token) {
|
||||
return next({
|
||||
ctx: {
|
||||
token: ctx.session.token.access_token,
|
||||
userPoints: verifiedUser?.data.membership?.currentPoints ?? 0,
|
||||
token: token,
|
||||
userPoints: pointsValue ?? 0,
|
||||
},
|
||||
input,
|
||||
})
|
||||
|
||||
@@ -4,7 +4,8 @@ import { z } from "zod"
|
||||
import { unauthorizedError } from "../../../errors"
|
||||
import { safeProtectedServiceProcedure } from "../../../procedures"
|
||||
import { toApiLang } from "../../../utils"
|
||||
import { getVerifiedUser } from "../../user/utils/getVerifiedUser"
|
||||
import { getRedemptionTokenSafely } from "../../../utils/getRedemptionTokenSafely"
|
||||
import { getUserPointsBalance } from "../../../utils/getUserPointsBalance"
|
||||
import { getHotelsAvailabilityByHotelIds } from "../services/getHotelsAvailabilityByHotelIds"
|
||||
|
||||
export type HotelsByHotelIdsAvailabilityInputSchema = z.output<
|
||||
@@ -65,12 +66,13 @@ export const hotelsByHotelIds = safeProtectedServiceProcedure
|
||||
.use(async ({ ctx, input, next }) => {
|
||||
if (input.redemption) {
|
||||
if (ctx.session?.token.access_token) {
|
||||
const verifiedUser = await getVerifiedUser({ session: ctx.session })
|
||||
if (!verifiedUser?.error) {
|
||||
const pointsValue = await getUserPointsBalance(ctx.session)
|
||||
const token = getRedemptionTokenSafely(ctx.session, ctx.serviceToken)
|
||||
if (pointsValue && token) {
|
||||
return next({
|
||||
ctx: {
|
||||
token: ctx.session.token.access_token,
|
||||
userPoints: verifiedUser?.data.membership?.currentPoints ?? 0,
|
||||
token: token,
|
||||
userPoints: pointsValue ?? 0,
|
||||
},
|
||||
input,
|
||||
})
|
||||
|
||||
@@ -6,7 +6,8 @@ import { createLogger } from "@scandic-hotels/common/logger/createLogger"
|
||||
import { SEARCH_TYPE_REDEMPTION } from "../../../constants/booking"
|
||||
import { unauthorizedError } from "../../../errors"
|
||||
import { safeProtectedServiceProcedure } from "../../../procedures"
|
||||
import { getVerifiedUser } from "../../user/utils/getVerifiedUser"
|
||||
import { getRedemptionTokenSafely } from "../../../utils/getRedemptionTokenSafely"
|
||||
import { getUserPointsBalance } from "../../../utils/getUserPointsBalance"
|
||||
import { baseBookingSchema, baseRoomSchema, selectedRoomSchema } from "../input"
|
||||
import { getRoomsAvailability } from "../services/getRoomsAvailability"
|
||||
import { getSelectedRoomAvailability } from "../utils"
|
||||
@@ -24,13 +25,15 @@ export const myStay = safeProtectedServiceProcedure
|
||||
.use(async ({ ctx, input, next }) => {
|
||||
if (input.booking.searchType === SEARCH_TYPE_REDEMPTION) {
|
||||
if (ctx.session?.token.access_token) {
|
||||
const verifiedUser = await getVerifiedUser({ session: ctx.session })
|
||||
if (!verifiedUser?.error) {
|
||||
const pointsValue = await getUserPointsBalance(ctx.session)
|
||||
const token = getRedemptionTokenSafely(ctx.session, ctx.serviceToken)
|
||||
if (pointsValue && token) {
|
||||
return next({
|
||||
ctx: {
|
||||
token: ctx.session.token.access_token,
|
||||
userPoints: verifiedUser?.data.membership?.currentPoints ?? 0,
|
||||
token: token,
|
||||
userPoints: pointsValue ?? 0,
|
||||
},
|
||||
input,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@ import { Lang } from "@scandic-hotels/common/constants/language"
|
||||
import { SEARCH_TYPE_REDEMPTION } from "../../../../constants/booking"
|
||||
import { unauthorizedError } from "../../../../errors"
|
||||
import { safeProtectedServiceProcedure } from "../../../../procedures"
|
||||
import { getVerifiedUser } from "../../../user/utils/getVerifiedUser"
|
||||
import { getRedemptionTokenSafely } from "../../../../utils/getRedemptionTokenSafely"
|
||||
import { getUserPointsBalance } from "../../../../utils/getUserPointsBalance"
|
||||
import { baseBookingSchema, baseRoomSchema } from "../../input"
|
||||
import { getRoomsAvailability } from "../../services/getRoomsAvailability"
|
||||
import { mergeRoomTypes } from "../../utils"
|
||||
@@ -22,15 +23,15 @@ export const room = safeProtectedServiceProcedure
|
||||
.use(async ({ ctx, input, next }) => {
|
||||
if (input.booking.searchType === SEARCH_TYPE_REDEMPTION) {
|
||||
if (ctx.session?.token.access_token) {
|
||||
const verifiedUser = await getVerifiedUser({
|
||||
session: ctx.session,
|
||||
})
|
||||
if (!verifiedUser?.error) {
|
||||
const pointsValue = await getUserPointsBalance(ctx.session)
|
||||
const token = getRedemptionTokenSafely(ctx.session, ctx.serviceToken)
|
||||
if (pointsValue && token) {
|
||||
return next({
|
||||
ctx: {
|
||||
token: ctx.session.token.access_token,
|
||||
userPoints: verifiedUser?.data.membership?.currentPoints ?? 0,
|
||||
token: token,
|
||||
userPoints: pointsValue ?? 0,
|
||||
},
|
||||
input,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@ import "server-only"
|
||||
import { SEARCH_TYPE_REDEMPTION } from "../../../../../constants/booking"
|
||||
import { unauthorizedError } from "../../../../../errors"
|
||||
import { safeProtectedServiceProcedure } from "../../../../../procedures"
|
||||
import { getVerifiedUser } from "../../../../user/utils/getVerifiedUser"
|
||||
import { getRedemptionTokenSafely } from "../../../../../utils/getRedemptionTokenSafely"
|
||||
import { getUserPointsBalance } from "../../../../../utils/getUserPointsBalance"
|
||||
import { getRoomsAvailability } from "../../../services/getRoomsAvailability"
|
||||
import { mergeRoomTypes } from "../../../utils"
|
||||
import { selectRateRoomsAvailabilityInputSchema } from "./schema"
|
||||
@@ -13,15 +14,15 @@ export const rooms = safeProtectedServiceProcedure
|
||||
.use(async ({ ctx, input, next }) => {
|
||||
if (input.booking.searchType === SEARCH_TYPE_REDEMPTION) {
|
||||
if (ctx.session?.token.access_token) {
|
||||
const verifiedUser = await getVerifiedUser({
|
||||
session: ctx.session,
|
||||
})
|
||||
if (!verifiedUser?.error) {
|
||||
const pointsValue = await getUserPointsBalance(ctx.session)
|
||||
const token = getRedemptionTokenSafely(ctx.session, ctx.serviceToken)
|
||||
if (pointsValue && token) {
|
||||
return next({
|
||||
ctx: {
|
||||
token: ctx.session.token.access_token,
|
||||
userPoints: verifiedUser?.data.membership?.currentPoints ?? 0,
|
||||
token: token,
|
||||
userPoints: pointsValue ?? 0,
|
||||
},
|
||||
input,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user