Repository navigation
Conversation
Sellers can enter an optional cost per unit on each item and an optional expenses total on the fundraiser. Profit = revenue from confirmed or picked-up orders - quantity * unit cost - expenses, using current costs so edits apply to past orders. Without enough cost data the Profit Goal card shows an "add costs to see profit" state instead of an estimate. Costs are seller-only: public schemas strip them, and the edit forms read them from a new admin-only GET /fundraiser/:id/costs endpoint. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
|
Great job Emir! One question: both money inputs store parseFloat(e.target.value) whenever the field is not empty, and parseFloat returns NaN for a value it cannot read. NaN is not null, so it gets saved as a real cost. Could the handler ignore NaN and leave the field null until the number is valid? The rest of the cost flow looks solid :) |
Summary
Seller analytics showed profit as a flat 20% of revenue, which is wrong for most fundraisers. Sellers can now enter real costs, and profit is calculated from them. If no costs are entered, the Profit Goal card says "Add costs to see profit" instead of showing an estimate. This replaces stale draft #134 rather than rebasing it.
Task: Replace the 20% profit margin with seller-entered costs
Changes
backend
20261122120000_add_seller_costsadds nullablefundraisers.expensesanditems.unit_cost(MONEY). No backfill is needed: null means "not entered".PROFIT_MARGINis removed. In its place,computeProfit/hasCompleteCostDatacalculate profit in the analytics build and in the cached-analytics updates for payment confirmation and pickup.order.servicesnow selectsunitCostso those cached updates have it.GET /fundraiser/:id/costs. Costs never appear on public endpoints: buyer-facing schemas strip them, and only org admins can read the new endpoint.profitis nownumber | null. Added fields:has_cost_data,item_cost,expenses.fundraiser_analytics_v2_*so cache entries from before the deploy (which lack the new fields) aren't updated in place.common
expenseson Create/UpdateFundraiserBody andunitCoston Create/UpdateFundraiserItemBody. On updates,undefinedleaves the value unchanged andnullclears it.SellerItemSchemaandFundraiserCostsSchema.frontend
diffSavedItemsnow detects unit-cost-only edits on unpublished fundraisers.How to test
Seller account, any fundraiser with confirmed or picked-up orders.
pnpm assemble, thencd backend && pnpm migrate:dev, then run both dev servers (GET /fundraiser/:id/itemshas nounitCost.GET /fundraiser/:id/costsreturns 403 for a non-admin.cd backend && pnpm testandcd frontend && pnpm test.Screenshots
Screenshots will be attached in a comment below: before (flat 20%), empty state, profit from entered costs, the Expenses field, the Cost per Unit field, and the item list showing a cost.