Validate affiliate offer text update types#452
Conversation
Greptile SummaryThis PR fixes a crash-on-invalid-input bug in the affiliate offer PATCH handler. Before the change, sending a non-string value for
Confidence Score: 4/5Safe to merge — the validation guards are correct and narrowly scoped, and the tests exercise exactly the crash path being fixed. The two new guards are correct and follow the existing Lines 125–136 of Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[PATCH /api/affiliates/offers/id] --> B{Auth check}
B -- Unauthorized --> C[401]
B -- Authorized --> D{Ownership check}
D -- Not owner --> E[404]
D -- Owner --> F{body.title defined?}
F -- Yes --> G{typeof title === string?}
G -- No --> H[400 title must be a string]
G -- Yes --> I[updateData.title = title.trim]
F -- No --> J{body.description defined?}
I --> J
J -- Yes --> K{typeof description === string?}
K -- No --> L[400 description must be a string]
K -- Yes --> M[updateData.description = description.trim]
J -- No --> N{body.product_url defined?}
M --> N
N -- Yes --> O{product_url !== null AND not string?}
O -- Yes --> P[400 product_url must be a string]
O -- No --> Q{isValidUrl check}
Q -- Fails --> R[400 invalid scheme]
Q -- Passes --> S[updateData.product_url = url]
N -- No --> T[Apply remaining fields and DB update]
S --> T
T --> U{DB error?}
U -- Yes --> V[400 DB error]
U -- No --> W[200 offer]
|
|
CI is green for PR #452. Verification:
uGig invoice evidence has been sent for this PR. |
Fixes #451.
What changed
titlevalues before trimming.descriptionvalues before trimming.Validation
./node_modules/.bin/vitest.cmd run src/app/api/affiliates/offers/[id]/route.test.ts./node_modules/.bin/tsc.cmd --noEmit