Skip to content

fix: resolve commission_rate schema mismatch causing silent default on project creation - #18

Merged
DebojitxBhatt merged 0 commit into
stagfrom
fix/commission-rate-schema
Aug 9, 2026
Merged

fix: resolve commission_rate schema mismatch causing silent default on project creation#18
DebojitxBhatt merged 0 commit into
stagfrom
fix/commission-rate-schema

Conversation

@azlaan428

Copy link
Copy Markdown
Member

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 as commisson_rate (typo, missing an "i"). Every part of the codebase that reads or writes this field — EditProject.tsx, the PUT handler, commission/route.js, invoice/route.js, stat/route.js — already uses that exact spelling and is internally consistent.

The one exception was the POST handler in app/api/project/route.js, which saved the field as commission_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: renamed commission_ratecommisson_rate in the POST handler so project creation matches the schema and every other consumer.
  • models/project.js:
    • Removed an incorrect import (import { string } from "sharp/lib/is") that was being used in place of Mongoose's built-in String type for clientName, email, phone, and address. Fixed those four fields to use type: String.
    • Added min: 0, max: 100 bounds to commisson_rate to 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 on commisson_rate, and that the POST handler 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.

@DebojitxBhatt
DebojitxBhatt force-pushed the fix/commission-rate-schema branch from 0de80a7 to d323586 Compare August 9, 2026 08:50
@DebojitxBhatt
DebojitxBhatt merged commit d323586 into stag Aug 9, 2026
1 of 2 checks passed
@vercel

vercel Bot commented Aug 9, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
salesfam Ready Ready Preview Aug 9, 2026 8:58am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants