fix(settings): bank accounts saved blank — flatten payload + harden schema to strictObject
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>
This commit is contained in:
@@ -1,7 +1,13 @@
|
||||
import { z } from "zod";
|
||||
import { booleanFromForm, numberFromForm } from "./common";
|
||||
|
||||
export const CreateBankAccountSchema = z.object({
|
||||
// `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(),
|
||||
@@ -12,7 +18,8 @@ export const CreateBankAccountSchema = z.object({
|
||||
position: numberFromForm.optional().default(0),
|
||||
});
|
||||
|
||||
export const UpdateBankAccountSchema = z.object({
|
||||
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(),
|
||||
|
||||
Reference in New Issue
Block a user