fix(validation): range/scale-guard money and hours numeric fields (PMS-383) #294
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/PMS-383-numeric-money-hours-validation"
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?
Six create/update endpoints bound a Decimal/f64 money or hours field straight to a DECIMAL/NUMERIC column with no request-layer guard, so an oversized value overflowed the column and surfaced as a raw 500 (numeric-field-overflow DATABASE_ERROR) instead of a clean 422, and excess scale was silently rounded.
Add a shared
mokosh_types::validationmodule (sibling to the server crate'svalidate_money_amount/validate_budget_*, but living inmokosh-typesso bothmokosh-serverand themokosh-appsclient share one definition) withvalidate_rate(DECIMAL(10,2)),validate_hours(DECIMAL(10,2)),validate_rate_per_mile(NUMERIC(8,4)), andvalidate_distance_miles(NUMERIC(8,2), strictly positive). Each rejects negatives (distance: non-positive), more decimal places than the column holds, and magnitudes that would overflow.Apply via
#[validate(custom(...))]on the affected fields:default_rate(work types),hourly_rate(time entries create/update),distance_miles+rate_per_mile(mileage create/update), andhourly_rate+estimated_hours(projects/tasks create/update). The ticketestimated_hoursisOption<f64>, so it uses arange(min = 0.0, max = 99_999_999.99)bound mirroring the existingsla_multiplierpattern; that also rejectsNaN/Infinity, which fail the comparison.#PMS-383