The bank form posted {id, bank:{...}} (nested) but the route/schema read fields
at the top level; lenient z.object silently stripped the wrapper, so every field
saved as null while returning success. Flatten the payload to top level and switch
the create/update schemas to strictObject so a future nesting 400s loudly instead
of saving a blank record. Affects both create and edit.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
35 lines
1.5 KiB
TypeScript
35 lines
1.5 KiB
TypeScript
import { z } from "zod";
|
|
import { booleanFromForm, numberFromForm } from "./common";
|
|
|
|
// `id` is declared (optional, ignored by the routes — they use the URL param)
|
|
// only so the client may send it in the body for URL/method routing without a
|
|
// strictObject rejection. strictObject is deliberate: a malformed/nested body
|
|
// (e.g. the old `{ id, bank: {...} }` shape) now 400s loudly instead of
|
|
// silently stripping every field and saving a blank record.
|
|
export const CreateBankAccountSchema = z.strictObject({
|
|
id: z.number().int().optional(),
|
|
account_name: z.string().max(255).nullish(),
|
|
bank_name: z.string().max(255).nullish(),
|
|
account_number: z.string().max(255).nullish(),
|
|
iban: z.string().max(255).nullish(),
|
|
bic: z.string().max(255).nullish(),
|
|
currency: z.string().max(255).optional().default("CZK"),
|
|
is_default: booleanFromForm.optional().default(false),
|
|
position: numberFromForm.optional().default(0),
|
|
});
|
|
|
|
export const UpdateBankAccountSchema = z.strictObject({
|
|
id: z.number().int().optional(),
|
|
account_name: z.string().max(255).nullish(),
|
|
bank_name: z.string().max(255).nullish(),
|
|
account_number: z.string().max(255).nullish(),
|
|
iban: z.string().max(255).nullish(),
|
|
bic: z.string().max(255).nullish(),
|
|
currency: z.string().max(255).optional(),
|
|
is_default: booleanFromForm.optional(),
|
|
position: numberFromForm.optional(),
|
|
});
|
|
|
|
export type CreateBankAccountInput = z.infer<typeof CreateBankAccountSchema>;
|
|
export type UpdateBankAccountInput = z.infer<typeof UpdateBankAccountSchema>;
|