feat(graphql): add SalesModule with configurable commission & points (GraphQL + Prisma)#2
Conversation
✅ Deploy Preview for api-da-jc ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 10688d8690
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| throw new BadRequestException('Produto inválido para a venda.'); | ||
| } | ||
|
|
||
| const totalPrice = product.unitPrice * item.quantity; |
There was a problem hiding this comment.
Validate sale item quantity before calculating totals
The use case never enforces quantity > 0, so a request with zero or negative quantities flows through as a valid sale. Because totalPrice is computed directly from item.quantity, negative quantities produce negative sale totals and then addPerformance applies negative commission/points to the seller, which corrupts accumulated performance data through a normal mutation path.
Useful? React with 👍 / 👎.
| const products = | ||
| await this.salesProductRepository.findManyByIds(productIds); | ||
|
|
||
| if (products.length !== productIds.length) { |
There was a problem hiding this comment.
Compare product lookup against unique IDs
This check rejects requests when the same productId appears more than once in items. findManyByIds queries with an IN clause and returns each matching product once, so duplicate IDs make products.length smaller than productIds.length even though all products exist, causing a false "not found" error for otherwise valid inputs.
Useful? React with 👍 / 👎.
Motivation
Description
SalesModulewired intoAppModulethat composes GraphQL resolver, use-cases, commission services and Prisma repositories.createSeller,sellers,createSalesProduct,salesProducts,registerSale,sales,updateCommissionConfigurationandcommissionConfiguration.CreateSellerUseCase,CreateSalesProductUseCase,RegisterSaleUseCase,List*UseCase) delegating business logic toCommissionPolicyService.CommissionPolicyServicewith strategy interfacesCommissionCalculatorandPointsCalculatorand default implementationsPercentageCommissionCalculatorandRevenuePointsCalculator.SellerRepository,SalesProductRepository,SaleRepository,CommissionRuleRepository) and Prisma implementations that map domain entities to DB models.prisma/schema.prismaand includes a SQL migrationprisma/migrations/20260401000000_add_sales_management/migration.sqlto create enums/tables/indices/constraints.src/modules/sales/README.mdand provides a mutation example to change commission config without touching business code.Testing
npm run type-check; the run failed due to pre-existing Prisma Client typing issues in the repository and other legacy type errors, so a full compile could not be validated.npx prisma ...which failed in the current environment because theprismabinary is not available, so client generation could not be completed here.prettierwas applied andeslintwas executed, which surfaced lint warnings/errors that were addressed where possible, with linting reporting remaining issues related to the wider repo typings.Codex Task