feat(BOOK-750): refactor booking endpoints * WIP * wip * wip * parse dates in UTC * wip * no more errors * Merge branch 'master' of bitbucket.org:scandic-swap/web into chore/refactor-trpc-booking-routes * . * cleanup * import named z from zod * fix(BOOK-750): updateBooking api endpoint expects dateOnly, we passed ISO date Approved-by: Anton Gunnarsson
34 lines
1021 B
TypeScript
34 lines
1021 B
TypeScript
import { z } from "zod"
|
|
|
|
import { Lang } from "@scandic-hotels/common/constants/language"
|
|
|
|
import { createRefIdPlugin } from "../../../plugins/refIdToConfirmationNumber"
|
|
import { safeProtectedServiceProcedure } from "../../../procedures"
|
|
import { getBookingStatus } from "../../../services/booking/getBookingStatus"
|
|
import { encrypt } from "../../../utils/encryption"
|
|
|
|
const getBookingStatusInput = z.object({
|
|
lang: z.nativeEnum(Lang).optional(),
|
|
})
|
|
|
|
const refIdPlugin = createRefIdPlugin()
|
|
export const getBookingStatusRoute = safeProtectedServiceProcedure
|
|
.input(getBookingStatusInput)
|
|
.concat(refIdPlugin.toConfirmationNumber)
|
|
.query(async function ({ ctx, input }) {
|
|
const lang = input.lang ?? ctx.lang
|
|
const { confirmationNumber } = ctx
|
|
|
|
const booking = await getBookingStatus(
|
|
{ confirmationNumber, lang },
|
|
ctx.serviceToken
|
|
)
|
|
|
|
const expire = Math.floor(Date.now() / 1000) + 60 // 1 minute expiry
|
|
|
|
return {
|
|
booking,
|
|
sig: encrypt(expire.toString()),
|
|
}
|
|
})
|