Merged in chore/refactor-trpc-booking-routes (pull request #3510)
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
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import "server-only"
|
||||
|
||||
import { PaymentMethodEnum } from "@scandic-hotels/common/constants/paymentMethod"
|
||||
|
||||
import { safeProtectedServiceProcedure } from "../../../../procedures"
|
||||
import { createBooking } from "../../../../services/booking/createBooking"
|
||||
import { encrypt } from "../../../../utils/encryption"
|
||||
import { createBookingInput } from "./schema"
|
||||
export const createBookingRoute = safeProtectedServiceProcedure
|
||||
.input(createBookingInput)
|
||||
.use(async ({ ctx, next }) => {
|
||||
const token = await ctx.getScandicUserToken()
|
||||
|
||||
return next({
|
||||
ctx: {
|
||||
token,
|
||||
},
|
||||
})
|
||||
})
|
||||
.mutation(async function ({ ctx, input }) {
|
||||
if (input.payment?.paymentMethod === PaymentMethodEnum.PartnerPoints) {
|
||||
const session = await ctx.auth()
|
||||
const token = session?.token.access_token
|
||||
if (!token) {
|
||||
throw new Error(
|
||||
"Cannot create booking with partner points without partner token"
|
||||
)
|
||||
}
|
||||
|
||||
input.partnerSpecific = {
|
||||
eurobonusAccessToken: session?.token.access_token,
|
||||
}
|
||||
}
|
||||
|
||||
const booking = await createBooking(input, ctx.token ?? ctx.serviceToken)
|
||||
if ("error" in booking) {
|
||||
return { ...booking }
|
||||
}
|
||||
|
||||
const expire = Math.floor(Date.now() / 1000) + 60 // 1 minute expiry
|
||||
|
||||
return {
|
||||
booking,
|
||||
sig: encrypt(expire.toString()),
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user