Reject fractional affiliate sale amounts#206
Conversation
Greptile SummaryThis PR fixes fractional
Confidence Score: 5/5Safe to merge — the change narrows a validation gap and adds no new code paths that could break existing behavior. The changes are small and surgical: one new pure helper function, one tightened guard in POST, and one changed control-flow branch in PUT that now returns an error instead of silently dropping a field. All three changes are directly covered by new unit tests, including the commission recalculation path. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[PUT /conversions] --> B{Auth check}
B -- fail --> Z1[401 Unauthorized]
B -- pass --> C[Fetch offer by id]
C --> D{offer exists & seller owns it?}
D -- no --> Z2[403 Not authorized]
D -- yes --> E[Parse body: conversion_id, sale_amount_sats, note, status]
E --> F{conversion_id present?}
F -- no --> Z3[400 conversion_id required]
F -- yes --> G[Build updateData: note + status if valid]
G --> H{sale_amount_sats in body?}
H -- no --> K{updateData non-empty?}
H -- yes --> I{isPositiveIntegerSats?}
I -- false --> Z4[400 must be a positive integer]
I -- true --> J[Add sale_amount_sats + calculateCommission to updateData]
J --> K
K -- empty --> Z5[400 Nothing to update]
K -- non-empty --> L[DB update affiliate_conversions WHERE id AND offer_id]
L --> M{updateErr?}
M -- yes --> Z6[400 error message]
M -- no --> N[200 ok: true]
Reviews (1): Last reviewed commit: "Reject fractional affiliate sale amounts" | Re-trigger Greptile |
Fixes #139
Summary:
sale_amount_satswhen creating manual affiliate conversions.sale_amount_satson conversion updates instead of silently ignoring it.Tests:
npx vitest run "src/app/api/affiliates/offers/[id]/conversions/route.test.ts"npx vitest run src/app/api/affiliates src/lib/affiliatesnpx eslint "src/app/api/affiliates/offers/[id]/conversions/route.ts" "src/app/api/affiliates/offers/[id]/conversions/route.test.ts"Note:
npx tsc --noEmit --pretty falsecurrently reports existing type errors outside the affiliate conversions code path.