Merged in chore/refactor-hotel-trpc-routes (pull request #2891)
Chore/refactor hotel trpc routes * chore(SW-3519): refactor trpc hotel routers * chore(SW-3519): refactor trpc hotel routers * refactor * merge * Merge branch 'master' of bitbucket.org:scandic-swap/web into chore/refactor-hotel-trpc-routes Approved-by: Linus Flood
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import dayjs from "dayjs"
|
||||
import { z } from "zod"
|
||||
|
||||
import { Lang } from "@scandic-hotels/common/constants/language"
|
||||
@@ -8,106 +7,6 @@ import { ChildBedMapEnum } from "../../enums/childBedMapEnum"
|
||||
import { RoomPackageCodeEnum } from "../../enums/roomFilter"
|
||||
import { Country } from "../../types/country"
|
||||
|
||||
export const hotelsAvailabilityInputSchema = z
|
||||
.object({
|
||||
cityId: z.string(),
|
||||
roomStayStartDate: z.string().refine(
|
||||
(val) => {
|
||||
const fromDate = dayjs(val)
|
||||
|
||||
return fromDate.isValid()
|
||||
},
|
||||
{
|
||||
message: "FROMDATE_INVALID",
|
||||
}
|
||||
),
|
||||
roomStayEndDate: z.string().refine(
|
||||
(val) => {
|
||||
const fromDate = dayjs(val)
|
||||
return fromDate.isValid()
|
||||
},
|
||||
{
|
||||
message: "TODATE_INVALID",
|
||||
}
|
||||
),
|
||||
adults: z.number(),
|
||||
children: z.string().optional(),
|
||||
bookingCode: z.string().optional().default(""),
|
||||
redemption: z.boolean().optional().default(false),
|
||||
})
|
||||
.refine(
|
||||
(data) => {
|
||||
const fromDate = dayjs(data.roomStayStartDate).startOf("day")
|
||||
const toDate = dayjs(data.roomStayEndDate).startOf("day")
|
||||
|
||||
return fromDate.isBefore(toDate)
|
||||
},
|
||||
{
|
||||
message: "FROMDATE_BEFORE_TODATE",
|
||||
}
|
||||
)
|
||||
.refine(
|
||||
(data) => {
|
||||
const fromDate = dayjs(data.roomStayStartDate)
|
||||
const today = dayjs().startOf("day")
|
||||
|
||||
return fromDate.isSameOrAfter(today)
|
||||
},
|
||||
{
|
||||
message: "FROMDATE_CANNOT_BE_IN_THE_PAST",
|
||||
}
|
||||
)
|
||||
|
||||
export const getHotelsByHotelIdsAvailabilityInputSchema = z
|
||||
.object({
|
||||
hotelIds: z.array(z.number()),
|
||||
roomStayStartDate: z.string().refine(
|
||||
(val) => {
|
||||
const fromDate = dayjs(val)
|
||||
return fromDate.isValid()
|
||||
},
|
||||
{
|
||||
message: "FROMDATE_INVALID",
|
||||
}
|
||||
),
|
||||
roomStayEndDate: z.string().refine(
|
||||
(val) => {
|
||||
const toDate = dayjs(val)
|
||||
|
||||
return toDate.isValid()
|
||||
},
|
||||
{
|
||||
message: "TODATE_INVALID",
|
||||
}
|
||||
),
|
||||
adults: z.number(),
|
||||
children: z.string().optional(),
|
||||
bookingCode: z.string().optional().default(""),
|
||||
redemption: z.boolean().optional().default(false),
|
||||
})
|
||||
.refine(
|
||||
(data) => {
|
||||
const fromDate = dayjs(data.roomStayStartDate).startOf("day")
|
||||
const toDate = dayjs(data.roomStayEndDate).startOf("day")
|
||||
|
||||
return fromDate.isBefore(toDate)
|
||||
},
|
||||
{
|
||||
message: "FROMDATE_BEFORE_TODATE",
|
||||
}
|
||||
)
|
||||
.refine(
|
||||
(data) => {
|
||||
const fromDate = dayjs(data.roomStayStartDate)
|
||||
const today = dayjs().startOf("day")
|
||||
|
||||
return fromDate.isSameOrAfter(today)
|
||||
},
|
||||
{
|
||||
message: "FROMDATE_CANNOT_BE_IN_THE_PAST",
|
||||
}
|
||||
)
|
||||
|
||||
const childrenInRoomSchema = z
|
||||
.array(
|
||||
z.object({
|
||||
@@ -117,7 +16,7 @@ const childrenInRoomSchema = z
|
||||
)
|
||||
.optional()
|
||||
|
||||
const baseRoomSchema = z.object({
|
||||
export const baseRoomSchema = z.object({
|
||||
adults: z.number().int().min(1),
|
||||
bookingCode: z.string().optional(),
|
||||
childrenInRoom: childrenInRoomSchema,
|
||||
@@ -126,13 +25,13 @@ const baseRoomSchema = z.object({
|
||||
.optional(),
|
||||
})
|
||||
|
||||
const selectedRoomSchema = z.object({
|
||||
export const selectedRoomSchema = z.object({
|
||||
counterRateCode: z.string().optional(),
|
||||
rateCode: z.string(),
|
||||
roomTypeCode: z.string(),
|
||||
})
|
||||
|
||||
const baseBookingSchema = z.object({
|
||||
export const baseBookingSchema = z.object({
|
||||
bookingCode: z.string().optional(),
|
||||
fromDate: z.string(),
|
||||
hotelId: z.string(),
|
||||
@@ -140,77 +39,6 @@ const baseBookingSchema = z.object({
|
||||
toDate: z.string(),
|
||||
})
|
||||
|
||||
export const selectRateRoomsAvailabilityInputSchema = z
|
||||
.object({
|
||||
booking: baseBookingSchema.extend({
|
||||
rooms: z.array(baseRoomSchema),
|
||||
}),
|
||||
lang: z.nativeEnum(Lang),
|
||||
})
|
||||
.refine(
|
||||
(data) => {
|
||||
const fromDate = dayjs(data.booking.fromDate)
|
||||
|
||||
return fromDate.isValid()
|
||||
},
|
||||
{
|
||||
message: "FROMDATE_INVALID",
|
||||
}
|
||||
)
|
||||
.refine(
|
||||
(data) => {
|
||||
const toDate = dayjs(data.booking.toDate)
|
||||
|
||||
return toDate.isValid()
|
||||
},
|
||||
{
|
||||
message: "TODATE_INVALID",
|
||||
}
|
||||
)
|
||||
.refine(
|
||||
(data) => {
|
||||
const fromDate = dayjs(data.booking.fromDate).startOf("day")
|
||||
const toDate = dayjs(data.booking.toDate).startOf("day")
|
||||
|
||||
return fromDate.isBefore(toDate)
|
||||
},
|
||||
{
|
||||
message: "TODATE_MUST_BE_AFTER_FROMDATE",
|
||||
}
|
||||
)
|
||||
.refine(
|
||||
(data) => {
|
||||
const fromDate = dayjs(data.booking.fromDate)
|
||||
const today = dayjs().startOf("day")
|
||||
|
||||
return fromDate.isSameOrAfter(today)
|
||||
},
|
||||
{
|
||||
message: "FROMDATE_CANNOT_BE_IN_THE_PAST",
|
||||
}
|
||||
)
|
||||
|
||||
export const selectRateRoomAvailabilityInputSchema = z.object({
|
||||
booking: baseBookingSchema.extend({
|
||||
room: baseRoomSchema,
|
||||
}),
|
||||
lang: z.nativeEnum(Lang),
|
||||
})
|
||||
|
||||
export const enterDetailsRoomsAvailabilityInputSchema = z.object({
|
||||
booking: baseBookingSchema.extend({
|
||||
rooms: z.array(baseRoomSchema.merge(selectedRoomSchema)),
|
||||
}),
|
||||
lang: z.nativeEnum(Lang),
|
||||
})
|
||||
|
||||
export const myStayRoomAvailabilityInputSchema = z.object({
|
||||
booking: baseBookingSchema.extend({
|
||||
room: baseRoomSchema.merge(selectedRoomSchema),
|
||||
}),
|
||||
lang: z.nativeEnum(Lang),
|
||||
})
|
||||
|
||||
export const roomFeaturesInputSchema = z.object({
|
||||
adults: z.number(),
|
||||
childrenInRoom: childrenInRoomSchema,
|
||||
|
||||
Reference in New Issue
Block a user