fix(contracts): reject out-of-set contract_type with 422 instead of 500 #233
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/pms-299-contract-type-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?
POST /api/v1/contractsdeserializescontract_typeas a freeString, so any value passes the request layer. The DB CHECK constraint oncontracts.contract_type(migration 009) only allowsmanaged_services,block_hours,time_and_materials,fixed_price,warranty. Values outside that set (e.g.recurring,retainer) reached the INSERT, violated the constraint, and surfaced as an unhandled 500 DATABASE_ERROR.Add
validate_contract_type(validation utils) backed by aCONTRACT_TYPESconstant kept in sync with the DB CHECK set, and wire it ontoCreateContractRequest::contract_typevia#[validate(custom(...))]. Requests carrying a contract_type outside the set now fail validation and return a clear 422 listing the valid values, so no value that passes deserialization can produce a 500.recurringandretainerare item-level concepts (contract_items.item_type), not contract-level types, so they are correctly rejected at the contract layer.#PMS-299