fix(projects): reject inverted task start/due dates (PMS-398) #304
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/PMS-398-task-date-ordering"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Enforces
start_date <= due_dateon task create and update (PMS-398), closing the gap that let an inverted negative-duration range persist. Adds a sharedtask_dates_okpredicate (equality allowed for single-day tasks;Noneon either side is unbounded) mirroring the PMS-343 appointment fix and PMS-306 contract check. Both request DTOs gain a#[validate(schema(...))]cross-field validator that re-keys the error ontodue_dateviacross_field_errorso the SPA shows it inline (PMS-364), andupdate_taskadditionally combines requested dates with the stored row before the UPDATE so a one-sided partial PUT cannot invert the range against stored values. Covered by 6 unit tests; fmt/clippy/tests all green in the dev container.#PMS-398
Tasks carried optional start_date/due_date on CreateTaskRequest and UpdateTaskRequest with no ordering check, so an inverted (negative-duration) range could be persisted. This adds a shared task_dates_ok(start, due) predicate (true when either side is None or start <= due, so a single-day task where start == due is valid and only start > due is rejected), mirroring appointment_range_ok (PMS-343) and the contract date range check (PMS-306). Both request DTOs now carry a #[validate(schema(function = ...))] cross-field validator that returns cross_field_error("task_dates_inverted", "due_date", ...) so the SPA renders the message inline against due_date rather than as a generic banner (PMS-364). The update_task service path additionally combines each requested date with the stored row from the to_jsonb before snapshot (request wins, else stored) and rejects an inverted effective range with AppError::BadRequest before the UPDATE runs, so a one-sided partial PUT cannot invert the range against the stored values. Unit tests cover task_dates_ok for both-None, only-start, only-due, equal, valid-ordered, and inverted cases. #PMS-398 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>