feat(SW-791): make confirmation page dynamic

This commit is contained in:
Simon Emanuelsson
2024-11-06 16:31:03 +01:00
parent e6a70a0a8a
commit 0897a398ee
35 changed files with 983 additions and 577 deletions

View File

@@ -2,6 +2,10 @@ import { z } from "zod"
import { ChildBedTypeEnum } from "@/constants/booking"
import { phoneValidator } from "@/utils/phoneValidator"
import { CurrencyEnum } from "@/types/enums/currency"
// MUTATION
export const createBookingSchema = z
.object({
@@ -42,20 +46,20 @@ const extraBedTypesSchema = z.object({
})
const guestSchema = z.object({
email: z.string().email().nullable().default(""),
firstName: z.string(),
lastName: z.string(),
email: z.string().nullable(),
phoneNumber: z.string().nullable(),
phoneNumber: phoneValidator().nullable().default(""),
})
const packagesSchema = z.array(
z.object({
accessibility: z.boolean().optional(),
allergyFriendly: z.boolean().optional(),
breakfast: z.boolean().optional(),
petFriendly: z.boolean().optional(),
})
)
const packageSchema = z.object({
code: z.string().default(""),
currency: z.nativeEnum(CurrencyEnum),
quantity: z.number().int(),
totalPrice: z.number(),
totalQuantity: z.number().int(),
unitPrice: z.number(),
})
export const bookingConfirmationSchema = z
.object({
@@ -66,17 +70,21 @@ export const bookingConfirmationSchema = z
checkOutDate: z.date({ coerce: true }),
createDateTime: z.date({ coerce: true }),
childrenAges: z.array(z.number()),
extraBedTypes: z.array(extraBedTypesSchema),
extraBedTypes: z.array(extraBedTypesSchema).default([]),
computedReservationStatus: z.string(),
confirmationNumber: z.string(),
currencyCode: z.string(),
currencyCode: z.nativeEnum(CurrencyEnum),
guest: guestSchema,
hasPayRouting: z.boolean().optional(),
hotelId: z.string(),
packages: packagesSchema,
packages: z.array(packageSchema),
rateCode: z.string(),
reservationStatus: z.string(),
roomPrice: z.number().int(),
roomTypeCode: z.string(),
totalPrice: z.number(),
totalPriceExVat: z.number(),
vatAmount: z.number(),
vatPercentage: z.number(),
}),
id: z.string(),
type: z.literal("booking"),

View File

@@ -1,6 +1,7 @@
import { metrics } from "@opentelemetry/api"
import * as api from "@/lib/api"
import { dt } from "@/lib/dt"
import { badRequestError, serverErrorByStatus } from "@/server/errors/trpc"
import { router, serviceProcedure } from "@/server/trpc"
@@ -87,6 +88,28 @@ export const bookingQueryRouter = router({
ctx.serviceToken
)
if (!hotelData) {
getBookingConfirmationFailCounter.add(1, {
confirmationNumber,
hotelId: booking.data.hotelId,
error_type: "http_error",
error: "Couldn`t get hotel",
})
console.error(
"api.booking.confirmation error",
JSON.stringify({
query: { confirmationNumber, hotelId: booking.data.hotelId },
error: {
status: apiResponse.status,
statusText: apiResponse.statusText,
text: "Couldn`t get hotel",
},
})
)
throw serverErrorByStatus(404)
}
getBookingConfirmationSuccessCounter.add(1, { confirmationNumber })
console.info(
"api.booking.confirmation success",
@@ -95,44 +118,31 @@ export const bookingQueryRouter = router({
})
)
/**
* Add hotels check in and out times to booking check in and out date
* as that is date only (YYYY-MM-DD)
*/
const checkInTime =
hotelData.data.attributes.hotelFacts.checkin.checkInTime
const [checkInHour, checkInMinute] = checkInTime.split(":")
const checkIn = dt(booking.data.checkInDate)
.set("hour", Number(checkInHour))
.set("minute", Number(checkInMinute))
const checkOutTime =
hotelData.data.attributes.hotelFacts.checkin.checkOutTime
const [checkOutHour, checkOutMinute] = checkOutTime.split(":")
const checkOut = dt(booking.data.checkOutDate)
.set("hour", Number(checkOutHour))
.set("minute", Number(checkOutMinute))
booking.data.checkInDate = checkIn.toDate()
booking.data.checkOutDate = checkOut.toDate()
return {
...booking.data,
hotel: hotelData,
temp: {
breakfastFrom: "06:30",
breakfastTo: "11:00",
cancelPolicy: "Free rebooking",
fromDate: "2024-10-21 14:00",
packages: [
{
name: "Breakfast buffet",
price: "150 SEK",
},
{
name: "Member discount",
price: "-297 SEK",
},
{
name: "Points used / remaining",
price: "0 / 1044",
},
],
payment: "2024-08-09 1:47",
room: {
price: "2 589 SEK",
type: "Cozy Cabin",
vat: "684,79 SEK",
},
toDate: "2024-10-22 11:00",
total: "2 739 SEK",
totalInEuro: "265 EUR",
},
guest: {
email: "sarah.obrian@gmail.com",
firstName: "Sarah",
lastName: "O'Brian",
memberbershipNumber: "19822",
phoneNumber: "+46702446688",
booking: booking.data,
hotel: {
...hotelData.data.attributes,
included: hotelData.included,
},
}
}),