From e22210aca80fc46a9ffd73af4367cc0ca3eb9c59 Mon Sep 17 00:00:00 2001 From: Maurice Date: Tue, 17 Nov 2026 21:02:25 +0100 Subject: [PATCH] fix(db): refuse a fraction for an integer column at the request boundary Every integer column is bigint on Postgres. SQLite stored a fraction sent to one (a packing quantity of 1.5, a budget item for 2.5 days, an id of 3.5) as a REAL, while Postgres rounded it in a statement MikroORM renders and refused it with a 500 in a Kysely statement, so the engines held different data for the same request. The request schemas of those fields now take whole numbers only, and INTCOL (tests/unit/contracts/integer-columns.test.ts) holds the class: it reads the integer columns from the entities and fails on any DTO field or inline MCP tool field of that name that takes any number. --- server/src/nest/packing/packing.mcp.ts | 2 +- .../unit/contracts/integer-columns.test.ts | 258 ++++++++++++++++++ shared/src/admin/admin.schema.ts | 4 +- shared/src/assignment/assignment.schema.ts | 4 +- shared/src/budget/budget.schema.ts | 24 +- shared/src/collab/collab.schema.ts | 10 +- shared/src/collection/collection.schema.ts | 46 ++-- shared/src/file/file.schema.ts | 2 +- shared/src/memories/memories.schema.ts | 8 +- shared/src/packing/packing.schema.ts | 18 +- shared/src/place/place.schema.ts | 2 +- shared/src/reservation/reservation.schema.ts | 10 +- shared/src/todo/todo.schema.ts | 8 +- shared/src/trip/trip.schema.ts | 6 +- shared/src/vacay/vacay.schema.ts | 12 +- 15 files changed, 337 insertions(+), 77 deletions(-) create mode 100644 server/tests/unit/contracts/integer-columns.test.ts diff --git a/server/src/nest/packing/packing.mcp.ts b/server/src/nest/packing/packing.mcp.ts index be4498560..125153fa5 100644 --- a/server/src/nest/packing/packing.mcp.ts +++ b/server/src/nest/packing/packing.mcp.ts @@ -664,7 +664,7 @@ export class PackingMcp { .max(100) .optional() .describe('Bag name to assign the item to; created if it does not exist'), - weight_grams: z.number().nonnegative().optional(), + weight_grams: z.number().int().nonnegative().optional(), checked: z.boolean().optional(), }), ) diff --git a/server/tests/unit/contracts/integer-columns.test.ts b/server/tests/unit/contracts/integer-columns.test.ts new file mode 100644 index 000000000..e6606dad4 --- /dev/null +++ b/server/tests/unit/contracts/integer-columns.test.ts @@ -0,0 +1,258 @@ +/** + * INTCOL: a request number bound for an integer column is a + * whole number at the request boundary. + * + * Every integer column is `bigint` on Postgres. SQLite stores a fraction sent + * to one as a REAL without a word, while Postgres rounds it (a statement + * MikroORM renders) or refuses it with a 500 (a Kysely statement, whose + * values travel as text), so the two engines end up holding different data + * for the same request. The fix is to refuse the fraction before it reaches + * the database, with `.int()` on the field in the `@trek/shared` schema, the + * way `idSchema` already does for ids. + * + * This walks every `class X extends createZodDto(...)` under src/ (the schemas + * the global ZodValidationPipe enforces, found as contracts:dto-open finds + * them), and reads the fields an MCP tool declares inline in a `*.mcp.ts`, and + * fails on a number field without `.int()` whose name is a column + * that is an integer in some entity and fractional in none. The names come + * from the entity files (`: p.integer()`), so a new integer column is + * checked as soon as it exists. A field that shares a column's name but does + * not end up in it goes into NOT_A_COLUMN with the reason; a name that is + * an integer in one table and a double in another (`sort_order`, `position`) + * cannot be judged by its name and is left out. + */ +import { isZodDto } from 'nestjs-zod/dto'; +import { readdirSync, readFileSync, statSync } from 'node:fs'; +import path from 'node:path'; +import { pathToFileURL } from 'node:url'; +import { beforeAll, describe, expect, it } from 'vitest'; +import { z } from 'zod'; + +const SERVER_ROOT = path.resolve(__dirname, '../../..'); +const SRC = path.join(SERVER_ROOT, 'src'); +const ENTITIES = path.join(SRC, 'db/entities'); + +/** + * Fields named like an integer column that never reach one, each with its + * reason, keyed `DtoClass.path`, or `DtoClass` alone for every field of a DTO + * that is stored as one document or not stored at all. Only add one when the + * value never lands in an integer column. + */ +const NOT_A_COLUMN: Record = { + BookSaveDto: 'the photo book is stored whole as one JSON document; its sizes and widths are layout measures', + ImmichSearchDto: 'a search sent on to Immich: size is its page size and the offset a time zone, neither is stored', + SynologySearchDto: + 'a search sent on to Synology Photos: size is its page size and the offset a time zone, neither is stored', +}; + +/** Whether `key` (`DtoClass.path`) is excused by NOT_A_COLUMN. */ +function excused(key: string): boolean { + return key in NOT_A_COLUMN || key.split('.')[0] in NOT_A_COLUMN; +} + +/** An inline MCP tool field: `name: z.number()` or `name: z.coerce.number()`, with the rest of its line. */ +const INLINE_NUMBER = /\b(\w+): z\.(?:coerce\.)?number\(\)(.*)$/gm; +const DTO_CLASS = /\bexport\s+class\s+(\w+)\s+extends\s+createZodDto\s*\(/g; +const COLUMN = /^\s+(\w+): (?:\(\) => )?p\.(\w+)\(/gm; +const INTEGER_TYPES = new Set(['integer', 'smallint', 'bigint', 'tinyint', 'mediumint']); +const FRACTIONAL_TYPES = new Set(['double', 'float', 'decimal', 'real']); + +function sourceFiles(dir: string, files: string[] = []): string[] { + for (const name of readdirSync(dir)) { + const full = path.join(dir, name); + if (statSync(full).isDirectory()) sourceFiles(full, files); + else if (name.endsWith('.ts') && !name.endsWith('.d.ts')) files.push(full); + } + return files; +} + +/** The column names that are an integer in some entity and fractional in none. */ +function integerColumnNames(entitySources: readonly string[]): Set { + const integer = new Set(); + const fractional = new Set(); + for (const source of entitySources) { + for (const [, name, type] of source.matchAll(COLUMN)) { + if (INTEGER_TYPES.has(type)) integer.add(name); + if (FRACTIONAL_TYPES.has(type)) fractional.add(name); + } + } + return new Set([...integer].filter((name) => !fractional.has(name))); +} + +/** What a zod schema holds once its wrappers (optional, nullable, default, both ends of a pipe, ...) are taken off. */ +function children(schema: z.ZodType): Array<[string | null, z.ZodType]> { + const def = schema._zod.def as unknown as Record & { type: string }; + switch (def.type) { + case 'object': + return Object.entries(def.shape as Record); + case 'optional': + case 'nullable': + case 'default': + case 'prefault': + case 'readonly': + case 'catch': + case 'nonoptional': + case 'success': + return [[null, def.innerType as z.ZodType]]; + case 'pipe': + return [ + [null, def.in as z.ZodType], + [null, def.out as z.ZodType], + ]; + case 'array': + return [[null, def.element as z.ZodType]]; + case 'union': + return (def.options as z.ZodType[]).map((option) => [null, option]); + case 'intersection': + return [ + [null, def.left as z.ZodType], + [null, def.right as z.ZodType], + ]; + case 'record': + return [[null, def.valueType as z.ZodType]]; + case 'tuple': + return (def.items as z.ZodType[]).map((item) => [null, item]); + case 'lazy': + return [[null, (def.getter as () => z.ZodType)()]]; + default: + return []; + } +} + +/** + * The paths in `schema` whose field is named like an integer column but takes + * any number. A path names the object keys from the root, so a nested field + * reads `items.quantity`. + */ +function fractionalIntegerFields(schema: z.ZodType, integerNames: ReadonlySet): string[] { + const found = new Set(); + const seen = new Set(); + const walk = (node: z.ZodType, trail: string[], field: string | null): void => { + if (seen.has(node)) return; + seen.add(node); + if (node instanceof z.ZodNumber && field !== null && integerNames.has(field) && !node.isInt) { + found.add(trail.join('.')); + } + for (const [key, child] of children(node)) { + if (key === null) walk(child, trail, field); + else walk(child, [...trail, key], key); + } + seen.delete(node); + }; + walk(schema, [], null); + return [...found].sort(); +} + +/** `file:line field` for every inline number field in `source` named like an integer column without `.int()`. */ +function fractionalInlineFields(file: string, source: string, integerNames: ReadonlySet): string[] { + const found: string[] = []; + for (const match of source.matchAll(INLINE_NUMBER)) { + const [, field, rest] = match; + if (!integerNames.has(field) || rest.startsWith('.int()')) continue; + const line = source.slice(0, match.index).split('\n').length; + found.push(`${file}:${line} ${field}`); + } + return found; +} + +describe('request numbers bound for integer columns', () => { + let integerNames: Set; + let found: string[]; + let inline: string[]; + let dtoCount: number; + + beforeAll(async () => { + integerNames = integerColumnNames( + readdirSync(ENTITIES) + .filter((name) => name.endsWith('.entity.ts')) + .map((name) => readFileSync(path.join(ENTITIES, name), 'utf8')), + ); + found = []; + dtoCount = 0; + inline = sourceFiles(SRC) + .filter((file) => file.endsWith('.mcp.ts')) + .flatMap((file) => + fractionalInlineFields( + path.relative(SERVER_ROOT, file).split(path.sep).join('/'), + readFileSync(file, 'utf8'), + integerNames, + ), + ); + const files = sourceFiles(SRC).filter((file) => readFileSync(file, 'utf8').includes('createZodDto')); + const modules = await Promise.all( + files.map(async (file) => ({ + names: [...readFileSync(file, 'utf8').matchAll(DTO_CLASS)].map(([, name]) => name), + namespace: (await import(pathToFileURL(file).href)) as Record, + })), + ); + for (const { names, namespace } of modules) { + for (const name of names) { + const dto = namespace[name]; + if (typeof dto !== 'function' || !isZodDto(dto)) continue; + dtoCount++; + for (const field of fractionalIntegerFields(dto.schema as z.ZodType, integerNames)) + found.push(`${name}.${field}`); + } + } + }, 120_000); + + it('INTCOL-001: the walk saw DTOs and integer columns', () => { + expect(dtoCount, 'no DTO class found under src/: the check would look at nothing').toBeGreaterThan(0); + expect(integerNames.has('quantity')).toBe(true); + }); + + it('INTCOL-002: every such field is a whole number', () => { + expect( + found.filter((key) => !excused(key)), + 'add .int() to these fields in the @trek/shared schema: the column is bigint on Postgres, ' + + 'which cannot hold the fraction SQLite would store. If the field never reaches that column, ' + + 'list it in NOT_A_COLUMN in this file with the reason.', + ).toEqual([]); + }); + + it('INTCOL-006: no MCP tool declares such a field inline without .int()', () => { + expect(inline, 'add .int() to these inline MCP fields, or take the field from the @trek/shared schema').toEqual([]); + }); + + it('INTCOL-003: NOT_A_COLUMN names only fields that would be reported', () => { + const stale = Object.keys(NOT_A_COLUMN).filter( + (entry) => !found.some((key) => key === entry || key.startsWith(`${entry}.`)), + ); + expect(stale, 'drop these NOT_A_COLUMN entries: nothing they excuse is reported any more').toEqual([]); + }); +}); + +describe('the walk itself', () => { + const names = integerColumnNames([ + ' quantity: p.integer(),\n plan: () => p.manyToOne(Plans),\n plan_id: p.integer().persist(false),\n', + ' lat: p.double().nullable(),\n sort_order: p.integer(),\n', + ' sort_order: p.double(),\n', + ]); + + it('INTCOL-004: reads integer columns from the entities and drops the names a table keeps fractional', () => { + expect([...names].sort()).toEqual(['plan_id', 'quantity']); + }); + + it('INTCOL-005: finds a bare number through wrappers, arrays and nesting, and accepts .int()', () => { + const schema = z.object({ + quantity: z.number().optional(), + plan_id: z.number().int(), + lat: z.number(), + items: z.array(z.object({ quantity: z.number().nullable().default(null) })), + nested: z.object({ plan_id: z.coerce.number() }).optional(), + sort_order: z.number(), + }); + expect(fractionalIntegerFields(schema, names)).toEqual(['items.quantity', 'nested.plan_id', 'quantity']); + expect(fractionalIntegerFields(z.object({ quantity: z.int() }), names)).toEqual([]); + }); + + it('INTCOL-007: finds an inline MCP number field without .int() and its line', () => { + const source = [ + ' quantity: z.number().optional(),', + ' plan_id: z.number().int(),', + ' lat: z.number(),', + ' quantity: z.coerce.number().min(1),', + ].join('\n'); + expect(fractionalInlineFields('a.mcp.ts', source, names)).toEqual(['a.mcp.ts:1 quantity', 'a.mcp.ts:4 quantity']); + }); +}); diff --git a/shared/src/admin/admin.schema.ts b/shared/src/admin/admin.schema.ts index 4c2cb430c..7c74fe9c9 100644 --- a/shared/src/admin/admin.schema.ts +++ b/shared/src/admin/admin.schema.ts @@ -40,12 +40,12 @@ export type AdminPermissionsRequest = z.infer; diff --git a/shared/src/assignment/assignment.schema.ts b/shared/src/assignment/assignment.schema.ts index 5be28cc6f..525643703 100644 --- a/shared/src/assignment/assignment.schema.ts +++ b/shared/src/assignment/assignment.schema.ts @@ -74,7 +74,7 @@ export const assignmentSchema = z.object({ export type Assignment = z.infer; export const assignmentCreateRequestSchema = z.object({ - place_id: z.union([z.number(), z.string()]), + place_id: z.union([z.number().int(), z.string()]), notes: z.string().nullable().optional(), /** * MDT-02: puts one stage of a multi-day tour on the day instead of the whole @@ -94,7 +94,7 @@ export const assignmentMoveRequestSchema = z.object({ new_day_id: z.union([z.number(), z.string()]), // The client api types this `number | null` (assignmentsApi.move) and the // legacy route accepted null (`orderIndex || 0`) — keep null on the wire. - order_index: z.number().nullable().optional(), + order_index: z.number().int().nullable().optional(), }); export type AssignmentMoveRequest = z.infer; diff --git a/shared/src/budget/budget.schema.ts b/shared/src/budget/budget.schema.ts index 5febac67a..5ce81b0b4 100644 --- a/shared/src/budget/budget.schema.ts +++ b/shared/src/budget/budget.schema.ts @@ -117,12 +117,12 @@ export const budgetItemSchema = z.object({ export type BudgetItem = z.infer; const payerInputSchema = z.object({ - user_id: z.number(), + user_id: z.number().int(), amount: z.number(), }); const memberInputSchema = z.object({ - user_id: z.number(), + user_id: z.number().int(), amount: z.number().nullable().optional(), }); @@ -161,17 +161,17 @@ export const budgetCreateItemRequestSchema = z.object({ // Equal-split participants. When omitted, the item has no split (planning-only). member_ids: z.array(z.number()).optional(), members: z.array(memberInputSchema).optional(), - persons: z.number().nullable().optional(), - days: z.number().nullable().optional(), + persons: z.number().int().nullable().optional(), + days: z.number().int().nullable().optional(), note: z.string().nullable().optional(), ticket_json: z.string().nullable().optional(), expense_date: z.string().nullable().optional(), // Link this expense to a reservation (e.g. created from a booking's // "add expense" flow). The server stores it on budget_items.reservation_id. - reservation_id: z.number().optional(), + reservation_id: z.number().int().optional(), // The same for a place: the place form's "add expense" flow saves the place // first, then creates the expense against it (#1298). - place_id: z.number().optional(), + place_id: z.number().int().optional(), // Receipt files to link to this expense receipt_file_ids: z.array(z.number()).optional(), // Rates to freeze a foreign currency with when the server has none of its own. @@ -189,8 +189,8 @@ export const budgetUpdateItemRequestSchema = z.object({ payers: z.array(payerInputSchema).optional(), member_ids: z.array(z.number()).optional(), members: z.array(memberInputSchema).optional(), - persons: z.number().nullable().optional(), - days: z.number().nullable().optional(), + persons: z.number().int().nullable().optional(), + days: z.number().int().nullable().optional(), note: z.string().nullable().optional(), ticket_json: z.string().nullable().optional(), expense_date: z.string().nullable().optional(), @@ -244,8 +244,8 @@ export const budgetSettlementSchema = z.object({ export type BudgetSettlement = z.infer; export const budgetCreateSettlementRequestSchema = z.object({ - from_user_id: z.number(), - to_user_id: z.number(), + from_user_id: z.number().int(), + to_user_id: z.number().int(), amount: z.number(), // The display currency the amount was entered in; the server freezes its FX rate. currency: z.string().nullable().optional(), @@ -261,8 +261,8 @@ export type BudgetCreateSettlementRequest = z.infer; @@ -44,7 +44,7 @@ export const collabPollCreateRequestSchema = z.object({ export type CollabPollCreateRequest = z.infer; export const collabPollVoteRequestSchema = z.object({ - option_index: z.number(), + option_index: z.number().int(), }); export type CollabPollVoteRequest = z.infer; @@ -57,14 +57,14 @@ const httpUrl = z.url().refine((value) => /^https?:\/\//i.test(value.trim()), 'A export const collabLinkCreateRequestSchema = z.object({ title: z.string().trim().min(1), url: httpUrl, - pinned: z.union([z.boolean(), z.number()]).optional(), + pinned: z.union([z.boolean(), z.number().int()]).optional(), }); export type CollabLinkCreateRequest = z.infer; export const collabLinkUpdateRequestSchema = z.object({ title: z.string().trim().min(1).optional(), url: httpUrl.optional(), - pinned: z.union([z.boolean(), z.number()]).optional(), + pinned: z.union([z.boolean(), z.number().int()]).optional(), }); export type CollabLinkUpdateRequest = z.infer; @@ -73,7 +73,7 @@ export type CollabLinkUpdateRequest = z.infer; diff --git a/shared/src/collection/collection.schema.ts b/shared/src/collection/collection.schema.ts index ac945511f..41547717b 100644 --- a/shared/src/collection/collection.schema.ts +++ b/shared/src/collection/collection.schema.ts @@ -157,15 +157,15 @@ export type CollectionReorderRequest = z.infer; /** Bulk: copy several selected trip places into a list at once. */ export const collectionSaveFromTripManyRequestSchema = z.object({ - collection_id: z.number(), - source_trip_id: z.number(), + collection_id: z.number().int(), + source_trip_id: z.number().int(), source_place_ids: z.array(z.number()).min(1).max(1000), force: z.boolean().optional(), }); @@ -215,8 +215,8 @@ export const collectionPlaceUpdateRequestSchema = z.object({ // undefined (left unchanged) instead of being injected as 'idea' (see #1437). The // .catch('idea') guard against invalid values is preserved. status: collectionStatusSchema.removeDefault().optional(), - category_id: z.number().nullable().optional(), - collection_id: z.number().optional(), // move to another list + category_id: z.number().int().nullable().optional(), + collection_id: z.number().int().optional(), // move to another list links: collectionLinksSchema.optional(), tag_ids: z.array(z.number()).optional(), // Replace the place's per-collection label assignments (omit to leave unchanged). @@ -250,7 +250,7 @@ export type CollectionSetStatusManyRequest = z.infer; -export const collectionInviteActionRequestSchema = z.object({ collection_id: z.number() }); +export const collectionInviteActionRequestSchema = z.object({ collection_id: z.number().int() }); export type CollectionInviteActionRequest = z.infer; export const collectionInviteCancelRequestSchema = z.object({ - collection_id: z.number(), - user_id: z.number(), + collection_id: z.number().int(), + user_id: z.number().int(), }); export type CollectionInviteCancelRequest = z.infer; /** Owner removes an ALREADY-ACCEPTED member (kick). */ export const collectionRemoveMemberRequestSchema = z.object({ - collection_id: z.number(), - user_id: z.number(), + collection_id: z.number().int(), + user_id: z.number().int(), }); export type CollectionRemoveMemberRequest = z.infer; /** Owner changes an accepted member's permission role. */ export const collectionSetMemberRoleRequestSchema = z.object({ - collection_id: z.number(), - user_id: z.number(), + collection_id: z.number().int(), + user_id: z.number().int(), role: collectionRoleSchema, }); export type CollectionSetMemberRoleRequest = z.infer; @@ -363,7 +363,7 @@ const labelColorSchema = z.string().regex(/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/); /** Create a custom label in a list. */ export const collectionLabelCreateRequestSchema = z.object({ - collection_id: z.number(), + collection_id: z.number().int(), name: z.string().trim().min(1).max(60), color: labelColorSchema.optional(), }); diff --git a/shared/src/file/file.schema.ts b/shared/src/file/file.schema.ts index e219336e0..eec6de4f2 100644 --- a/shared/src/file/file.schema.ts +++ b/shared/src/file/file.schema.ts @@ -12,7 +12,7 @@ import { z } from 'zod'; * bodies. The bespoke 400/403/404 controller messages pin the rest. */ -const nullableIdField = z.union([z.string(), z.number()]).nullable().optional(); +const nullableIdField = z.union([z.string(), z.number().int()]).nullable().optional(); /** * Multipart text fields riding along with the upload — always strings on the diff --git a/shared/src/memories/memories.schema.ts b/shared/src/memories/memories.schema.ts index b6c87cc1d..0045a86ff 100644 --- a/shared/src/memories/memories.schema.ts +++ b/shared/src/memories/memories.schema.ts @@ -25,6 +25,8 @@ const looseBoolean = z.union([z.boolean(), z.literal('true'), z.literal('false') /** `Number(x) || fallback` — the client sends these as strings from query-ish forms. */ const looseNumber = z.union([z.number(), z.string()]).optional(); +/** A row id the same loose way: a whole number, or a string the service converts. */ +const looseId = z.union([z.number().int(), z.string()]).optional(); /** * The UTC offset the caller means its calendar days in, in minutes east of UTC @@ -119,7 +121,7 @@ export const synologySearchSchema = z.looseObject({ export const photoSelectionSchema = z.looseObject({ provider: z.string(), asset_ids: z.array(z.string()), - owner_id: z.number().optional(), + owner_id: z.number().int().optional(), passphrase: z.string().optional(), }); @@ -131,13 +133,13 @@ export const addTripPhotosSchema = z.looseObject({ }); export const setTripPhotoSharingSchema = z.looseObject({ - photo_id: looseNumber, + photo_id: looseId, shared: z.unknown().optional(), }); /** The photo to unlink from the trip. Same shape the sharing toggle takes. */ export const removeTripPhotoSchema = z.looseObject({ - photo_id: looseNumber, + photo_id: looseId, }); export const createAlbumLinkSchema = z.looseObject({ diff --git a/shared/src/packing/packing.schema.ts b/shared/src/packing/packing.schema.ts index 2d5586180..be43edbc9 100644 --- a/shared/src/packing/packing.schema.ts +++ b/shared/src/packing/packing.schema.ts @@ -102,9 +102,9 @@ export const packingCreateItemRequestSchema = z.object({ checked: z.union([z.boolean(), z.number().int().min(0).max(1)]).optional(), // Same shapes as the update schema below (#2154) — the create route used to // strip these three silently, forcing a second write to set them. - weight_grams: z.number().nullable().optional(), - bag_id: z.number().nullable().optional(), - quantity: z.number().optional(), + weight_grams: z.number().int().nullable().optional(), + bag_id: z.number().int().nullable().optional(), + quantity: z.number().int().optional(), // Mark the new item private to its creator (#858, legacy flag). is_private: z.boolean().optional(), // Three-tier sharing (#858): which list the item belongs to, and — for 'shared' — @@ -133,9 +133,9 @@ export const packingUpdateItemRequestSchema = z.object({ // The legacy route accepted both boolean and 0/1 for checked — both stay valid. checked: z.union([z.boolean(), z.number().int().min(0).max(1)]).optional(), category: z.string().optional(), - weight_grams: z.number().nullable().optional(), - bag_id: z.number().nullable().optional(), - quantity: z.number().optional(), + weight_grams: z.number().int().nullable().optional(), + bag_id: z.number().int().nullable().optional(), + quantity: z.number().int().optional(), // Count packed pieces of a multi-piece item (#2296). Reaching the quantity // checks the item; null or 0 clears the count. Ticking `checked` resets it. packed_quantity: z.number().int().min(0).max(999).nullable().optional(), @@ -158,15 +158,15 @@ export const packingCreateBagRequestSchema = z.object({ name: z.string().min(1), color: z.string().optional(), // Same shape as the update schema below (#2154) — POST used to strip it. - weight_limit_grams: z.number().nullable().optional(), + weight_limit_grams: z.number().int().nullable().optional(), }); export type PackingCreateBagRequest = z.infer; export const packingUpdateBagRequestSchema = z.object({ name: z.string().optional(), color: z.string().optional(), - weight_limit_grams: z.number().nullable().optional(), - user_id: z.number().nullable().optional(), + weight_limit_grams: z.number().int().nullable().optional(), + user_id: z.number().int().nullable().optional(), }); export type PackingUpdateBagRequest = z.infer; diff --git a/shared/src/place/place.schema.ts b/shared/src/place/place.schema.ts index b2447dae3..97d755ac3 100644 --- a/shared/src/place/place.schema.ts +++ b/shared/src/place/place.schema.ts @@ -298,7 +298,7 @@ export const placeBulkUpdateRequestSchema = z.object({ ids: z.array(z.number()), // null clears the category ("No category"); a number sets it. Optional so the // field can be omitted, but the endpoint requires it to be present to act. - category_id: z.number().nullable().optional(), + category_id: z.number().int().nullable().optional(), }); export type PlaceBulkUpdateRequest = z.infer; diff --git a/shared/src/reservation/reservation.schema.ts b/shared/src/reservation/reservation.schema.ts index a17dac7ce..330f17291 100644 --- a/shared/src/reservation/reservation.schema.ts +++ b/shared/src/reservation/reservation.schema.ts @@ -283,15 +283,15 @@ export const reservationPositionsRequestSchema = z.object({ // day_plan_position is optional on the wire: the legacy route never // validated position items, and an absent value binds NULL (clears the // stored position) — pinned by the server integration suite (RESV-006). - positions: z.array(z.object({ id: z.number(), day_plan_position: z.number().optional() })), - day_id: z.union([z.number(), z.string()]).nullable().optional(), + positions: z.array(z.object({ id: z.number().int(), day_plan_position: z.number().optional() })), + day_id: z.union([z.number().int(), z.string()]).nullable().optional(), }); export type ReservationPositionsRequest = z.infer; export const accommodationCreateRequestSchema = z.object({ - place_id: z.union([z.number(), z.string()]), - start_day_id: z.union([z.number(), z.string()]), - end_day_id: z.union([z.number(), z.string()]), + place_id: z.union([z.number().int(), z.string()]), + start_day_id: z.union([z.number().int(), z.string()]), + end_day_id: z.union([z.number().int(), z.string()]), check_in: z.string().nullable().optional(), check_in_end: z.string().nullable().optional(), check_out: z.string().nullable().optional(), diff --git a/shared/src/todo/todo.schema.ts b/shared/src/todo/todo.schema.ts index ede39d89d..8efb1c1b4 100644 --- a/shared/src/todo/todo.schema.ts +++ b/shared/src/todo/todo.schema.ts @@ -17,8 +17,8 @@ export const todoCreateItemRequestSchema = z.object({ category: z.string().nullable().optional(), due_date: z.string().nullable().optional(), description: z.string().nullable().optional(), - assigned_user_id: z.number().nullable().optional(), - priority: z.number().optional(), + assigned_user_id: z.number().int().nullable().optional(), + priority: z.number().int().optional(), }); export type TodoCreateItemRequest = z.infer; @@ -31,8 +31,8 @@ export const todoUpdateItemRequestSchema = z.object({ category: z.string().nullable().optional(), due_date: z.string().nullable().optional(), description: z.string().nullable().optional(), - assigned_user_id: z.number().nullable().optional(), - priority: z.number().nullable().optional(), + assigned_user_id: z.number().int().nullable().optional(), + priority: z.number().int().nullable().optional(), }); export type TodoUpdateItemRequest = z.infer; diff --git a/shared/src/trip/trip.schema.ts b/shared/src/trip/trip.schema.ts index 6b805e1b9..c4d8b374c 100644 --- a/shared/src/trip/trip.schema.ts +++ b/shared/src/trip/trip.schema.ts @@ -108,7 +108,7 @@ export const tripCreateRequestSchema = z.object({ start_date: z.string().nullable().optional(), end_date: z.string().nullable().optional(), currency: z.string().optional(), - reminder_days: z.number().optional(), + reminder_days: z.number().int().optional(), day_count: z.number().optional(), }); export type TripCreateRequest = z.infer; @@ -127,9 +127,9 @@ export const tripUpdateRequestSchema = z.object({ */ date_shift_mode: z.enum(['keep_bookings', 'shift_all']).optional(), currency: z.string().optional(), - reminder_days: z.number().optional(), + reminder_days: z.number().int().optional(), day_count: z.number().optional(), - is_archived: z.union([z.boolean(), z.number()]).optional(), + is_archived: z.union([z.boolean(), z.number().int()]).optional(), // Bounded like a place's image url: a replaced cover is queued for release, // and every upload path the old value spells out is one queued object. cover_image: z.string().max(2048).nullable().optional(), diff --git a/shared/src/vacay/vacay.schema.ts b/shared/src/vacay/vacay.schema.ts index 184e208f1..3e67a8830 100644 --- a/shared/src/vacay/vacay.schema.ts +++ b/shared/src/vacay/vacay.schema.ts @@ -29,7 +29,7 @@ export const vacayUpdatePlanRequestSchema = z.object({ company_holidays_enabled: z.boolean().optional(), carry_over_enabled: z.boolean().optional(), weekend_days: z.string().optional(), - week_start: z.number().optional(), + week_start: z.number().int().optional(), }); export type VacayUpdatePlanRequest = z.infer; @@ -60,17 +60,17 @@ export const vacaySetColorRequestSchema = z.object({ export type VacaySetColorRequest = z.infer; export const vacayInviteRequestSchema = z.object({ - user_id: z.union([z.number(), z.string()]), + user_id: z.union([z.number().int(), z.string()]), }); export type VacayInviteRequest = z.infer; export const vacayInviteActionRequestSchema = z.object({ - plan_id: z.number().optional(), + plan_id: z.number().int().optional(), }); export type VacayInviteActionRequest = z.infer; export const vacayAddYearRequestSchema = z.object({ - year: z.union([z.number(), z.string()]), + year: z.union([z.number().int(), z.string()]), }); export type VacayAddYearRequest = z.infer; @@ -110,7 +110,7 @@ export const vacayCompanyHolidayRequestSchema = z.object({ export type VacayCompanyHolidayRequest = z.infer; export const vacayUpdateStatsRequestSchema = z.object({ - vacation_days: z.number().optional(), + vacation_days: z.number().int().optional(), target_user_id: z.union([z.number(), z.string()]).optional(), }); export type VacayUpdateStatsRequest = z.infer; @@ -118,7 +118,7 @@ export type VacayUpdateStatsRequest = z.infer;