-
Notifications
You must be signed in to change notification settings - Fork 0
feat: new affiliate collection #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements a new affiliate collection and API endpoints to support the affiliate code creation flow. The implementation includes schema definition, API routes, controllers, services, validation logic, and configuration for default affiliate program parameters.
Changes:
- Added new
/affiliatesAPI endpoints with full CRUD operations - Implemented affiliate lifecycle hooks with validation for code format, wallet addresses, and program parameters
- Added configuration support for affiliate program defaults via environment variables
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| src/gen/types.ts | Generated TypeScript types for affiliate and restricted token list API endpoints |
| src/api/affiliate/services/affiliate.ts | Strapi service factory for affiliate collection |
| src/api/affiliate/routes/affiliate.ts | Strapi router factory for affiliate endpoints |
| src/api/affiliate/documentation/1.0.0/affiliate.json | OpenAPI documentation for affiliate endpoints |
| src/api/affiliate/controllers/affiliate.ts | Strapi controller factory for affiliate operations |
| src/api/affiliate/content-types/affiliate/schema.json | Database schema defining affiliate collection structure |
| src/api/affiliate/content-types/affiliate/lifecycles.ts | Lifecycle hooks with validation logic for affiliate creation and updates |
| config/affiliate.ts | Configuration file for affiliate program default parameters |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]>
alfetopito
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just one comment regarding the code length.
Additionally, can you improve the description a bit, with some screenshots and explanation of the feature?
| @@ -0,0 +1,195 @@ | |||
| import { errors } from "@strapi/utils"; | |||
|
|
|||
| const CODE_REGEX = /^[A-Z0-9_-]{6,12}$/; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to limit code to 6-12 chars?
Lower bound of 6 is ok I guess, but we could probably accept longer codes IMO. How about 20 or 30 char limit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
| const hasOwn = (obj: object, key: string) => | ||
| Object.prototype.hasOwnProperty.call(obj, key); | ||
|
|
||
| const normalizeWallet = (value?: string | null) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't normalizeWallet and normalizeCode the same?
If you want to keep both for semantics reason, you can do:
const normalizeCode = normalizeWallet
| ); | ||
| const dao = parseNumber(params.revenueSplitDaoPct, "revenueSplitDaoPct"); | ||
|
|
||
| if (affiliate > 100 || trader > 100 || dao > 100) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be great to avoid using magic number and move them to consts
shoom3301
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of code style nitpicks

Summary
Implements https://linear.app/cowswap/issue/COW-142/implement-affiliate-code-creation-flow
and https://linear.app/cowswap/issue/COW-147/adjustable-program-parameters
Adds a new collection called
affiliate, when you create codes through the admin UI in Strapi CMS the empty fields are filled with our preset defaults on save. Additionally you can enable or disable a code.Security: we must make sure the collection is not readable without an api key. Reads and writes by the FE will be done via a BFF service.
Testing
nvm use 20yarn devThe reason for this is to make the accounting simpler, for new params new codes must be created.