Merged in chore/remove-unused-code (pull request #2229)
Remove unused code * Remove unused scandic-web files * Remove unused exports Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -1,5 +0,0 @@
|
||||
import { z } from "zod"
|
||||
|
||||
export const getHotelListDataInput = z.object({
|
||||
cityIdentifier: z.string(),
|
||||
})
|
||||
@@ -1,112 +1,16 @@
|
||||
import { GetHotelPageRefs } from "@/lib/graphql/Query/HotelPage/HotelPage.graphql"
|
||||
import { GetHotelPageCount } from "@/lib/graphql/Query/HotelPage/HotelPageCount.graphql"
|
||||
import { GetHotelPageUrls } from "@/lib/graphql/Query/HotelPage/HotelPageUrl.graphql"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
import { notFound } from "@/server/errors/trpc"
|
||||
import { createCounter } from "@/server/telemetry"
|
||||
|
||||
import {
|
||||
generateRefsResponseTag,
|
||||
generateTag,
|
||||
generateTagsFromSystem,
|
||||
} from "@/utils/generateTag"
|
||||
import { batchedHotelPageUrlsSchema, hotelPageCountSchema } from "./output"
|
||||
|
||||
import {
|
||||
batchedHotelPageUrlsSchema,
|
||||
hotelPageCountSchema,
|
||||
hotelPageRefsSchema,
|
||||
} from "./output"
|
||||
|
||||
import { HotelPageEnum } from "@/types/enums/hotelPage"
|
||||
import type { System } from "@/types/requests/system"
|
||||
import type {
|
||||
GetHotelPageCountData,
|
||||
GetHotelPageRefsSchema,
|
||||
GetHotelPageUrlsData,
|
||||
HotelPageRefs,
|
||||
} from "@/types/trpc/routers/contentstack/hotelPage"
|
||||
import type { Lang } from "@/constants/languages"
|
||||
|
||||
export async function fetchHotelPageRefs(lang: Lang, uid: string) {
|
||||
const getHotelPageRefsCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"hotelPage.get.refs"
|
||||
)
|
||||
const metricsGetHotelPageRefs = getHotelPageRefsCounter.init({ lang, uid })
|
||||
|
||||
metricsGetHotelPageRefs.start()
|
||||
|
||||
const refsResponse = await request<GetHotelPageRefsSchema>(
|
||||
GetHotelPageRefs,
|
||||
{ locale: lang, uid },
|
||||
{
|
||||
key: generateRefsResponseTag(lang, uid),
|
||||
ttl: "max",
|
||||
}
|
||||
)
|
||||
if (!refsResponse.data) {
|
||||
const notFoundError = notFound(refsResponse)
|
||||
metricsGetHotelPageRefs.noDataError()
|
||||
throw notFoundError
|
||||
}
|
||||
|
||||
return refsResponse.data
|
||||
}
|
||||
|
||||
export function validateHotelPageRefs(
|
||||
data: GetHotelPageRefsSchema,
|
||||
lang: Lang,
|
||||
uid: string
|
||||
) {
|
||||
const getHotelPageRefsCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
"hotelPage.get.refs"
|
||||
)
|
||||
const metricsGetHotelPageRefs = getHotelPageRefsCounter.init({ lang, uid })
|
||||
|
||||
const validatedData = hotelPageRefsSchema.safeParse(data)
|
||||
|
||||
if (!validatedData.success) {
|
||||
metricsGetHotelPageRefs.validationError(validatedData.error)
|
||||
return null
|
||||
}
|
||||
|
||||
metricsGetHotelPageRefs.success()
|
||||
|
||||
return validatedData.data
|
||||
}
|
||||
|
||||
export function generatePageTags(
|
||||
validatedData: HotelPageRefs,
|
||||
lang: Lang
|
||||
): string[] {
|
||||
const connections = getConnections(validatedData)
|
||||
return [
|
||||
generateTagsFromSystem(lang, connections),
|
||||
generateTag(lang, validatedData.hotel_page.system.uid),
|
||||
].flat()
|
||||
}
|
||||
|
||||
export function getConnections({ hotel_page }: HotelPageRefs) {
|
||||
const connections: System["system"][] = [hotel_page.system]
|
||||
if (hotel_page.content) {
|
||||
hotel_page.content.forEach((block) => {
|
||||
switch (block.__typename) {
|
||||
case HotelPageEnum.ContentStack.blocks.ActivitiesCard: {
|
||||
if (block.upcoming_activities_card.length) {
|
||||
connections.push(...block.upcoming_activities_card)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
if (hotel_page.faq) {
|
||||
connections.push(...hotel_page.faq)
|
||||
}
|
||||
})
|
||||
}
|
||||
return connections
|
||||
}
|
||||
|
||||
export async function getHotelPageCount(lang: Lang) {
|
||||
const getHotelPageCountCounter = createCounter(
|
||||
"trpc.contentstack",
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
import { z } from "zod"
|
||||
|
||||
export const hotelFilterSchema = z.object({
|
||||
hotelFacilities: z.array(z.string()),
|
||||
hotelSurroundings: z.array(z.string()),
|
||||
roomFacilities: z.array(z.string()),
|
||||
})
|
||||
@@ -1,68 +0,0 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { isDefined } from "@/server/utils"
|
||||
|
||||
export const locationsUrlsSchema = z.object({
|
||||
hotels: z
|
||||
.object({
|
||||
items: z.array(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
url: z.string(),
|
||||
})
|
||||
),
|
||||
})
|
||||
.transform((data) => {
|
||||
return data.items
|
||||
}),
|
||||
cities: z
|
||||
.object({
|
||||
items: z
|
||||
.array(
|
||||
z
|
||||
.object({
|
||||
id: z
|
||||
.object({
|
||||
da: z.string().nullish(),
|
||||
de: z.string().nullish(),
|
||||
en: z.string().nullish(),
|
||||
fi: z.string().nullish(),
|
||||
no: z.string().nullish(),
|
||||
pl: z.string().nullish(),
|
||||
sv: z.string().nullish(),
|
||||
})
|
||||
.transform(
|
||||
(data) =>
|
||||
data.da ||
|
||||
data.de ||
|
||||
data.en ||
|
||||
data.fi ||
|
||||
data.no ||
|
||||
data.pl ||
|
||||
data.sv
|
||||
),
|
||||
url: z.string().nullish(),
|
||||
})
|
||||
.partial()
|
||||
.transform((data) => {
|
||||
if (!data.id || !data.url) {
|
||||
return null
|
||||
}
|
||||
|
||||
return {
|
||||
id: data.id,
|
||||
url: data.url,
|
||||
}
|
||||
})
|
||||
)
|
||||
.transform((data) => {
|
||||
return data.filter(isDefined)
|
||||
}),
|
||||
})
|
||||
.transform((data) => {
|
||||
return data.items
|
||||
}),
|
||||
})
|
||||
|
||||
export type GetLocationsUrlsData = z.input<typeof locationsUrlsSchema>
|
||||
export type LocationsUrls = z.output<typeof locationsUrlsSchema>
|
||||
@@ -1,81 +0,0 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { imageSchema } from "./image"
|
||||
import { specialAlertsSchema } from "./specialAlerts"
|
||||
|
||||
const restaurantPriceSchema = z.object({
|
||||
currency: z.string(),
|
||||
amount: z.number(),
|
||||
})
|
||||
export const restaurantDaySchema = z.object({
|
||||
sortOrder: z.number(),
|
||||
alwaysOpen: z.boolean(),
|
||||
isClosed: z.boolean(),
|
||||
openingTime: z.string(),
|
||||
closingTime: z.string(),
|
||||
})
|
||||
export const restaurantOpeningHoursSchema = z.object({
|
||||
isActive: z.boolean(),
|
||||
name: z.string().optional(),
|
||||
monday: restaurantDaySchema.optional(),
|
||||
tuesday: restaurantDaySchema.optional(),
|
||||
wednesday: restaurantDaySchema.optional(),
|
||||
thursday: restaurantDaySchema.optional(),
|
||||
friday: restaurantDaySchema.optional(),
|
||||
saturday: restaurantDaySchema.optional(),
|
||||
sunday: restaurantDaySchema.optional(),
|
||||
})
|
||||
|
||||
const restaurantOpeningDetailSchema = z.object({
|
||||
openingHours: restaurantOpeningHoursSchema,
|
||||
alternateOpeningHours: restaurantOpeningHoursSchema.optional(),
|
||||
})
|
||||
|
||||
export const restaurantSchema = z
|
||||
.object({
|
||||
attributes: z.object({
|
||||
name: z.string(),
|
||||
isPublished: z.boolean().default(false),
|
||||
restaurantPage: z.boolean(),
|
||||
email: z.string().optional(),
|
||||
phoneNumber: z.string().optional(),
|
||||
externalBreakfast: z
|
||||
.object({
|
||||
isAvailable: z.boolean(),
|
||||
localPriceForExternalGuests: restaurantPriceSchema.optional(),
|
||||
requestedPriceForExternalGuests: restaurantPriceSchema.optional(),
|
||||
})
|
||||
.optional(),
|
||||
menus: z
|
||||
.array(
|
||||
z.object({
|
||||
name: z.string(),
|
||||
url: z.string(),
|
||||
})
|
||||
)
|
||||
.default([]),
|
||||
openingDetails: z.array(restaurantOpeningDetailSchema).default([]),
|
||||
content: z.object({
|
||||
images: z.array(imageSchema),
|
||||
texts: z.object({
|
||||
descriptions: z.object({
|
||||
short: z.string().default(""),
|
||||
medium: z.string().default(""),
|
||||
}),
|
||||
}),
|
||||
bookTableUrl: z.string().optional(),
|
||||
specialAlerts: specialAlertsSchema,
|
||||
}),
|
||||
}),
|
||||
id: z.string(),
|
||||
type: z.literal("restaurants"),
|
||||
})
|
||||
.transform(({ attributes, id, type }) => ({ ...attributes, id, type }))
|
||||
|
||||
export const getRestaurantsSchema = z
|
||||
.object({
|
||||
data: z.array(restaurantSchema),
|
||||
})
|
||||
.transform(({ data }) => {
|
||||
return data.filter((item) => !!item.isPublished)
|
||||
})
|
||||
@@ -1,122 +0,0 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { BedTypeEnum, ExtraBedTypeEnum } from "@/constants/booking"
|
||||
|
||||
import { imageSchema } from "./image"
|
||||
|
||||
const roomContentSchema = z.object({
|
||||
images: z.array(imageSchema),
|
||||
texts: z.object({
|
||||
descriptions: z.object({
|
||||
short: z.string().optional(),
|
||||
medium: z.string().optional(),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
|
||||
const roomTypesSchema = z.object({
|
||||
name: z.string(),
|
||||
description: z.string(),
|
||||
code: z.string(),
|
||||
roomCount: z.number(),
|
||||
mainBed: z
|
||||
.object({
|
||||
type: z.string(),
|
||||
description: z.string(),
|
||||
widthRange: z.object({
|
||||
min: z.number(),
|
||||
max: z.number(),
|
||||
}),
|
||||
})
|
||||
.transform((data) => ({
|
||||
type:
|
||||
data.type in BedTypeEnum
|
||||
? (data.type as BedTypeEnum)
|
||||
: BedTypeEnum.Other,
|
||||
description: data.description,
|
||||
widthRange: data.widthRange,
|
||||
})),
|
||||
fixedExtraBed: z
|
||||
.object({
|
||||
type: z.string(),
|
||||
description: z.string().optional(),
|
||||
widthRange: z.object({
|
||||
min: z.number(),
|
||||
max: z.number(),
|
||||
}),
|
||||
})
|
||||
.transform((data) => {
|
||||
return data.type in ExtraBedTypeEnum
|
||||
? {
|
||||
type: data.type as ExtraBedTypeEnum,
|
||||
description: data.description,
|
||||
}
|
||||
: undefined
|
||||
}),
|
||||
roomSize: z.object({
|
||||
min: z.number(),
|
||||
max: z.number(),
|
||||
}),
|
||||
occupancy: z.object({
|
||||
total: z.number(),
|
||||
adults: z.number(),
|
||||
children: z.number(),
|
||||
}),
|
||||
isLackingCribs: z.boolean(),
|
||||
isLackingExtraBeds: z.boolean(),
|
||||
})
|
||||
|
||||
const roomFacilitiesSchema = z.object({
|
||||
availableInAllRooms: z.boolean(),
|
||||
name: z.string(),
|
||||
isUniqueSellingPoint: z.boolean(),
|
||||
sortOrder: z.number(),
|
||||
icon: z.string().optional(),
|
||||
})
|
||||
|
||||
export const roomSchema = z
|
||||
.object({
|
||||
attributes: z.object({
|
||||
name: z.string(),
|
||||
sortOrder: z.number(),
|
||||
content: roomContentSchema,
|
||||
roomTypes: z.array(roomTypesSchema),
|
||||
roomFacilities: z.array(roomFacilitiesSchema),
|
||||
occupancy: z.object({
|
||||
min: z.number(),
|
||||
max: z.number(),
|
||||
}),
|
||||
roomSize: z.object({
|
||||
min: z.number(),
|
||||
max: z.number(),
|
||||
}),
|
||||
}),
|
||||
id: z.string(),
|
||||
type: z.literal("roomcategories"),
|
||||
})
|
||||
.transform((data) => {
|
||||
return {
|
||||
descriptions: data.attributes.content.texts.descriptions,
|
||||
id: data.id,
|
||||
images: data.attributes.content.images,
|
||||
name: data.attributes.name,
|
||||
occupancy: data.attributes.occupancy,
|
||||
totalOccupancy:
|
||||
data.attributes.occupancy.min === data.attributes.occupancy.max
|
||||
? {
|
||||
max: data.attributes.occupancy.max,
|
||||
range: `${data.attributes.occupancy.max}`,
|
||||
}
|
||||
: {
|
||||
max: data.attributes.occupancy.max,
|
||||
range: `${data.attributes.occupancy.min}-${data.attributes.occupancy.max}`,
|
||||
},
|
||||
roomSize: data.attributes.roomSize,
|
||||
roomTypes: data.attributes.roomTypes,
|
||||
sortOrder: data.attributes.sortOrder,
|
||||
type: data.type,
|
||||
roomFacilities: data.attributes.roomFacilities,
|
||||
}
|
||||
})
|
||||
|
||||
export type RoomType = Pick<z.output<typeof roomSchema>, "roomTypes" | "name">
|
||||
@@ -1,39 +0,0 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { dt } from "@/lib/dt"
|
||||
|
||||
import { AlertTypeEnum } from "@/types/enums/alert"
|
||||
|
||||
const specialAlertSchema = z.object({
|
||||
type: z.string(),
|
||||
title: z.string().optional(),
|
||||
description: z.string().optional(),
|
||||
displayInBookingFlow: z.boolean(),
|
||||
startDate: z.string().optional(),
|
||||
endDate: z.string().optional(),
|
||||
})
|
||||
|
||||
export const specialAlertsSchema = z
|
||||
.array(specialAlertSchema)
|
||||
.transform((data) => {
|
||||
const now = dt().utc().format("YYYY-MM-DD")
|
||||
const filteredAlerts = data.filter((alert) => {
|
||||
let shouldShowNow = true
|
||||
|
||||
if (alert.startDate && alert.startDate > now) {
|
||||
shouldShowNow = false
|
||||
}
|
||||
if (alert.endDate && alert.endDate < now) {
|
||||
shouldShowNow = false
|
||||
}
|
||||
const hasText = alert.description || alert.title
|
||||
return shouldShowNow && hasText
|
||||
})
|
||||
return filteredAlerts.map((alert, idx) => ({
|
||||
id: `alert-${alert.type}-${idx}`,
|
||||
type: AlertTypeEnum.Info,
|
||||
heading: alert.title || null,
|
||||
text: alert.description || null,
|
||||
}))
|
||||
})
|
||||
.default([])
|
||||
Reference in New Issue
Block a user