33 lines
883 B
TypeScript
33 lines
883 B
TypeScript
import { z } from "zod"
|
|
|
|
import { getPoiGroupByCategoryName } from "../../utils"
|
|
import { locationSchema } from "./location"
|
|
|
|
export const pointOfInterestSchema = z
|
|
.object({
|
|
category: z.object({
|
|
name: z.string().optional(),
|
|
group: z.string().optional(),
|
|
}),
|
|
distance: z.number().optional(),
|
|
isHighlighted: z.boolean().optional(),
|
|
location: locationSchema.optional(),
|
|
name: z.string().optional(),
|
|
})
|
|
.transform((poi) => ({
|
|
categoryName: poi.category.name,
|
|
coordinates: {
|
|
lat: poi.location?.latitude ?? 0,
|
|
lng: poi.location?.longitude ?? 0,
|
|
},
|
|
distance: poi.distance,
|
|
group: getPoiGroupByCategoryName(poi.category.name),
|
|
name: poi.name,
|
|
}))
|
|
|
|
export const pointOfInterestsSchema = z
|
|
.array(pointOfInterestSchema)
|
|
.transform((pois) =>
|
|
pois.sort((a, b) => (a.distance ?? 0) - (b.distance ?? 0))
|
|
)
|