fix: resolve commission_rate schema mismatch causing silent default on project creation - #18
Merged
Merged
Conversation
DebojitxBhatt
force-pushed
the
fix/commission-rate-schema
branch
from
August 9, 2026 08:50
0de80a7 to
d323586
Compare
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Problem
Closes #10
Project creation was silently ignoring the actual commission rate and always saving the schema default (20%) instead.
Root Cause
The Mongoose model (
models/project.js) defines the field ascommisson_rate(typo, missing an "i"). Every part of the codebase that reads or writes this field —EditProject.tsx, thePUThandler,commission/route.js,invoice/route.js,stat/route.js— already uses that exact spelling and is internally consistent.The one exception was the
POSThandler inapp/api/project/route.js, which saved the field ascommission_rate(correct spelling). Since Mongoose runs in strict mode by default, it silently dropped that field on every new project and fell back to the schema default of 20%, regardless of the sales person's actual contracted rate.Changes
app/api/project/route.js: renamedcommission_rate→commisson_ratein thePOSThandler so project creation matches the schema and every other consumer.models/project.js:import { string } from "sharp/lib/is") that was being used in place of Mongoose's built-inStringtype forclientName,email,phone, andaddress. Fixed those four fields to usetype: String.min: 0, max: 100bounds tocommisson_rateto prevent invalid data from being saved.Testing
I wasn't able to test this end-to-end locally — there's no
.env/dev environment configuration available yet, so I can't connect to a database or run the app fully. The fix is based on tracing every read/write of this field across the codebase to confirm the schema, frontend, and other API routes all agree oncommisson_rate, and that thePOSThandler was the sole outlier.Would appreciate a DB-backed test (create a project, confirm the saved rate matches the sales person's contract rate rather than defaulting to 20%) before merging.