Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8e787ddcf0 | ||
| 11c52d284c |
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "flyer-crawler",
|
||||
"version": "0.0.27",
|
||||
"version": "0.0.28",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "flyer-crawler",
|
||||
"version": "0.0.27",
|
||||
"version": "0.0.28",
|
||||
"dependencies": {
|
||||
"@bull-board/api": "^6.14.2",
|
||||
"@bull-board/express": "^6.14.2",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "flyer-crawler",
|
||||
"private": true,
|
||||
"version": "0.0.27",
|
||||
"version": "0.0.28",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "concurrently \"npm:start:dev\" \"vite\"",
|
||||
|
||||
@@ -126,7 +126,7 @@ describe('Price Routes (/api/price-history)', () => {
|
||||
expect(response.body.errors).toHaveLength(2);
|
||||
// The actual message is "Too small: expected number to be >0"
|
||||
expect(response.body.errors[0].message).toBe('Too small: expected number to be >0');
|
||||
expect(response.body.errors[1].message).toBe('Expected number, received string');
|
||||
expect(response.body.errors[1].message).toBe('Invalid input: expected number, received NaN');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -59,7 +59,6 @@ export const optionalNumeric = (
|
||||
nonnegative?: boolean;
|
||||
} = {},
|
||||
) => {
|
||||
// Start with the base number schema and apply all number-specific constraints first.
|
||||
let numberSchema = z.coerce.number();
|
||||
|
||||
if (options.integer) numberSchema = numberSchema.int();
|
||||
@@ -69,15 +68,18 @@ export const optionalNumeric = (
|
||||
if (options.min !== undefined) numberSchema = numberSchema.min(options.min);
|
||||
if (options.max !== undefined) numberSchema = numberSchema.max(options.max);
|
||||
|
||||
// Now, wrap the fully configured number schema with the preprocess step.
|
||||
// Make the number schema optional *before* preprocessing. This allows it to correctly handle
|
||||
// the `undefined` value that our preprocessor generates from `null`.
|
||||
const optionalNumberSchema = numberSchema.optional();
|
||||
|
||||
// This is crucial because z.coerce.number(null) results in 0, which bypasses
|
||||
// the .optional() and .default() logic for null inputs. We want null to be
|
||||
// treated as "not provided", just like undefined.
|
||||
const schema = z.preprocess((val) => (val === null ? undefined : val), numberSchema);
|
||||
const schema = z.preprocess((val) => (val === null ? undefined : val), optionalNumberSchema);
|
||||
|
||||
if (options.default !== undefined) return schema.optional().default(options.default);
|
||||
if (options.default !== undefined) return schema.default(options.default);
|
||||
|
||||
return schema.optional();
|
||||
return schema;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user