Files
web/packages/trpc/lib/routers/partners/jobylon/output.ts
Anton Gunnarsson f9c719ff4b Merged in feat/sw-2866-move-partners-router-to-trpc-package (pull request #2414)
feat(sw-2866): Move partners router to trpc package

* Add eslint to trpc package

* Apply lint rules

* Use direct imports from trpc package

* Add lint-staged config to trpc

* Move lang enum to common

* Restructure trpc package folder structure

* WIP first step

* update internal imports in trpc

* Fix most errors in scandic-web

Just 100 left...

* Move Props type out of trpc

* Fix CategorizedFilters types

* Move more schemas in hotel router

* Fix deps

* fix getNonContentstackUrls

* Fix import error

* Fix entry error handling

* Fix generateMetadata metrics

* Fix alertType enum

* Fix duplicated types

* lint:fix

* Merge branch 'master' into feat/sw-2863-move-contentstack-router-to-trpc-package

* Fix broken imports

* Move booking router to trpc package

* Move partners router to trpc package

* Merge branch 'master' into feat/sw-2866-move-partners-router-to-trpc-package


Approved-by: Linus Flood
2025-06-26 09:44:13 +00:00

130 lines
2.9 KiB
TypeScript

import { z } from "zod"
import { dt } from "@scandic-hotels/common/dt"
const categoriesSchema = z
.array(
z
.object({ category: z.object({ id: z.number(), text: z.string() }) })
.transform(({ category }) => {
return {
id: category.id,
text: category.text,
}
})
)
.transform((categories) =>
categories.filter(
(category): category is NonNullable<typeof category> => !!category
)
)
const departmentsSchema = z
.array(
z
.object({
department: z.object({
id: z.number(),
name: z.string(),
}),
})
.transform(({ department }) => {
if (!department.id || !department.name) {
return null
}
return {
id: department.id,
name: department.name,
}
})
)
.transform((departments) =>
departments.filter(
(department): department is NonNullable<typeof department> => !!department
)
)
const locationsSchema = z
.array(
z
.object({
location: z.object({
city: z.string().nullish(),
country: z.string().nullish(),
place_id: z.string().nullish(),
country_short: z.string().nullish(),
}),
})
.transform(({ location }) => {
if (!location.city || !location.country) {
return null
}
return {
city: location.city,
country: location.country,
countryShort: location.country_short ?? null,
placeId: location.place_id ?? null,
}
})
)
.transform((locations) =>
locations.filter(
(location): location is NonNullable<typeof location> => !!location
)
)
const urlsSchema = z
.object({
apply: z.string(),
ad: z.string(),
})
.transform(({ ad }) => ad)
export const jobylonItemSchema = z
.object({
id: z.number(),
title: z.string(),
from_date: z.string().nullish(),
to_date: z.string().nullish(),
categories: categoriesSchema,
departments: departmentsSchema,
locations: locationsSchema,
urls: urlsSchema,
})
.transform(
({
id,
from_date,
to_date,
title,
categories,
departments,
locations,
urls,
}) => {
const now = dt.utc()
const fromDate = from_date ? dt(from_date) : null
const toDate = to_date ? dt(to_date) : null
// Transformed to string as Dayjs objects cannot be passed to client components
const toDateAsString = toDate?.toString() ?? null
return {
id,
title,
isActive:
fromDate &&
now.isSameOrAfter(fromDate) &&
(!toDate || now.isSameOrBefore(toDate)),
categories,
departments,
toDate: toDateAsString,
locations,
url: urls,
}
}
)
export const jobylonFeedSchema = z
.array(jobylonItemSchema)
.transform((jobs) => jobs.filter((job) => job.isActive))