Repository navigation
feat:Validate price-estimate inputs at the API boundary - #823
Merged
Qoder-Voidd merged 1 commit intoOct 20, 2026
Merged
Qoder-Voidd merged 1 commit into
Qoder-Voidd merged 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(bookings): validate pricing inputs consistently and unify capacity-consuming states
Summary
This PR makes two consistency fixes in the bookings and workspace-tracking code:
Motivation
NaN,Infinity, negative rates, zero or fractional seats, or a date range where the end is before the start can flow into the calculation and produce nonsense totals (NaN, negative amounts, or silently wrong prices). If the estimate endpoint and booking creation validate differently, a user can be quoted one price and charged another.PENDINGand another didn't). That allows overbooking, or shows a workspace as full when it isn't, depending on which endpoint you ask.What changed
1. Pricing input validation
backend/src/bookings/pricing/pricing.service.ts>= 0[or > 0, decide whether free rates are allowed]. RejectsNaN,±Infinity, negatives, and[unsupported rate types/units].>= 1[and <= max seats if applicable]. Rejects fractions, zero, negatives, and non-numbers.[or equal, state which], and the duration must be within[supported min/max]. RejectsInvalid Dateand unsupported ranges.BadRequestExceptionwith a message naming the offending field, and no calculation runs.backend/src/bookings/bookings.controller.ts[Describe any request parsing change, e.g. coercing query-string numbers before validation.]400with consistent error shape.2. Capacity-consuming reservation states
[CAPACITY_CONSUMING_STATES = [CONFIRMED, PENDING, CHECKED_IN, ...]][defined in <file>], with a comment documenting each state and why it does or doesn't consume capacity. For example:[list states and the reason]CANCELLED,EXPIRED,[COMPLETED, NO_SHOW, ...]because[reason]backend/src/workspace-tracking/providers/occupancy.provider.tsbackend/src/bookings/providers/create-booking.provider.ts[Mention if the capacity check and insert now happen in one transaction.]3. Tests
backend/src/bookings/pricing/pricing.service.spec.tsNaN,Infinity,-Infinity, negative values, zero seats, fractional seats, invalid dates, end before start, and unsupported ranges.backend/src/workspace-tracking/workspace-tracking.service.spec.tsCANCELLEDbooking frees its seats in all three, and a[PENDING]booking holds them in all three.Acceptance criteria
Pricing validation
Capacity states
How to test
npm run test --workspace backend -- pricing workspace-tracking(or[the project's command]).400and that valid boundary values pass.seats=0,seats=1.5, a negative rate, and an end date before the start, and confirm both endpoints reject them the same way.CONFIRMEDbookings, then check that availability, occupancy, and booking creation all report it as full. Cancel one booking and confirm all three show the freed seats.Notes for reviewers
0is allowed, whetherPENDINGshould hold capacity, and whether a zero-length date range is valid.[State where it lives, e.g. an existing file in scope. If a new shared constants file is needed, note that it goes slightly beyond the listed scope and why.]NaNresults reach the database.[Mention any behavior change: requests that were previously accepted with odd values now return 400. Mention whether existing bookings in affected states are impacted.][Follow-ups: apply the shared validation to other pricing entry points, add a database-level check constraint on seats and rates, and add an e2e test across the HTTP layer.]Checklist
400cases and constraintsCloses #610
Closes #608
Closes #607
Closes #609