Skip to content

feat(graphql): add SalesModule with configurable commission & points (GraphQL + Prisma)#2

Open
Joaoof wants to merge 1 commit into
masterfrom
codex/implement-seller-and-product-management-system
Open

feat(graphql): add SalesModule with configurable commission & points (GraphQL + Prisma)#2
Joaoof wants to merge 1 commit into
masterfrom
codex/implement-seller-and-product-management-system

Conversation

@Joaoof

@Joaoof Joaoof commented Apr 1, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Add a full sales management feature (sellers, products, sales) exposed via GraphQL following the existing layered architecture to keep resolvers thin and business rules centralized.
  • Centralize commission and points calculation in a configurable service to allow future strategies (by product, category, seller, progressive tiers) without touching resolvers or use-cases.
  • Provide persistence-ready Prisma models and a migration to persist sellers, catalog products, sales, sale items and commission configuration.

Description

  • Introduces a new SalesModule wired into AppModule that composes GraphQL resolver, use-cases, commission services and Prisma repositories.
  • Adds GraphQL schema artifacts: DTOs and Inputs for sellers, sales products, sale items, sales and commission configuration plus resolver operations createSeller, sellers, createSalesProduct, salesProducts, registerSale, sales, updateCommissionConfiguration and commissionConfiguration.
  • Implements application layer use-cases (CreateSellerUseCase, CreateSalesProductUseCase, RegisterSaleUseCase, List*UseCase) delegating business logic to CommissionPolicyService.
  • Centralizes commission and points logic via CommissionPolicyService with strategy interfaces CommissionCalculator and PointsCalculator and default implementations PercentageCommissionCalculator and RevenuePointsCalculator.
  • Adds persistence contracts (SellerRepository, SalesProductRepository, SaleRepository, CommissionRuleRepository) and Prisma implementations that map domain entities to DB models.
  • Updates prisma/schema.prisma and includes a SQL migration prisma/migrations/20260401000000_add_sales_management/migration.sql to create enums/tables/indices/constraints.
  • Documents organization, usage and evolution strategy in src/modules/sales/README.md and provides a mutation example to change commission config without touching business code.

Testing

  • Ran type-check with 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.
  • Attempted Prisma tasks with npx prisma ... which failed in the current environment because the prisma binary is not available, so client generation could not be completed here.
  • Ran lint/format tooling; prettier was applied and eslint was executed, which surfaced lint warnings/errors that were addressed where possible, with linting reporting remaining issues related to the wider repo typings.
  • No unit or integration test suites were executed as part of this PR.

Codex Task

@netlify

netlify Bot commented Apr 1, 2026

Copy link
Copy Markdown

Deploy Preview for api-da-jc ready!

Name Link
🔨 Latest commit 10688d8
🔍 Latest deploy log https://app.netlify.com/projects/api-da-jc/deploys/69cd4aa406e9230008a4eb3d
😎 Deploy Preview https://deploy-preview-2--api-da-jc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant