-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gabriele Granello
committed
Aug 23, 2024
1 parent
0b65c42
commit 7237d4a
Showing
5 changed files
with
53 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { z } from "zod"; | ||
import { parse as parsePostcode } from "postcode"; | ||
import { HOUSE_TYPES } from "../models/Property"; | ||
|
||
// Type not exported by postcode lib directly | ||
export type ValidPostcode = Extract< | ||
ReturnType<typeof parsePostcode>, | ||
{ valid: true } | ||
>; | ||
|
||
const HouseTypeEnum = z.enum(HOUSE_TYPES); | ||
|
||
export const apiSchema = z.object({ | ||
housePostcode: z.custom<ValidPostcode>(), | ||
houseSize: z.coerce.number().positive("houseSize must be a positive integer"), | ||
houseAge: z.coerce.number().positive("houseAge must be a positive integer"), | ||
houseBedrooms: z.coerce | ||
.number() | ||
.positive("houseBedrooms must be a positive integer"), | ||
houseType: HouseTypeEnum.refine( | ||
(value) => HouseTypeEnum.options.includes(value), | ||
{ | ||
message: `houseType is required and must be one of ${HOUSE_TYPES}`, | ||
} | ||
), | ||
}); | ||
|
||
export type api = z.infer<typeof apiSchema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters