Skip to content

Reject fractional affiliate sale amounts#206

Merged
ralyodio merged 1 commit into
profullstack:masterfrom
keeze12:codex/fix-affiliate-fractional-sats
May 23, 2026
Merged

Reject fractional affiliate sale amounts#206
ralyodio merged 1 commit into
profullstack:masterfrom
keeze12:codex/fix-affiliate-fractional-sats

Conversation

@keeze12
Copy link
Copy Markdown
Contributor

@keeze12 keeze12 commented May 21, 2026

Fixes #139

Summary:

  • Reject fractional/non-integer sale_amount_sats when creating manual affiliate conversions.
  • Reject invalid sale_amount_sats on conversion updates instead of silently ignoring it.
  • Add regression coverage for fractional create/update requests and integer update commission recalculation.

Tests:

  • npx vitest run "src/app/api/affiliates/offers/[id]/conversions/route.test.ts"
  • npx vitest run src/app/api/affiliates src/lib/affiliates
  • npx 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 false currently reports existing type errors outside the affiliate conversions code path.

@ralyodio ralyodio closed this May 23, 2026
@ralyodio ralyodio reopened this May 23, 2026
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 23, 2026

Greptile Summary

This PR fixes fractional sale_amount_sats handling for affiliate conversion endpoints: POST now rejects non-integer values via a new isPositiveIntegerSats helper, and PUT no longer silently ignores an invalid sale_amount_sats — it returns a 400 instead.

  • POST validation tightened: replaces the ad-hoc numeric guard with isPositiveIntegerSats, closing the gap that allowed values like 100.5 to pass through to recordConversion.
  • PUT validation made explicit: wraps the sale_amount_sats branch with Object.prototype.hasOwnProperty.call(body, \"sale_amount_sats\") so the field is only validated when the caller actually provided it, then rejects fractional values instead of silently dropping them.
  • Tests added: fractional-create rejection, fractional-update rejection, and integer-update commission recalculation are all covered.

Confidence Score: 5/5

Safe 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

Filename Overview
src/app/api/affiliates/offers/[id]/conversions/route.ts Adds isPositiveIntegerSats helper to reject fractional sale_amount_sats in POST, and changes the PUT handler from silently dropping invalid sale_amount_sats to explicitly returning 400; also removes the eslint-disable-next-line comment above the AnySupabase type alias.
src/app/api/affiliates/offers/[id]/conversions/route.test.ts Expands test coverage: adds PUT import and mock for calculateCommission, introduces makePutRequest helper, adds fractional-create and fractional-update rejection tests, and a full integer-update test that verifies commission recalculation.

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]
Loading

Reviews (1): Last reviewed commit: "Reject fractional affiliate sale amounts" | Re-trigger Greptile

@ralyodio ralyodio merged commit b35a77c into profullstack:master May 23, 2026
4 checks passed
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.

bug: affiliate conversions accept fractional sat amounts

2 participants