Repository navigation
Om 97 #67
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
Om 97 #67
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| import { z } from "zod"; | ||
|
|
||
| const emptyToUndefined = (value: unknown) => | ||
| value === "" || value === null ? undefined : value; | ||
|
|
||
| export const FilterStoreProductsDTO = z | ||
| .object({ | ||
| name: z.string().trim().optional(), | ||
|
|
||
| category: z.preprocess( | ||
| emptyToUndefined, | ||
| z | ||
| .string() | ||
| .transform(Number) | ||
| .pipe(z.number().int().positive("category debe ser un ID valido")) | ||
| .optional() | ||
| ), | ||
|
|
||
| price_min: z.preprocess( | ||
| emptyToUndefined, | ||
| z | ||
| .string() | ||
| .transform(Number) | ||
| .pipe(z.number().min(0, "price_min debe ser mayor o igual a 0")) | ||
| .optional() | ||
| ), | ||
|
|
||
| price_max: z.preprocess( | ||
| emptyToUndefined, | ||
| z | ||
| .string() | ||
| .transform(Number) | ||
| .pipe(z.number().min(0, "price_max debe ser mayor o igual a 0")) | ||
| .optional() | ||
| ), | ||
|
|
||
| available: z.preprocess( | ||
| emptyToUndefined, | ||
| z | ||
| .enum(["true", "false", "1", "0"]) | ||
| .transform((value) => value === "true" || value === "1") | ||
| .optional() | ||
| ), | ||
|
|
||
| isOffer: z.preprocess( | ||
| emptyToUndefined, | ||
| z | ||
| .enum(["true", "false", "1", "0"]) | ||
| .transform((value) => value === "true" || value === "1") | ||
| .optional() | ||
| ), | ||
|
|
||
| sortBy: z.preprocess( | ||
| emptyToUndefined, | ||
| z | ||
| .enum(["created_at", "price", "name"], { | ||
| error: "sortBy debe ser created_at, price o name" | ||
| }) | ||
| .optional() | ||
| .default("created_at") | ||
| ), | ||
|
|
||
| sortOrder: z.preprocess( | ||
| emptyToUndefined, | ||
| z | ||
| .enum(["asc", "desc"], { | ||
| error: "sortOrder debe ser asc o desc" | ||
| }) | ||
| .optional() | ||
| .default("desc") | ||
| ) | ||
|
Comment on lines
+53
to
+71
Contributor
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. 🧩 Analysis chain🌐 Web query:
💡 Result: In Zod 4, error customization for z.enum uses the unified error parameter, replacing the Zod 3 errorMap. The error param accepts either a static string (applied to all errors from the schema) or a function that receives an issue object (iss) and returns a string or {message: string}. Syntax: - Static string: z.enum(["a", "b"], "Must be a or b!") - Function (error map): z.enum(["a", "b"], { error: (iss) => "Custom message" }) The function receives iss with properties like code (e.g., "invalid_type", "invalid_value" for enum), input, expected. Return undefined to fall back to default. Example for z.enum: const StatusSchema = z.enum(["draft", "published"], { error: (issue) => { if (issue.code === "invalid_value") { return "Status must be 'draft' or 'published'"; } return "Invalid status"; } }); This applies to all issues from the z.enum schema (invalid type, invalid enum value). For refinements on the enum, use separate error params. Zod 3 used errorMap: (issue, ctx) => ({message: string}); Zod 4 simplifies to error: (issue) => string | {message: string} | undefined, dropping ctx and specific params like invalid_type_error. Precedence: schema-level > per-parse > global > locale. Citations:
Corregir la sintaxis de personalización de errores en La sintaxis 🤖 Prompt for AI Agents |
||
| }) | ||
| .refine( | ||
| (data) => | ||
| data.price_min === undefined || | ||
| data.price_max === undefined || | ||
| data.price_min <= data.price_max, | ||
| { | ||
| message: "price_min no puede ser mayor que price_max", | ||
| path: ["price_min"] | ||
| } | ||
| ); | ||
|
|
||
| export type FilterStoreProductsDTOType = z.infer<typeof FilterStoreProductsDTO>; | ||
This file was deleted.
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.
🧩 Analysis chain
🏁 Script executed:
Repository: CrisNAC/BackendMarketplace
Length of output: 530
🏁 Script executed:
Repository: CrisNAC/BackendMarketplace
Length of output: 131
🏁 Script executed:
# Check the content of src/server.js to see how it's bootstrapped head -30 src/server.jsRepository: CrisNAC/BackendMarketplace
Length of output: 279
🏁 Script executed:
Repository: CrisNAC/BackendMarketplace
Length of output: 89
🏁 Script executed:
Repository: CrisNAC/BackendMarketplace
Length of output: 650
🏁 Script executed:
Repository: CrisNAC/BackendMarketplace
Length of output: 129
🏁 Script executed:
Repository: CrisNAC/BackendMarketplace
Length of output: 754
🏁 Script executed:
Repository: CrisNAC/BackendMarketplace
Length of output: 366
🏁 Script executed:
Repository: CrisNAC/BackendMarketplace
Length of output: 83
Importación de archivo
.tsdesde archivo.jscausará error de runtime.La importación directa con extensión
.tsdesde un archivo JavaScript no funcionará. Node.js no puede resolver extensiones.tsen runtime con los scripts actuales (nodesintsx). Aunquetsxestá instalado como dependencia, los scripts destartydevusannodeynodemondirectamente, notsx.Opciones para resolver:
import { FilterStoreProductsDTO } from "../../global/dtos/commerce/filter-store-products.dto.js";(si el archivo está compilado a .js)tsxen los scripts:"start": "tsx src/server.js"y"dev": "nodemon --exec tsx src/server.js"tscse ejecute antes destart(agregar step previo)Este cambio causará un error de módulo no encontrado cuando la app intente iniciarse.
🤖 Prompt for AI Agents