Merged in feature/SW-3516-pass-eurobonus-number-on-booking (pull request #2902)
* feat(SW-3516): Include partnerLoyaltyNumber on bookings - Added user context to BookingFlowProviders for user state management. - Updated booking input and output schemas to accommodate new user data. - Refactored booking mutation logic to include user-related information. - Improved type definitions for better TypeScript support across booking components. Approved-by: Anton Gunnarsson
This commit is contained in:
@@ -1,17 +1,83 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
|
import { useSession } from "next-auth/react"
|
||||||
|
|
||||||
import { BookingFlowContextProvider } from "@scandic-hotels/booking-flow/BookingFlowContextProvider"
|
import { BookingFlowContextProvider } from "@scandic-hotels/booking-flow/BookingFlowContextProvider"
|
||||||
|
import { logger } from "@scandic-hotels/common/logger"
|
||||||
|
import { trpc } from "@scandic-hotels/trpc/client"
|
||||||
|
|
||||||
import { useIsUserLoggedIn } from "../hooks/useIsUserLoggedIn"
|
import type { Session } from "next-auth"
|
||||||
|
import type { ComponentProps, ReactNode } from "react"
|
||||||
import type { ReactNode } from "react"
|
|
||||||
|
|
||||||
export function BookingFlowProviders({ children }: { children: ReactNode }) {
|
export function BookingFlowProviders({ children }: { children: ReactNode }) {
|
||||||
const isLoggedIn = useIsUserLoggedIn()
|
const user = useBookingFlowUser()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BookingFlowContextProvider data={{ isLoggedIn }}>
|
<BookingFlowContextProvider
|
||||||
|
data={{
|
||||||
|
isLoggedIn: user.state === "loaded" && !!user.data,
|
||||||
|
user,
|
||||||
|
}}
|
||||||
|
>
|
||||||
{children}
|
{children}
|
||||||
</BookingFlowContextProvider>
|
</BookingFlowContextProvider>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type BookingFlowContextData = ComponentProps<
|
||||||
|
typeof BookingFlowContextProvider
|
||||||
|
>["data"]
|
||||||
|
type BookingFlowUser = BookingFlowContextData["user"]
|
||||||
|
|
||||||
|
function useBookingFlowUser(): BookingFlowUser {
|
||||||
|
const { data: session } = useSession()
|
||||||
|
const hasValidSession = isValidClientSession(session)
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: euroBonusProfile,
|
||||||
|
isError,
|
||||||
|
isLoading,
|
||||||
|
} = trpc.partner.sas.getEuroBonusProfile.useQuery(undefined, {
|
||||||
|
enabled: hasValidSession,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return { state: "loading", data: undefined }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isError || !euroBonusProfile) {
|
||||||
|
return { state: "error", data: undefined }
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
state: "loaded",
|
||||||
|
data: {
|
||||||
|
type: "partner-sas",
|
||||||
|
partnerLoyaltyNumber: `EB${euroBonusProfile.eurobonusNumber}`,
|
||||||
|
firstName: euroBonusProfile.firstName || null,
|
||||||
|
lastName: euroBonusProfile.lastName || null,
|
||||||
|
email: euroBonusProfile.email,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function isValidClientSession(session: Session | null) {
|
||||||
|
if (!session) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if (session.error) {
|
||||||
|
logger.error(`Session error: ${session.error}`)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (session.token.error) {
|
||||||
|
logger.error(`Session token error: ${session.token.error}`)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if (session.token.expires_at && session.token.expires_at < Date.now()) {
|
||||||
|
logger.error(`Session expired: ${session.token.expires_at}`)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,32 +1,6 @@
|
|||||||
import { useSession } from "next-auth/react"
|
import { useBookingFlowContext } from "@scandic-hotels/booking-flow/hooks/useBookingFlowContext"
|
||||||
|
|
||||||
import { logger } from "@scandic-hotels/common/logger"
|
|
||||||
|
|
||||||
import type { Session } from "next-auth"
|
|
||||||
|
|
||||||
export function useIsUserLoggedIn() {
|
export function useIsUserLoggedIn() {
|
||||||
const { data: session } = useSession()
|
const { isLoggedIn } = useBookingFlowContext()
|
||||||
const isUserLoggedIn = isValidClientSession(session)
|
return isLoggedIn
|
||||||
return isUserLoggedIn
|
|
||||||
}
|
|
||||||
|
|
||||||
function isValidClientSession(session: Session | null) {
|
|
||||||
if (!session) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if (session.error) {
|
|
||||||
logger.error(`Session error: ${session.error}`)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if (session.token.error) {
|
|
||||||
logger.error(`Session token error: ${session.token.error}`)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if (session.token.expires_at && session.token.expires_at < Date.now()) {
|
|
||||||
logger.error(`Session expired: ${session.token.expires_at}`)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ export async function createAppContext() {
|
|||||||
const headersList = await headers()
|
const headersList = await headers()
|
||||||
|
|
||||||
const ctx = createContext({
|
const ctx = createContext({
|
||||||
|
app: "partner-sas",
|
||||||
lang: headersList.get("x-lang") as Lang,
|
lang: headersList.get("x-lang") as Lang,
|
||||||
pathname: headersList.get("x-pathname")!,
|
pathname: headersList.get("x-pathname")!,
|
||||||
uid: headersList.get("x-uid"),
|
uid: headersList.get("x-uid"),
|
||||||
|
|||||||
@@ -1,17 +1,50 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { BookingFlowContextProvider } from "@scandic-hotels/booking-flow/BookingFlowContextProvider"
|
import { BookingFlowContextProvider } from "@scandic-hotels/booking-flow/BookingFlowContextProvider"
|
||||||
|
import { trpc } from "@scandic-hotels/trpc/client"
|
||||||
|
|
||||||
import { useIsUserLoggedIn } from "@/hooks/useIsUserLoggedIn"
|
import { useIsUserLoggedIn } from "@/hooks/useIsUserLoggedIn"
|
||||||
|
|
||||||
import type { ReactNode } from "react"
|
import type { ComponentProps, ReactNode } from "react"
|
||||||
|
|
||||||
export function BookingFlowProviders({ children }: { children: ReactNode }) {
|
export function BookingFlowProviders({ children }: { children: ReactNode }) {
|
||||||
const isLoggedIn = useIsUserLoggedIn()
|
const isLoggedIn = useIsUserLoggedIn()
|
||||||
|
const user = useBookingFlowUser()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BookingFlowContextProvider data={{ isLoggedIn }}>
|
<BookingFlowContextProvider data={{ isLoggedIn, user }}>
|
||||||
{children}
|
{children}
|
||||||
</BookingFlowContextProvider>
|
</BookingFlowContextProvider>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type BookingFlowContextData = ComponentProps<
|
||||||
|
typeof BookingFlowContextProvider
|
||||||
|
>["data"]
|
||||||
|
type BookingFlowUser = BookingFlowContextData["user"]
|
||||||
|
|
||||||
|
function useBookingFlowUser(): BookingFlowUser {
|
||||||
|
const isLoggedIn = useIsUserLoggedIn()
|
||||||
|
const { data, isError, isLoading } = trpc.user.getSafely.useQuery(undefined, {
|
||||||
|
enabled: isLoggedIn,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return { state: "loading", data: undefined }
|
||||||
|
}
|
||||||
|
if (isError || !data) {
|
||||||
|
return { state: "error", data: undefined }
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
state: "loaded",
|
||||||
|
data: {
|
||||||
|
type: "scandic",
|
||||||
|
partnerLoyaltyNumber: null,
|
||||||
|
membershipNumber: data.membershipNumber,
|
||||||
|
firstName: data.firstName || null,
|
||||||
|
lastName: data.lastName || null,
|
||||||
|
email: data.email,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ export async function createAppContext() {
|
|||||||
const loginType = headersList.get("loginType")
|
const loginType = headersList.get("loginType")
|
||||||
|
|
||||||
const ctx = createContext({
|
const ctx = createContext({
|
||||||
|
app: "scandic-web",
|
||||||
lang: headersList.get("x-lang") as Lang,
|
lang: headersList.get("x-lang") as Lang,
|
||||||
pathname: headersList.get("x-pathname")!,
|
pathname: headersList.get("x-pathname")!,
|
||||||
uid: headersList.get("x-uid"),
|
uid: headersList.get("x-uid"),
|
||||||
|
|||||||
@@ -1,23 +1,35 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { createContext, useContext } from "react"
|
import { createContext } from "react"
|
||||||
|
|
||||||
|
type BaseUser = {
|
||||||
|
firstName: string | null
|
||||||
|
lastName: string | null
|
||||||
|
email: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export type BookingFlowUser =
|
||||||
|
| (BaseUser & {
|
||||||
|
type: "partner-sas"
|
||||||
|
partnerLoyaltyNumber: `EB${string}`
|
||||||
|
})
|
||||||
|
| (BaseUser & {
|
||||||
|
type: "scandic"
|
||||||
|
/**
|
||||||
|
* This will always be null for Scandic Friends members
|
||||||
|
*/
|
||||||
|
partnerLoyaltyNumber: null
|
||||||
|
membershipNumber: string
|
||||||
|
})
|
||||||
|
|
||||||
export type BookingFlowContextData = {
|
export type BookingFlowContextData = {
|
||||||
isLoggedIn: boolean
|
isLoggedIn: boolean
|
||||||
|
user:
|
||||||
|
| { state: "loading"; data: undefined }
|
||||||
|
| { state: "error"; data: undefined }
|
||||||
|
| { state: "loaded"; data: BookingFlowUser | undefined }
|
||||||
}
|
}
|
||||||
|
|
||||||
export const BookingFlowContext = createContext<
|
export const BookingFlowContext = createContext<
|
||||||
BookingFlowContextData | undefined
|
BookingFlowContextData | undefined
|
||||||
>(undefined)
|
>(undefined)
|
||||||
|
|
||||||
export const useBookingFlowContext = (): BookingFlowContextData => {
|
|
||||||
const context = useContext(BookingFlowContext)
|
|
||||||
|
|
||||||
if (!context) {
|
|
||||||
throw new Error(
|
|
||||||
"useBookingFlowContext must be used within a BookingFlowContextProvider. Did you forget to use the provider in the consuming app?"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return context
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import { RoomPackageCodeEnum } from "@scandic-hotels/trpc/enums/roomFilter"
|
|||||||
|
|
||||||
import { env } from "../../../../env/client"
|
import { env } from "../../../../env/client"
|
||||||
import { useAvailablePaymentOptions } from "../../../hooks/useAvailablePaymentOptions"
|
import { useAvailablePaymentOptions } from "../../../hooks/useAvailablePaymentOptions"
|
||||||
|
import { useBookingFlowContext } from "../../../hooks/useBookingFlowContext"
|
||||||
import { useHandleBookingStatus } from "../../../hooks/useHandleBookingStatus"
|
import { useHandleBookingStatus } from "../../../hooks/useHandleBookingStatus"
|
||||||
import { useIsLoggedIn } from "../../../hooks/useIsLoggedIn"
|
import { useIsLoggedIn } from "../../../hooks/useIsLoggedIn"
|
||||||
import useLang from "../../../hooks/useLang"
|
import useLang from "../../../hooks/useLang"
|
||||||
@@ -59,6 +60,7 @@ import TermsAndConditions from "./TermsAndConditions"
|
|||||||
|
|
||||||
import styles from "./payment.module.css"
|
import styles from "./payment.module.css"
|
||||||
|
|
||||||
|
import type { CreateBookingInput } from "@scandic-hotels/trpc/routers/booking/mutation/create/schema"
|
||||||
import type { CreditCard } from "@scandic-hotels/trpc/types/user"
|
import type { CreditCard } from "@scandic-hotels/trpc/types/user"
|
||||||
|
|
||||||
import type { PriceChangeData } from "../PriceChangeData"
|
import type { PriceChangeData } from "../PriceChangeData"
|
||||||
@@ -83,6 +85,7 @@ export default function PaymentClient({
|
|||||||
const searchParams = useSearchParams()
|
const searchParams = useSearchParams()
|
||||||
const isUserLoggedIn = useIsLoggedIn()
|
const isUserLoggedIn = useIsLoggedIn()
|
||||||
const { getTopOffset } = useStickyPosition({})
|
const { getTopOffset } = useStickyPosition({})
|
||||||
|
const { user } = useBookingFlowContext()
|
||||||
|
|
||||||
const [showBookingAlert, setShowBookingAlert] = useState(false)
|
const [showBookingAlert, setShowBookingAlert] = useState(false)
|
||||||
|
|
||||||
@@ -397,13 +400,14 @@ export default function PaymentClient({
|
|||||||
}
|
}
|
||||||
writePaymentInfoToSessionStorage(paymentMethodType, !!savedCreditCard)
|
writePaymentInfoToSessionStorage(paymentMethodType, !!savedCreditCard)
|
||||||
|
|
||||||
const payload = {
|
const payload: CreateBookingInput = {
|
||||||
checkInDate: fromDate,
|
checkInDate: fromDate,
|
||||||
checkOutDate: toDate,
|
checkOutDate: toDate,
|
||||||
hotelId,
|
hotelId,
|
||||||
language: lang,
|
language: lang,
|
||||||
payment,
|
payment,
|
||||||
rooms: rooms.map(({ room }, idx) => {
|
rooms: rooms.map(
|
||||||
|
({ room }, idx): CreateBookingInput["rooms"][number] => {
|
||||||
const isMainRoom = idx === 0
|
const isMainRoom = idx === 0
|
||||||
let rateCode = ""
|
let rateCode = ""
|
||||||
if (isMainRoom && isUserLoggedIn) {
|
if (isMainRoom && isUserLoggedIn) {
|
||||||
@@ -422,14 +426,7 @@ export default function PaymentClient({
|
|||||||
room.guest.phoneNumberCC
|
room.guest.phoneNumberCC
|
||||||
)
|
)
|
||||||
|
|
||||||
return {
|
const guest: CreateBookingInput["rooms"][number]["guest"] = {
|
||||||
adults: room.adults,
|
|
||||||
bookingCode: room.roomRate.bookingCode,
|
|
||||||
childrenAges: room.childrenInRoom?.map((child) => ({
|
|
||||||
age: child.age,
|
|
||||||
bedType: bedTypeMap[parseInt(child.bed.toString())],
|
|
||||||
})),
|
|
||||||
guest: {
|
|
||||||
becomeMember: room.guest.join,
|
becomeMember: room.guest.join,
|
||||||
countryCode: room.guest.countryCode,
|
countryCode: room.guest.countryCode,
|
||||||
email: room.guest.email,
|
email: room.guest.email,
|
||||||
@@ -437,19 +434,24 @@ export default function PaymentClient({
|
|||||||
lastName: room.guest.lastName,
|
lastName: room.guest.lastName,
|
||||||
membershipNumber: room.guest.membershipNo,
|
membershipNumber: room.guest.membershipNo,
|
||||||
phoneNumber,
|
phoneNumber,
|
||||||
// Only allowed for room one
|
partnerLoyaltyNumber: null,
|
||||||
...(idx === 0 && {
|
}
|
||||||
dateOfBirth:
|
|
||||||
|
if (isMainRoom) {
|
||||||
|
// Only valid for main room
|
||||||
|
guest.partnerLoyaltyNumber =
|
||||||
|
user?.data?.partnerLoyaltyNumber || null
|
||||||
|
guest.dateOfBirth =
|
||||||
"dateOfBirth" in room.guest && room.guest.dateOfBirth
|
"dateOfBirth" in room.guest && room.guest.dateOfBirth
|
||||||
? room.guest.dateOfBirth
|
? room.guest.dateOfBirth
|
||||||
: undefined,
|
: undefined
|
||||||
postalCode:
|
guest.postalCode =
|
||||||
"zipCode" in room.guest && room.guest.zipCode
|
"zipCode" in room.guest && room.guest.zipCode
|
||||||
? room.guest.zipCode
|
? room.guest.zipCode
|
||||||
: undefined,
|
: undefined
|
||||||
}),
|
}
|
||||||
},
|
|
||||||
packages: {
|
const packages: CreateBookingInput["rooms"][number]["packages"] = {
|
||||||
accessibility:
|
accessibility:
|
||||||
room.roomFeatures?.some(
|
room.roomFeatures?.some(
|
||||||
(feature) =>
|
(feature) =>
|
||||||
@@ -464,7 +466,17 @@ export default function PaymentClient({
|
|||||||
room.roomFeatures?.some(
|
room.roomFeatures?.some(
|
||||||
(feature) => feature.code === RoomPackageCodeEnum.PET_ROOM
|
(feature) => feature.code === RoomPackageCodeEnum.PET_ROOM
|
||||||
) ?? false,
|
) ?? false,
|
||||||
},
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
adults: room.adults,
|
||||||
|
bookingCode: room.roomRate.bookingCode,
|
||||||
|
childrenAges: room.childrenInRoom?.map((child) => ({
|
||||||
|
age: child.age,
|
||||||
|
bedType: bedTypeMap[parseInt(child.bed.toString())],
|
||||||
|
})),
|
||||||
|
guest,
|
||||||
|
packages,
|
||||||
rateCode,
|
rateCode,
|
||||||
roomPrice: {
|
roomPrice: {
|
||||||
memberPrice:
|
memberPrice:
|
||||||
@@ -484,27 +496,29 @@ export default function PaymentClient({
|
|||||||
: undefined,
|
: undefined,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}),
|
}
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
initiateBooking.mutate(payload)
|
initiateBooking.mutate(payload)
|
||||||
},
|
},
|
||||||
[
|
[
|
||||||
|
setIsSubmitting,
|
||||||
|
preSubmitCallbacks,
|
||||||
|
rooms,
|
||||||
|
getPaymentMethod,
|
||||||
savedCreditCards,
|
savedCreditCards,
|
||||||
lang,
|
lang,
|
||||||
initiateBooking,
|
bookingMustBeGuaranteed,
|
||||||
hotelId,
|
hasOnlyFlexRates,
|
||||||
fromDate,
|
fromDate,
|
||||||
toDate,
|
toDate,
|
||||||
rooms,
|
hotelId,
|
||||||
booking.rooms,
|
initiateBooking,
|
||||||
getPaymentMethod,
|
|
||||||
hasOnlyFlexRates,
|
|
||||||
bookingMustBeGuaranteed,
|
|
||||||
preSubmitCallbacks,
|
|
||||||
isUserLoggedIn,
|
|
||||||
getTopOffset,
|
getTopOffset,
|
||||||
setIsSubmitting,
|
isUserLoggedIn,
|
||||||
|
booking.rooms,
|
||||||
|
user?.data?.partnerLoyaltyNumber,
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
18
packages/booking-flow/lib/hooks/useBookingFlowContext.ts
Normal file
18
packages/booking-flow/lib/hooks/useBookingFlowContext.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { useContext } from "react"
|
||||||
|
|
||||||
|
import {
|
||||||
|
BookingFlowContext,
|
||||||
|
type BookingFlowContextData,
|
||||||
|
} from "../bookingFlowContext"
|
||||||
|
|
||||||
|
export const useBookingFlowContext = (): BookingFlowContextData => {
|
||||||
|
const context = useContext(BookingFlowContext)
|
||||||
|
|
||||||
|
if (!context) {
|
||||||
|
throw new Error(
|
||||||
|
"useBookingFlowContext must be used within a BookingFlowContextProvider. Did you forget to use the provider in the consuming app?"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return context
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useBookingFlowContext } from "../bookingFlowContext"
|
import { useBookingFlowContext } from "./useBookingFlowContext"
|
||||||
|
|
||||||
export function useIsLoggedIn() {
|
export function useIsLoggedIn() {
|
||||||
const data = useBookingFlowContext()
|
const data = useBookingFlowContext()
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
"./global.d.ts": "./global.d.ts",
|
"./global.d.ts": "./global.d.ts",
|
||||||
"./hooks/useHandleBookingStatus": "./lib/hooks/useHandleBookingStatus.ts",
|
"./hooks/useHandleBookingStatus": "./lib/hooks/useHandleBookingStatus.ts",
|
||||||
"./hooks/useBookingWidgetState": "./lib/hooks/useBookingWidgetState.ts",
|
"./hooks/useBookingWidgetState": "./lib/hooks/useBookingWidgetState.ts",
|
||||||
|
"./hooks/useBookingFlowContext": "./lib/hooks/useBookingFlowContext.ts",
|
||||||
"./pages/*": "./lib/pages/*.tsx",
|
"./pages/*": "./lib/pages/*.tsx",
|
||||||
"./stores/enter-details/types": "./lib/stores/enter-details/types.ts",
|
"./stores/enter-details/types": "./lib/stores/enter-details/types.ts",
|
||||||
"./stores/hotels-map": "./lib/stores/hotels-map.ts",
|
"./stores/hotels-map": "./lib/stores/hotels-map.ts",
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ type CreateContextOptions = {
|
|||||||
url: string
|
url: string
|
||||||
webToken?: string
|
webToken?: string
|
||||||
contentType?: string
|
contentType?: string
|
||||||
|
app: "scandic-web" | "partner-sas"
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createContext(opts: CreateContextOptions) {
|
export function createContext(opts: CreateContextOptions) {
|
||||||
|
|||||||
@@ -3,106 +3,6 @@ import { z } from "zod"
|
|||||||
import { Lang } from "@scandic-hotels/common/constants/language"
|
import { Lang } from "@scandic-hotels/common/constants/language"
|
||||||
|
|
||||||
import { langToApiLang } from "../../constants/apiLang"
|
import { langToApiLang } from "../../constants/apiLang"
|
||||||
import { ChildBedTypeEnum } from "../../enums/childBedTypeEnum"
|
|
||||||
|
|
||||||
const roomsSchema = z
|
|
||||||
.array(
|
|
||||||
z.object({
|
|
||||||
adults: z.number().int().nonnegative(),
|
|
||||||
bookingCode: z.string().nullish(),
|
|
||||||
childrenAges: z
|
|
||||||
.array(
|
|
||||||
z.object({
|
|
||||||
age: z.number().int().nonnegative(),
|
|
||||||
bedType: z.nativeEnum(ChildBedTypeEnum),
|
|
||||||
})
|
|
||||||
)
|
|
||||||
.default([]),
|
|
||||||
rateCode: z.string(),
|
|
||||||
redemptionCode: z.string().optional(),
|
|
||||||
roomTypeCode: z.coerce.string(),
|
|
||||||
guest: z.object({
|
|
||||||
becomeMember: z.boolean(),
|
|
||||||
countryCode: z.string(),
|
|
||||||
dateOfBirth: z.string().nullish(),
|
|
||||||
email: z.string().email(),
|
|
||||||
firstName: z.string(),
|
|
||||||
lastName: z.string(),
|
|
||||||
membershipNumber: z.string().nullish(),
|
|
||||||
postalCode: z.string().nullish(),
|
|
||||||
phoneNumber: z.string(),
|
|
||||||
}),
|
|
||||||
smsConfirmationRequested: z.boolean(),
|
|
||||||
specialRequest: z.object({
|
|
||||||
comment: z.string().optional(),
|
|
||||||
}),
|
|
||||||
packages: z.object({
|
|
||||||
breakfast: z.boolean(),
|
|
||||||
allergyFriendly: z.boolean(),
|
|
||||||
petFriendly: z.boolean(),
|
|
||||||
accessibility: z.boolean(),
|
|
||||||
}),
|
|
||||||
roomPrice: z.object({
|
|
||||||
memberPrice: z.number().nullish(),
|
|
||||||
publicPrice: z.number().nullish(),
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
)
|
|
||||||
.superRefine((data, ctx) => {
|
|
||||||
data.forEach((room, idx) => {
|
|
||||||
if (idx === 0 && room.guest.becomeMember) {
|
|
||||||
if (!room.guest.dateOfBirth) {
|
|
||||||
ctx.addIssue({
|
|
||||||
code: z.ZodIssueCode.invalid_type,
|
|
||||||
expected: "string",
|
|
||||||
received: typeof room.guest.dateOfBirth,
|
|
||||||
path: ["guest", "dateOfBirth"],
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!room.guest.postalCode) {
|
|
||||||
ctx.addIssue({
|
|
||||||
code: z.ZodIssueCode.invalid_type,
|
|
||||||
expected: "string",
|
|
||||||
received: typeof room.guest.postalCode,
|
|
||||||
path: ["guest", "postalCode"],
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
const paymentSchema = z.object({
|
|
||||||
paymentMethod: z.string(),
|
|
||||||
card: z
|
|
||||||
.object({
|
|
||||||
alias: z.string(),
|
|
||||||
expiryDate: z.string(),
|
|
||||||
cardType: z.string(),
|
|
||||||
})
|
|
||||||
.optional(),
|
|
||||||
cardHolder: z
|
|
||||||
.object({
|
|
||||||
email: z.string().email(),
|
|
||||||
name: z.string(),
|
|
||||||
phoneCountryCode: z.string(),
|
|
||||||
phoneSubscriber: z.string(),
|
|
||||||
})
|
|
||||||
.optional(),
|
|
||||||
success: z.string(),
|
|
||||||
error: z.string(),
|
|
||||||
cancel: z.string(),
|
|
||||||
})
|
|
||||||
|
|
||||||
// Mutation
|
|
||||||
export const createBookingInput = z.object({
|
|
||||||
hotelId: z.string(),
|
|
||||||
checkInDate: z.string(),
|
|
||||||
checkOutDate: z.string(),
|
|
||||||
rooms: roomsSchema,
|
|
||||||
payment: paymentSchema.optional(),
|
|
||||||
language: z.nativeEnum(Lang).transform((val) => langToApiLang[val]),
|
|
||||||
})
|
|
||||||
|
|
||||||
export const addPackageInput = z.object({
|
export const addPackageInput = z.object({
|
||||||
ancillaryComment: z.string(),
|
ancillaryComment: z.string(),
|
||||||
|
|||||||
83
packages/trpc/lib/routers/booking/mutation/create/index.ts
Normal file
83
packages/trpc/lib/routers/booking/mutation/create/index.ts
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
import "server-only"
|
||||||
|
|
||||||
|
import { createCounter } from "@scandic-hotels/common/telemetry"
|
||||||
|
|
||||||
|
import * as api from "../../../../api"
|
||||||
|
import { safeProtectedServiceProcedure } from "../../../../procedures"
|
||||||
|
import { encrypt } from "../../../../utils/encryption"
|
||||||
|
import { isValidSession } from "../../../../utils/session"
|
||||||
|
import { getMembershipNumber } from "../../../user/utils"
|
||||||
|
import { createBookingInput, createBookingSchema } from "./schema"
|
||||||
|
|
||||||
|
export const create = safeProtectedServiceProcedure
|
||||||
|
.input(createBookingInput)
|
||||||
|
.use(async ({ ctx, next }) => {
|
||||||
|
const token = isValidSession(ctx.session)
|
||||||
|
? ctx.session.token.access_token
|
||||||
|
: ctx.serviceToken
|
||||||
|
|
||||||
|
return next({
|
||||||
|
ctx: {
|
||||||
|
token,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.mutation(async function ({ ctx, input }) {
|
||||||
|
const { language, ...inputWithoutLang } = input
|
||||||
|
const { rooms, ...loggableInput } = inputWithoutLang
|
||||||
|
|
||||||
|
const createBookingCounter = createCounter("trpc.booking", "create")
|
||||||
|
const metricsCreateBooking = createBookingCounter.init({
|
||||||
|
membershipNumber: await getMembershipNumber(ctx.session),
|
||||||
|
language,
|
||||||
|
...loggableInput,
|
||||||
|
rooms: inputWithoutLang.rooms.map(({ guest, ...room }) => {
|
||||||
|
const { becomeMember, membershipNumber } = guest
|
||||||
|
return { ...room, guest: { becomeMember, membershipNumber } }
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
|
||||||
|
metricsCreateBooking.start()
|
||||||
|
|
||||||
|
const headers = {
|
||||||
|
Authorization: `Bearer ${ctx.token}`,
|
||||||
|
}
|
||||||
|
|
||||||
|
const apiResponse = await api.post(
|
||||||
|
api.endpoints.v1.Booking.bookings,
|
||||||
|
{
|
||||||
|
headers,
|
||||||
|
body: inputWithoutLang,
|
||||||
|
},
|
||||||
|
{ language }
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!apiResponse.ok) {
|
||||||
|
await metricsCreateBooking.httpError(apiResponse)
|
||||||
|
|
||||||
|
const apiJson = await apiResponse.json()
|
||||||
|
if ("errors" in apiJson && apiJson.errors.length) {
|
||||||
|
const error = apiJson.errors[0]
|
||||||
|
return { error: true, cause: error.code } as const
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
const apiJson = await apiResponse.json()
|
||||||
|
|
||||||
|
const verifiedData = createBookingSchema.safeParse(apiJson)
|
||||||
|
if (!verifiedData.success) {
|
||||||
|
metricsCreateBooking.validationError(verifiedData.error)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
metricsCreateBooking.success()
|
||||||
|
|
||||||
|
const expire = Math.floor(Date.now() / 1000) + 60 // 1 minute expiry
|
||||||
|
|
||||||
|
return {
|
||||||
|
booking: verifiedData.data,
|
||||||
|
sig: encrypt(expire.toString()),
|
||||||
|
}
|
||||||
|
})
|
||||||
173
packages/trpc/lib/routers/booking/mutation/create/schema.ts
Normal file
173
packages/trpc/lib/routers/booking/mutation/create/schema.ts
Normal file
@@ -0,0 +1,173 @@
|
|||||||
|
import { z } from "zod"
|
||||||
|
|
||||||
|
import { Lang } from "@scandic-hotels/common/constants/language"
|
||||||
|
|
||||||
|
import { langToApiLang } from "../../../../constants/apiLang"
|
||||||
|
import { ChildBedTypeEnum } from "../../../../enums/childBedTypeEnum"
|
||||||
|
import { calculateRefId } from "../../../../utils/refId"
|
||||||
|
import { guestSchema } from "../../output"
|
||||||
|
|
||||||
|
const roomsSchema = z
|
||||||
|
.array(
|
||||||
|
z.object({
|
||||||
|
adults: z.number().int().nonnegative(),
|
||||||
|
bookingCode: z.string().nullish(),
|
||||||
|
childrenAges: z
|
||||||
|
.array(
|
||||||
|
z.object({
|
||||||
|
age: z.number().int().nonnegative(),
|
||||||
|
bedType: z.nativeEnum(ChildBedTypeEnum),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.default([]),
|
||||||
|
rateCode: z.string(),
|
||||||
|
redemptionCode: z.string().optional(),
|
||||||
|
roomTypeCode: z.coerce.string(),
|
||||||
|
guest: z.object({
|
||||||
|
becomeMember: z.boolean(),
|
||||||
|
countryCode: z.string(),
|
||||||
|
dateOfBirth: z.string().nullish(),
|
||||||
|
email: z.string().email(),
|
||||||
|
firstName: z.string(),
|
||||||
|
lastName: z.string(),
|
||||||
|
membershipNumber: z.string().nullish(),
|
||||||
|
postalCode: z.string().nullish(),
|
||||||
|
phoneNumber: z.string(),
|
||||||
|
partnerLoyaltyNumber: z.string().nullable(),
|
||||||
|
}),
|
||||||
|
smsConfirmationRequested: z.boolean(),
|
||||||
|
specialRequest: z.object({
|
||||||
|
comment: z.string().optional(),
|
||||||
|
}),
|
||||||
|
packages: z.object({
|
||||||
|
breakfast: z.boolean(),
|
||||||
|
allergyFriendly: z.boolean(),
|
||||||
|
petFriendly: z.boolean(),
|
||||||
|
accessibility: z.boolean(),
|
||||||
|
}),
|
||||||
|
roomPrice: z.object({
|
||||||
|
memberPrice: z.number().nullish(),
|
||||||
|
publicPrice: z.number().nullish(),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.superRefine((data, ctx) => {
|
||||||
|
data.forEach((room, idx) => {
|
||||||
|
if (idx === 0 && room.guest.becomeMember) {
|
||||||
|
if (!room.guest.dateOfBirth) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.invalid_type,
|
||||||
|
expected: "string",
|
||||||
|
received: typeof room.guest.dateOfBirth,
|
||||||
|
path: ["guest", "dateOfBirth"],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!room.guest.postalCode) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.invalid_type,
|
||||||
|
expected: "string",
|
||||||
|
received: typeof room.guest.postalCode,
|
||||||
|
path: ["guest", "postalCode"],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const paymentSchema = z.object({
|
||||||
|
paymentMethod: z.string(),
|
||||||
|
card: z
|
||||||
|
.object({
|
||||||
|
alias: z.string(),
|
||||||
|
expiryDate: z.string(),
|
||||||
|
cardType: z.string(),
|
||||||
|
})
|
||||||
|
.optional(),
|
||||||
|
cardHolder: z
|
||||||
|
.object({
|
||||||
|
email: z.string().email(),
|
||||||
|
name: z.string(),
|
||||||
|
phoneCountryCode: z.string(),
|
||||||
|
phoneSubscriber: z.string(),
|
||||||
|
})
|
||||||
|
.optional(),
|
||||||
|
success: z.string(),
|
||||||
|
error: z.string(),
|
||||||
|
cancel: z.string(),
|
||||||
|
})
|
||||||
|
|
||||||
|
export type CreateBookingInput = z.input<typeof createBookingInput>
|
||||||
|
export const createBookingInput = z.object({
|
||||||
|
hotelId: z.string(),
|
||||||
|
checkInDate: z.string(),
|
||||||
|
checkOutDate: z.string(),
|
||||||
|
rooms: roomsSchema,
|
||||||
|
payment: paymentSchema.optional(),
|
||||||
|
language: z.nativeEnum(Lang).transform((val) => langToApiLang[val]),
|
||||||
|
})
|
||||||
|
|
||||||
|
export const createBookingSchema = z
|
||||||
|
.object({
|
||||||
|
data: z.object({
|
||||||
|
attributes: z.object({
|
||||||
|
reservationStatus: z.string(),
|
||||||
|
guest: guestSchema.optional(),
|
||||||
|
paymentUrl: z.string().nullable().optional(),
|
||||||
|
rooms: z
|
||||||
|
.array(
|
||||||
|
z.object({
|
||||||
|
confirmationNumber: z.string(),
|
||||||
|
cancellationNumber: z.string().nullable(),
|
||||||
|
priceChangedMetadata: z
|
||||||
|
.object({
|
||||||
|
roomPrice: z.number(),
|
||||||
|
totalPrice: z.number(),
|
||||||
|
})
|
||||||
|
.nullable()
|
||||||
|
.optional(),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.default([]),
|
||||||
|
errors: z
|
||||||
|
.array(
|
||||||
|
z.object({
|
||||||
|
confirmationNumber: z.string().nullable().optional(),
|
||||||
|
errorCode: z.string(),
|
||||||
|
description: z.string().nullable().optional(),
|
||||||
|
meta: z
|
||||||
|
.record(z.string(), z.union([z.string(), z.number()]))
|
||||||
|
.nullable()
|
||||||
|
.optional(),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.default([]),
|
||||||
|
}),
|
||||||
|
type: z.string(),
|
||||||
|
id: z.string(),
|
||||||
|
links: z.object({
|
||||||
|
self: z.object({
|
||||||
|
href: z.string().url(),
|
||||||
|
meta: z.object({
|
||||||
|
method: z.string(),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
.transform((d) => ({
|
||||||
|
id: d.data.id,
|
||||||
|
links: d.data.links,
|
||||||
|
type: d.data.type,
|
||||||
|
reservationStatus: d.data.attributes.reservationStatus,
|
||||||
|
paymentUrl: d.data.attributes.paymentUrl,
|
||||||
|
rooms: d.data.attributes.rooms.map((room) => {
|
||||||
|
const lastName = d.data.attributes.guest?.lastName ?? ""
|
||||||
|
return {
|
||||||
|
...room,
|
||||||
|
refId: calculateRefId(room.confirmationNumber, lastName),
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
errors: d.data.attributes.errors,
|
||||||
|
guest: d.data.attributes.guest,
|
||||||
|
}))
|
||||||
@@ -1,100 +1,28 @@
|
|||||||
import { createLogger } from "@scandic-hotels/common/logger/createLogger"
|
import { createLogger } from "@scandic-hotels/common/logger/createLogger"
|
||||||
import { createCounter } from "@scandic-hotels/common/telemetry"
|
import { createCounter } from "@scandic-hotels/common/telemetry"
|
||||||
|
|
||||||
import { router } from "../.."
|
import { router } from "../../.."
|
||||||
import * as api from "../../api"
|
import * as api from "../../../api"
|
||||||
import { createRefIdPlugin } from "../../plugins/refIdToConfirmationNumber"
|
import { createRefIdPlugin } from "../../../plugins/refIdToConfirmationNumber"
|
||||||
import { safeProtectedServiceProcedure } from "../../procedures"
|
import { safeProtectedServiceProcedure } from "../../../procedures"
|
||||||
import { encrypt } from "../../utils/encryption"
|
import { isValidSession } from "../../../utils/session"
|
||||||
import { isValidSession } from "../../utils/session"
|
|
||||||
import { getMembershipNumber } from "../user/utils/getMemberShipNumber"
|
|
||||||
import {
|
import {
|
||||||
addPackageInput,
|
addPackageInput,
|
||||||
cancelBookingsInput,
|
cancelBookingsInput,
|
||||||
createBookingInput,
|
|
||||||
guaranteeBookingInput,
|
guaranteeBookingInput,
|
||||||
removePackageInput,
|
removePackageInput,
|
||||||
updateBookingInput,
|
updateBookingInput,
|
||||||
} from "./input"
|
} from "../input"
|
||||||
import { bookingConfirmationSchema, createBookingSchema } from "./output"
|
import { bookingConfirmationSchema } from "../output"
|
||||||
import { cancelBooking } from "./utils"
|
import { cancelBooking } from "../utils"
|
||||||
|
import { createBookingSchema } from "./create/schema"
|
||||||
|
import { create } from "./create"
|
||||||
|
|
||||||
const refIdPlugin = createRefIdPlugin()
|
const refIdPlugin = createRefIdPlugin()
|
||||||
const bookingLogger = createLogger("trpc.booking")
|
const bookingLogger = createLogger("trpc.booking")
|
||||||
|
|
||||||
export const bookingMutationRouter = router({
|
export const bookingMutationRouter = router({
|
||||||
create: safeProtectedServiceProcedure
|
create,
|
||||||
.input(createBookingInput)
|
|
||||||
.use(async ({ ctx, next }) => {
|
|
||||||
const token = isValidSession(ctx.session)
|
|
||||||
? ctx.session.token.access_token
|
|
||||||
: ctx.serviceToken
|
|
||||||
|
|
||||||
return next({
|
|
||||||
ctx: {
|
|
||||||
token,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.mutation(async function ({ ctx, input }) {
|
|
||||||
const { language, ...inputWithoutLang } = input
|
|
||||||
const { rooms, ...loggableInput } = inputWithoutLang
|
|
||||||
|
|
||||||
const createBookingCounter = createCounter("trpc.booking", "create")
|
|
||||||
const metricsCreateBooking = createBookingCounter.init({
|
|
||||||
membershipNumber: await getMembershipNumber(ctx.session),
|
|
||||||
language,
|
|
||||||
...loggableInput,
|
|
||||||
rooms: inputWithoutLang.rooms.map(({ guest, ...room }) => {
|
|
||||||
const { becomeMember, membershipNumber } = guest
|
|
||||||
return { ...room, guest: { becomeMember, membershipNumber } }
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
|
|
||||||
metricsCreateBooking.start()
|
|
||||||
|
|
||||||
const headers = {
|
|
||||||
Authorization: `Bearer ${ctx.token}`,
|
|
||||||
}
|
|
||||||
|
|
||||||
const apiResponse = await api.post(
|
|
||||||
api.endpoints.v1.Booking.bookings,
|
|
||||||
{
|
|
||||||
headers,
|
|
||||||
body: inputWithoutLang,
|
|
||||||
},
|
|
||||||
{ language }
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!apiResponse.ok) {
|
|
||||||
await metricsCreateBooking.httpError(apiResponse)
|
|
||||||
|
|
||||||
const apiJson = await apiResponse.json()
|
|
||||||
if ("errors" in apiJson && apiJson.errors.length) {
|
|
||||||
const error = apiJson.errors[0]
|
|
||||||
return { error: true, cause: error.code } as const
|
|
||||||
}
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
const apiJson = await apiResponse.json()
|
|
||||||
|
|
||||||
const verifiedData = createBookingSchema.safeParse(apiJson)
|
|
||||||
if (!verifiedData.success) {
|
|
||||||
metricsCreateBooking.validationError(verifiedData.error)
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
metricsCreateBooking.success()
|
|
||||||
|
|
||||||
const expire = Math.floor(Date.now() / 1000) + 60 // 1 minute expiry
|
|
||||||
|
|
||||||
return {
|
|
||||||
booking: verifiedData.data,
|
|
||||||
sig: encrypt(expire.toString()),
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
priceChange: safeProtectedServiceProcedure
|
priceChange: safeProtectedServiceProcedure
|
||||||
.concat(refIdPlugin.toConfirmationNumber)
|
.concat(refIdPlugin.toConfirmationNumber)
|
||||||
.use(async ({ ctx, next }) => {
|
.use(async ({ ctx, next }) => {
|
||||||
@@ -13,7 +13,7 @@ import { BreakfastPackageEnum } from "../../enums/breakfast"
|
|||||||
import { ChildBedTypeEnum } from "../../enums/childBedTypeEnum"
|
import { ChildBedTypeEnum } from "../../enums/childBedTypeEnum"
|
||||||
import { calculateRefId } from "../../utils/refId"
|
import { calculateRefId } from "../../utils/refId"
|
||||||
|
|
||||||
const guestSchema = z.object({
|
export const guestSchema = z.object({
|
||||||
email: nullableStringEmailValidator,
|
email: nullableStringEmailValidator,
|
||||||
firstName: nullableStringValidator,
|
firstName: nullableStringValidator,
|
||||||
lastName: nullableStringValidator,
|
lastName: nullableStringValidator,
|
||||||
@@ -24,72 +24,6 @@ const guestSchema = z.object({
|
|||||||
|
|
||||||
export type Guest = z.output<typeof guestSchema>
|
export type Guest = z.output<typeof guestSchema>
|
||||||
|
|
||||||
// MUTATION
|
|
||||||
export const createBookingSchema = z
|
|
||||||
.object({
|
|
||||||
data: z.object({
|
|
||||||
attributes: z.object({
|
|
||||||
reservationStatus: z.string(),
|
|
||||||
guest: guestSchema.optional(),
|
|
||||||
paymentUrl: z.string().nullable().optional(),
|
|
||||||
rooms: z
|
|
||||||
.array(
|
|
||||||
z.object({
|
|
||||||
confirmationNumber: z.string(),
|
|
||||||
cancellationNumber: z.string().nullable(),
|
|
||||||
priceChangedMetadata: z
|
|
||||||
.object({
|
|
||||||
roomPrice: z.number(),
|
|
||||||
totalPrice: z.number(),
|
|
||||||
})
|
|
||||||
.nullable()
|
|
||||||
.optional(),
|
|
||||||
})
|
|
||||||
)
|
|
||||||
.default([]),
|
|
||||||
errors: z
|
|
||||||
.array(
|
|
||||||
z.object({
|
|
||||||
confirmationNumber: z.string().nullable().optional(),
|
|
||||||
errorCode: z.string(),
|
|
||||||
description: z.string().nullable().optional(),
|
|
||||||
meta: z
|
|
||||||
.record(z.string(), z.union([z.string(), z.number()]))
|
|
||||||
.nullable()
|
|
||||||
.optional(),
|
|
||||||
})
|
|
||||||
)
|
|
||||||
.default([]),
|
|
||||||
}),
|
|
||||||
type: z.string(),
|
|
||||||
id: z.string(),
|
|
||||||
links: z.object({
|
|
||||||
self: z.object({
|
|
||||||
href: z.string().url(),
|
|
||||||
meta: z.object({
|
|
||||||
method: z.string(),
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
.transform((d) => ({
|
|
||||||
id: d.data.id,
|
|
||||||
links: d.data.links,
|
|
||||||
type: d.data.type,
|
|
||||||
reservationStatus: d.data.attributes.reservationStatus,
|
|
||||||
paymentUrl: d.data.attributes.paymentUrl,
|
|
||||||
rooms: d.data.attributes.rooms.map((room) => {
|
|
||||||
const lastName = d.data.attributes.guest?.lastName ?? ""
|
|
||||||
return {
|
|
||||||
...room,
|
|
||||||
refId: calculateRefId(room.confirmationNumber, lastName),
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
errors: d.data.attributes.errors,
|
|
||||||
guest: d.data.attributes.guest,
|
|
||||||
}))
|
|
||||||
|
|
||||||
// QUERY
|
// QUERY
|
||||||
const childBedPreferencesSchema = z.object({
|
const childBedPreferencesSchema = z.object({
|
||||||
bedType: z.nativeEnum(ChildBedTypeEnum),
|
bedType: z.nativeEnum(ChildBedTypeEnum),
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import { toApiLang } from "../../utils"
|
|||||||
import { encrypt } from "../../utils/encryption"
|
import { encrypt } from "../../utils/encryption"
|
||||||
import { isValidSession } from "../../utils/session"
|
import { isValidSession } from "../../utils/session"
|
||||||
import { getHotel } from "../hotels/services/getHotel"
|
import { getHotel } from "../hotels/services/getHotel"
|
||||||
|
import { createBookingSchema } from "./mutation/create/schema"
|
||||||
import { getHotelRoom } from "./helpers"
|
import { getHotelRoom } from "./helpers"
|
||||||
import {
|
import {
|
||||||
createRefIdInput,
|
createRefIdInput,
|
||||||
@@ -20,7 +21,6 @@ import {
|
|||||||
getBookingStatusInput,
|
getBookingStatusInput,
|
||||||
getLinkedReservationsInput,
|
getLinkedReservationsInput,
|
||||||
} from "./input"
|
} from "./input"
|
||||||
import { createBookingSchema } from "./output"
|
|
||||||
import { findBooking, getBooking } from "./utils"
|
import { findBooking, getBooking } from "./utils"
|
||||||
|
|
||||||
const refIdPlugin = createRefIdPlugin()
|
const refIdPlugin = createRefIdPlugin()
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ import { createCounter } from "@scandic-hotels/common/telemetry"
|
|||||||
import * as api from "../../api"
|
import * as api from "../../api"
|
||||||
import { badRequestError, serverErrorByStatus } from "../../errors"
|
import { badRequestError, serverErrorByStatus } from "../../errors"
|
||||||
import { toApiLang } from "../../utils"
|
import { toApiLang } from "../../utils"
|
||||||
import { bookingConfirmationSchema, createBookingSchema } from "./output"
|
import { createBookingSchema } from "./mutation/create/schema"
|
||||||
|
import { bookingConfirmationSchema } from "./output"
|
||||||
|
|
||||||
import type { Lang } from "@scandic-hotels/common/constants/language"
|
import type { Lang } from "@scandic-hotels/common/constants/language"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user