Files
app/src/schemas/plan.schema.ts
BOHA 519edce373 fix: 2026-06-09 full-codebase audit hardening
Validation: shared NaN-guarded Zod coercion helpers in schemas/common.ts replace
the raw number|string transform idiom across every schema (the root-cause NaN bug
class); emailOrEmpty + lenient isoDateString/timeString.

Security: roles privilege-escalation closed; refresh-token family revocation on
reuse; TOTP uses config params; read endpoints permission-guarded; received-invoices
gross VAT on all paths; orders-pdf custom-items authz.

Concurrency: $queryRaw SELECT...FOR UPDATE locks in ascending-id order (warehouse
confirm/cancel, attendance lockUserRow); uniqueness checks moved into create
transactions (TOCTOU -> 409); deterministic id tiebreak on second-precision
timestamp ordering (plan resolveCell/resolveGrid, warehouse FIFO).

Frontend: Rules-of-Hooks fixed across ~14 pages + PlanCellModal; UTC-date persisted
fields; dashboard invalidation gaps; stale-closure confirm bugs.

Tooling/tests: ESLint flat config (react-hooks/rules-of-hooks = error) + Prettier;
tsconfig.test.json so tsc -b type-checks the tests; removed 3 dead deps; npm audit
fix (8 -> 3). Suite 195 -> 247 (happy-path auth, FIFO oldest-first, flakiness fixes),
isolated on app_test via .env.test with a hard-throw setup guard.

Gates: tsc 0 | build 0 | vitest 247/247 | eslint 0 errors.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 06:45:26 +02:00

91 lines
2.6 KiB
TypeScript

import { z } from "zod";
import { intIdFromForm, isoDateString, nullableNumberFromForm } from "./common";
const isoDate = isoDateString;
const intFromForm = intIdFromForm;
// Category is now a dynamic key (validated against plan_categories in the
// service). Keep it a non-empty string here.
const planCategoryEnum = z.string().trim().min(1, "Kategorie je povinná");
export const CreatePlanEntrySchema = z
.object({
user_id: intFromForm,
date_from: isoDate,
date_to: isoDate,
project_id: nullableNumberFromForm.nullish(),
category: planCategoryEnum.default("work"),
note: z.string().max(500, "Maximálně 500 znaků"),
})
.refine((v) => v.date_to >= v.date_from, {
message: "Datum do musí být stejné nebo po datumu od",
path: ["date_to"],
});
export const UpdatePlanEntrySchema = z
.object({
date_from: isoDate.optional(),
date_to: isoDate.optional(),
project_id: nullableNumberFromForm.nullish(),
category: planCategoryEnum.optional(),
note: z.string().max(500).optional(),
})
.refine(
(v) =>
v.date_from === undefined ||
v.date_to === undefined ||
v.date_to >= v.date_from,
{
message: "Datum do musí být stejné nebo po datumu od",
path: ["date_to"],
},
);
export const CreatePlanOverrideSchema = z.object({
user_id: intFromForm,
shift_date: isoDate,
project_id: nullableNumberFromForm.nullish(),
category: planCategoryEnum,
note: z.string().max(500, "Maximálně 500 znaků"),
});
export const UpdatePlanOverrideSchema = z.object({
project_id: nullableNumberFromForm.nullish(),
category: planCategoryEnum.optional(),
note: z.string().max(500).optional(),
});
export const PlanRangeQuerySchema = z.object({
user_id: intFromForm.optional(),
date_from: isoDate,
date_to: isoDate,
});
export const PlanGridQuerySchema = z.object({
date_from: isoDate,
date_to: isoDate,
view: z.enum(["week", "month"]).default("week"),
});
export const BulkPlanEntrySchema = z
.object({
user_ids: z
.array(intFromForm)
.min(1, "Vyberte alespoň jednoho zaměstnance")
.transform((ids) => [...new Set(ids)]),
date_from: isoDate,
date_to: isoDate,
include_weekends: z
.union([z.boolean(), z.string()])
.transform((v) => v === true || v === "true" || v === "1")
.default(false),
project_id: nullableNumberFromForm.nullish(),
category: planCategoryEnum.default("work"),
note: z.string().max(500, "Maximálně 500 znaků").default(""),
})
.refine((v) => v.date_to >= v.date_from, {
message: "Datum do musí být stejné nebo po datumu od",
path: ["date_to"],
});