-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschemas.ts
More file actions
64 lines (58 loc) · 1.79 KB
/
schemas.ts
File metadata and controls
64 lines (58 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { z } from "zod";
/**
* Zod schemas validate external data entering the domain layer.
*/
export const PropertySummarySchema = z.object({
id: z.string(),
addressLine: z.string(),
city: z.string(),
state: z.string().length(2).or(z.string().min(2)),
zip: z.string().min(3),
price: z.number().optional(),
beds: z.number().optional(),
baths: z.number().optional(),
sqft: z.number().optional(),
lotSqft: z.number().optional(),
imageUrl: z.string().url().optional(),
badges: z
.array(
z.object({
label: z.string(),
tone: z.enum(["default", "info", "success", "warning"]).optional(),
}),
)
.optional(),
aiScore: z.number().min(0).max(100).optional(),
createdAt: z.string().optional(),
});
export const PaginationSchema = z.object({
page: z.number().int().nonnegative(),
pageSize: z.number().int().positive(),
total: z.number().int().nonnegative(),
});
export const SortSpecSchema = z.object({
field: z.enum(["price", "beds", "baths", "sqft", "createdAt", "aiScore"]),
direction: z.enum(["asc", "desc"]),
});
export const FilterSpecSchema = z
.object({
query: z.string().optional(),
minPrice: z.number().optional(),
maxPrice: z.number().optional(),
beds: z.number().optional(),
baths: z.number().optional(),
propertyType: z.string().optional(),
city: z.string().optional(),
state: z.string().optional(),
})
.refine((v) => (v.minPrice ?? 0) <= (v.maxPrice ?? Number.MAX_SAFE_INTEGER), {
message: "minPrice cannot exceed maxPrice",
path: ["minPrice"],
});
export const QueryParamsSchema = z.object({
page: z.number().int().nonnegative().default(0),
pageSize: z.number().int().positive().default(24),
sort: SortSpecSchema.nullable().default(null),
filters: FilterSpecSchema.default({}),
});
export type PropertySummaryInput = z.infer<typeof PropertySummarySchema>;