Files
web/packages/trpc/lib/routers/booking/query/findBookingForCurrentUserRoute.ts
Anton Gunnarsson c2cf6b03a7 Merged in feat/loy-291-new-claim-points-flow (pull request #3508)
feat(LOY-291): New claim points flow for logged in users

* wip new flow

* More wip

* More wip

* Wip styling

* wip with a mutation

* Actually fetch booking data

* More styling wip

* Fix toast duration

* fix loading a11y maybe

* More stuff

* Add feature flag

* Add invalid state

* Clean up

* Add fields for missing user info

* Restructure files

* Add todos

* Disable warning

* Fix icon and border radius


Approved-by: Emma Zettervall
Approved-by: Matilda Landström
2026-02-03 13:27:24 +00:00

87 lines
2.2 KiB
TypeScript

import { createCounter } from "@scandic-hotels/common/telemetry"
import { notFoundError } from "../../../errors"
import { safeProtectedServiceProcedure } from "../../../procedures"
import { findBooking } from "../../../services/booking/findBooking"
import { getHotel } from "../../hotels/services/getHotel"
import { findBookingInput } from "../input"
export const findBookingForCurrentUserRoute = safeProtectedServiceProcedure
.input(
findBookingInput.omit({ lastName: true, firstName: true, email: true })
)
.query(async function ({ ctx, input }) {
const lang = input.lang ?? ctx.lang
const { confirmationNumber } = input
const user = await ctx.getScandicUser()
const token = await ctx.getScandicUserToken()
const findBookingCounter = createCounter(
"trpc.booking.findBookingForCurrentUser"
)
const metricsFindBooking = findBookingCounter.init({
confirmationNumber,
})
metricsFindBooking.start()
if (!user || !token) {
metricsFindBooking.dataError(
`Fail to find user when finding booking for ${confirmationNumber}`,
{ confirmationNumber }
)
return null
}
const booking = await findBooking(
{
confirmationNumber,
lang,
lastName: user.lastName,
firstName: user.firstName,
email: user.email,
},
token
)
if (!booking) {
metricsFindBooking.dataError(
`Fail to find booking data for ${confirmationNumber}`,
{ confirmationNumber }
)
return null
}
const hotelData = await getHotel(
{
hotelId: booking.hotelId,
isCardOnlyPayment: false,
language: lang,
},
ctx.serviceToken
)
if (!hotelData) {
metricsFindBooking.dataError(
`Failed to find hotel data for ${booking.hotelId}`,
{
hotelId: booking.hotelId,
}
)
throw notFoundError({
message: "Hotel data not found",
errorDetails: { hotelId: booking.hotelId },
})
}
metricsFindBooking.success()
return {
hotel: {
name: hotelData.hotel.name,
cityName: hotelData.hotel.cityName,
},
booking,
}
})