fix(illness): allow creating episodes before noon

This commit is contained in:
Konrad Garbal committed 2026-11-15 09:22:26 +01:00
1 parent ecde3330c1
commit 851d52b137
11 files changed
+653 -90

No files matched your search

@@ -3,7 +3,7 @@
* episode schemas. An episode can never resolve before it began; the schema
* `superRefine` rejects an inverted window when both instants are supplied
* (a partial edit touching only one is checked against the stored row in the
* route).
* route). Instants are compared at millisecond precision via Date.parse.
*/
import { describe, expect, it } from "vitest";
import {
@@ -49,6 +49,24 @@ describe("illnessEpisodeCreateSchema — window invariant", () => {
});
expect(out.success).toBe(true);
});
it.each([
["after", "2026-01-10T11:00:00Z", true],
["before", "2026-01-10T09:00:00Z", false],
["equal", "2026-01-10T10:00:00Z", true],
])(
"compares mixed Z/offset instants correctly (%s)",
(_, resolvedAt, expected) => {
// 19:00:00+09:00 is 10:00:00Z
const out = illnessEpisodeCreateSchema.safeParse({
label: "Cold",
type: "INFECTION",
onsetAt: "2026-01-10T19:00:00+09:00",
resolvedAt,
});
expect(out.success).toBe(expected);
},
);
});
describe("illnessEpisodeUpdateSchema — window invariant", () => {
+10 -2
View File
@@ -84,7 +84,11 @@ export const illnessEpisodeCreateSchema = z
// server-side when omitted, so the invariant only bites when BOTH instants
// are supplied (the inverted-window case).
.superRefine((v, ctx) => {
if (v.resolvedAt && v.onsetAt && v.resolvedAt < v.onsetAt) {
if (
v.resolvedAt &&
v.onsetAt &&
Date.parse(v.resolvedAt) < Date.parse(v.onsetAt)
) {
ctx.addIssue({
code: "custom",
path: ["resolvedAt"],
@@ -116,7 +120,11 @@ export const illnessEpisodeUpdateSchema = z
// parse time. A partial edit touching only one is validated against the
// stored value in the route (it must load the row anyway).
.superRefine((v, ctx) => {
if (v.resolvedAt && v.onsetAt && v.resolvedAt < v.onsetAt) {
if (
v.resolvedAt &&
v.onsetAt &&
Date.parse(v.resolvedAt) < Date.parse(v.onsetAt)
) {
ctx.addIssue({
code: "custom",
path: ["resolvedAt"],