-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Ensure input postcode is always parsed #229
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,7 @@ const getItl3ByPostcodeDistrict = async ( | |
}, | ||
}); | ||
|
||
// Cast to string as 'not: null' clause in Prisma query does not type narrow | ||
return itl3 as string; | ||
return itl3; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small unrelated tidy up sorry - this column in now non-nullable. |
||
} catch (error) { | ||
throw new Error( | ||
`Data error: Unable get get itl3 for postcode district ${postcodeDistrict}` | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { z } from "zod"; | ||
import { fix as fixPostcode } from "postcode"; | ||
import { isValid as isValidPostcode } from "postcode"; | ||
import { HOUSE_TYPES } from "../models/Property"; | ||
import { maintenancePercentageSchema } from "../schemas/calculationSchema"; | ||
|
||
|
@@ -11,17 +11,17 @@ const HouseTypeEnum = z.enum(HOUSE_TYPES); | |
export const formSchema = z.object({ | ||
housePostcode: z | ||
.string() | ||
.min(1, "housePostcode is required") | ||
.refine(fixPostcode, "Invalid postcode"), | ||
houseSize: z.coerce.number().positive("houseSize must be a positive integer"), | ||
houseAge: z.coerce.number().positive("houseAge must be a positive integer"), | ||
.min(1, "Postcode is required") | ||
.refine(isValidPostcode, "Invalid postcode"), | ||
houseSize: z.coerce.number().positive("House size must be a positive number"), | ||
houseAge: z.coerce.number().positive("House age must be a positive number"), | ||
houseBedrooms: z.coerce | ||
.number() | ||
.positive("houseBedrooms must be a positive integer"), | ||
.positive("House bedrooms must be a positive number"), | ||
houseType: HouseTypeEnum.refine( | ||
(value) => HouseTypeEnum.options.includes(value), | ||
{ | ||
message: `houseType is required and must be one of ${HOUSE_TYPES}`, | ||
message: `House type is required`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Error messages here are using facing and more a bit more user-friendly. |
||
} | ||
), | ||
maintenancePercentage: maintenancePercentageSchema, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Main change in this PR - falling back to parsing the input.