Skip to content

Conversation

@knoid
Copy link
Contributor

@knoid knoid commented Jul 31, 2025

Description

Function getStockMovementsByProductVariantId accepts a type filter but was not really filtering by that field. This PR adds that condition when the type filter is requested.

Breaking changes

Does this PR include any breaking changes we should be aware of? No.

Screenshots

You can add screenshots here if applicable.

Checklist

📌 Always:

  • I have set a clear title
  • My PR is small and contains a single feature
  • I have checked my own PR

👍 Most of the time:

  • I have added or updated test cases
  • I have updated the README if needed

Summary by CodeRabbit

  • New Features

    • GraphQL support to fetch stock movements filtered by type, enabling per-variant, per-type stock movement views.
  • Refactor

    • Simplified internal query building for stock movement retrieval for more reliable and clearer results.
  • Tests

    • End-to-end tests added to validate type-based filtering and aggregated results.

@vercel
Copy link

vercel bot commented Jul 31, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Project Deployment Preview Updated (UTC)
docs Ready Preview Aug 12, 2025 2:15am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 31, 2025

Warning

Rate limit exceeded

@knoid has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 6 minutes and 18 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 43349ff and 6c48a55.

📒 Files selected for processing (4)
  • packages/core/e2e/graphql/generated-e2e-admin-types.ts (2 hunks)
  • packages/core/e2e/graphql/shared-definitions.ts (1 hunks)
  • packages/core/e2e/stock-control.e2e-spec.ts (3 hunks)
  • packages/core/src/service/services/stock-movement.service.ts (1 hunks)

Walkthrough

Made the options parameter optional in getStockMovementsByProductVariantId, introduced a local query builder qb with a conditional stockmovement.type filter, simplified the query result return, and added a GraphQL query plus an e2e test to request stockMovements filtered by type.

Changes

Cohort / File(s) Change Summary
Stock Movement Service Update
packages/core/src/service/services/stock-movement.service.ts
Made options optional on getStockMovementsByProductVariantId, introduced local qb query builder, added conditional stockmovement.type filter, and returned { items, totalItems } from getManyAndCount().
GraphQL Query Added
packages/core/e2e/graphql/shared-definitions.ts
Added GET_STOCK_MOVEMENT_BY_TYPE GraphQL query to fetch product variant stockMovements with options: { type: $type }.
End-to-end Test Added
packages/core/e2e/stock-control.e2e-spec.ts
Added e2e test that uses GET_STOCK_MOVEMENT_BY_TYPE to verify per-variant stockMovements filtered by ALLOCATION and validates quantities; added helper getProductWithStockMovementByType.

Sequence Diagram(s)

sequenceDiagram
  participant Client as GraphQL Client
  participant API as GraphQL Resolver
  participant Service as StockMovementService
  participant DB as Database

  Client->>API: query GetStockMovementByType(id, type)
  API->>Service: getStockMovementsByProductVariantId(ctx, variantId, { type })
  Service->>DB: build query (WHERE productVariantId = ... [AND type = ...])
  DB-->>Service: rows, count
  Service-->>API: { items, totalItems }
  API-->>Client: GraphQL response
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/core/e2e/stock-control.e2e-spec.ts (2)

24-24: Use CreateAddressInput from shop codegen to match the mutation’s variable types

You’re casting inputs for SET_SHIPPING_ADDRESS to CreateAddressInput, but importing the type from the admin codegen. It works due to structural typing, but it’s confusing and easy to mix up. Prefer importing CreateAddressInput from the shop codegen to match the mutation.

Apply this diff to adjust the imports:

-import {
-    ErrorCode as AdminErrorCode,
-    CreateAddressInput,
-    FulfillmentFragment,
-    GlobalFlag,
-    StockMovementType,
-    UpdateProductVariantInput,
-    VariantWithStockFragment,
-} from './graphql/generated-e2e-admin-types';
+import {
+    ErrorCode as AdminErrorCode,
+    FulfillmentFragment,
+    GlobalFlag,
+    StockMovementType,
+    UpdateProductVariantInput,
+    VariantWithStockFragment,
+} from './graphql/generated-e2e-admin-types';

And include CreateAddressInput in the shop types import:

-import { ErrorCode, PaymentInput } from './graphql/generated-e2e-shop-types';
+import { CreateAddressInput, ErrorCode, PaymentInput } from './graphql/generated-e2e-shop-types';

357-373: Rename test description to reflect ALLOCATION filter

The test asserts ALLOCATION movements, not sales. Rename for clarity.

Apply this diff:

-it('returns all sales', async () => {
+it('returns allocations filtered by type', async () => {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between be419e2 and 2701c4c.

📒 Files selected for processing (3)
  • packages/core/e2e/graphql/shared-definitions.ts (1 hunks)
  • packages/core/e2e/stock-control.e2e-spec.ts (4 hunks)
  • packages/core/src/service/services/stock-movement.service.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/core/src/service/services/stock-movement.service.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/core/e2e/stock-control.e2e-spec.ts (2)
packages/core/e2e/graphql/generated-e2e-admin-types.ts (2)
  • GetStockMovementByTypeQuery (9679-9696)
  • GetStockMovementByTypeQueryVariables (9674-9677)
packages/core/e2e/graphql/shared-definitions.ts (1)
  • GET_STOCK_MOVEMENT_BY_TYPE (297-315)
🔇 Additional comments (4)
packages/core/e2e/graphql/shared-definitions.ts (1)

296-315: New typed query for per-type stock movements looks correct

The GraphQL query is well-formed, uses the StockMovement interface fragment appropriately, and scopes the filter to the stockMovements field via options: { type: $type }. Export and naming are consistent with existing patterns.

packages/core/e2e/stock-control.e2e-spec.ts (3)

17-17: Import additions/reorganization look good

The added imports (TEST_SETUP_TIMEOUT_MS, Codegen namespace, shop types, and GET_STOCK_MOVEMENT_BY_TYPE) align with the new helper/test usage.

Also applies to: 21-21, 32-32, 38-38


115-121: Helper for type-filtered stock movements is clear and typed

The helper cleanly mirrors the existing getProductWithStockMovement and correctly wires Codegen types with the new GET_STOCK_MOVEMENT_BY_TYPE query.


1246-1248: Non-functional formatting change

The reformatting of the activeOrder query is fine and has no functional impact.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
packages/core/e2e/stock-control.e2e-spec.ts (3)

21-25: Use CreateAddressInput from shop types for consistency

The CreateAddressInput is used in shop API calls (SetShippingAddress). Importing it from admin types works due to structural typing, but it’s confusing and couples a shop concern to admin types. Prefer importing from the shop-generated types.

Apply these diffs to align imports:

- import {
-     ErrorCode as AdminErrorCode,
-     CreateAddressInput,
-     FulfillmentFragment,
-     GlobalFlag,
-     StockMovementType,
-     UpdateProductVariantInput,
-     VariantWithStockFragment,
- } from './graphql/generated-e2e-admin-types';
+ import {
+     ErrorCode as AdminErrorCode,
+     FulfillmentFragment,
+     GlobalFlag,
+     StockMovementType,
+     UpdateProductVariantInput,
+     VariantWithStockFragment,
+ } from './graphql/generated-e2e-admin-types';

And update the shop types import (see lines 32-33).


32-33: Co-locate CreateAddressInput with shop types

Follow-up to the previous comment: import CreateAddressInput from the shop types to match its usage locations.

-import { ErrorCode, PaymentInput } from './graphql/generated-e2e-shop-types';
+import { CreateAddressInput, ErrorCode, PaymentInput } from './graphql/generated-e2e-shop-types';

357-373: Rename test: it asserts ALLOCATIONs, not Sales

The test name says “returns all sales” but it filters for StockMovementType.ALLOCATION and asserts allocations. Rename to avoid confusion and future maintenance mistakes.

-        it('returns all sales', async () => {
+        it('returns allocations when filtered by type', async () => {

Optional: Consider adding a follow-up test after “creates a Sale on Fulfillment creation” that filters by StockMovementType.SALE to validate filtering across multiple types (SALE, RELEASE, CANCELLATION) and strengthen coverage.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2701c4c and 43349ff.

📒 Files selected for processing (3)
  • packages/core/e2e/graphql/shared-definitions.ts (1 hunks)
  • packages/core/e2e/stock-control.e2e-spec.ts (4 hunks)
  • packages/core/src/service/services/stock-movement.service.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/core/src/service/services/stock-movement.service.ts
  • packages/core/e2e/graphql/shared-definitions.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/core/e2e/stock-control.e2e-spec.ts (1)
packages/core/e2e/graphql/shared-definitions.ts (1)
  • GET_STOCK_MOVEMENT_BY_TYPE (316-334)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: codegen / codegen
  • GitHub Check: e2e tests (22.x, postgres)
  • GitHub Check: e2e tests (22.x, sqljs)
  • GitHub Check: e2e tests (24.x, mariadb)
  • GitHub Check: e2e tests (22.x, mariadb)
  • GitHub Check: e2e tests (20.x, mysql)
  • GitHub Check: e2e tests (20.x, sqljs)
  • GitHub Check: build (24.x)
  • GitHub Check: e2e tests (20.x, mariadb)
  • GitHub Check: build (20.x)
  • GitHub Check: unit tests (24.x)
  • GitHub Check: publish_install (macos-latest, 24.x)
  • GitHub Check: publish_install (macos-latest, 20.x)
  • GitHub Check: publish_install (windows-latest, 22.x)
  • GitHub Check: publish_install (windows-latest, 20.x)
  • GitHub Check: publish_install (ubuntu-latest, 20.x)
  • GitHub Check: publish_install (windows-latest, 24.x)
  • GitHub Check: publish_install (macos-latest, 22.x)
  • GitHub Check: publish_install (ubuntu-latest, 24.x)
  • GitHub Check: publish_install (ubuntu-latest, 22.x)
🔇 Additional comments (4)
packages/core/e2e/stock-control.e2e-spec.ts (4)

17-17: LGTM: import usage is correct

TEST_SETUP_TIMEOUT_MS and testConfig() are both used and consistent with the test environment setup.


38-39: LGTM: new query import

GET_STOCK_MOVEMENT_BY_TYPE import is correct and used by the new e2e test.


115-121: LGTM: helper for type-filtered stock movements

Helper correctly queries the Admin API using the new GraphQL operation and typed variables. Straightforward and reusable.


1246-1248: LGTM: minor formatting

Formatting-only change; no functional impact.

@knoid knoid force-pushed the stockMovement-type branch from 9315d4b to 6c48a55 Compare August 12, 2025 02:14
@sonarqubecloud
Copy link

@dlhck dlhck merged commit 99907fc into vendure-ecommerce:master Aug 12, 2025
51 of 52 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Aug 12, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants