feat(SW-2116): Use refId instead of confirmationNumber

This commit is contained in:
Michael Zetterberg
2025-05-04 11:11:15 +02:00
parent f681fa7675
commit b910b6a313
59 changed files with 491 additions and 310 deletions

View File

@@ -2,6 +2,7 @@ import { z } from "zod"
import { BookingStatusEnum, ChildBedTypeEnum } from "@/constants/booking"
import { calculateRefId } from "@/utils/refId"
import { nullableArrayObjectValidator } from "@/utils/zod/arrayValidator"
import { nullableIntValidator } from "@/utils/zod/numberValidator"
import {
@@ -78,7 +79,13 @@ export const createBookingSchema = z
type: d.data.type,
reservationStatus: d.data.attributes.reservationStatus,
paymentUrl: d.data.attributes.paymentUrl,
rooms: d.data.attributes.rooms,
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,
}))
@@ -248,6 +255,31 @@ export const bookingConfirmationSchema = z
})
.transform(({ data }) => ({
...data.attributes,
refId: calculateRefId(
data.attributes.confirmationNumber,
data.attributes.guest.lastName
),
linkedReservations: data.attributes.linkedReservations.map(
(linkedReservation) => {
/**
* We lazy load linked reservations in the client.
* The problem is that we need to load the reservation in order to
* calculate the refId for the reservation as the refId uses the guest's
* lastname in it. Ideally we should pass a promise to the React
* component that uses `use()` to resolve it. But right now we use tRPC
* in the client. That tRPC endpoint only uses the confirmationNumber
* from the refId. So that means we can pass whatever as the lastname
* here, because it is actually never read. We should change this ASAP.
*/
return {
...linkedReservation,
refId: calculateRefId(
linkedReservation.confirmationNumber,
"" // TODO: Empty lastname here, see comment above
),
}
}
),
packages: data.attributes.packages.filter((p) => p.type !== "Ancillary"),
ancillaries: data.attributes.packages.filter((p) => p.type === "Ancillary"),
extraBedTypes: data.attributes.childBedPreferences,