Skip to content
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

Pos sale status #5038

Merged
merged 4 commits into from Mar 11, 2024
Merged

Pos sale status #5038

merged 4 commits into from Mar 11, 2024

Conversation

KhBaterdene
Copy link
Collaborator

No description provided.

Copy link

sonarcloud bot commented Feb 29, 2024

Quality Gate Passed Quality Gate passed

Issues
1 New issue
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

PR Type: Enhancement

PR Summary: This pull request introduces the concept of sale status within the POS client API, allowing for orders to be marked with specific sale statuses such as 'CART' or 'CONFIRMED'. It includes updates to GraphQL resolvers, schema definitions, and the addition of a new mutation for changing the sale status of an order. The changes span across multiple files, including mutations, queries, schema definitions, and constants, ensuring that the new sale status functionality is integrated throughout the system.

Decision: Comment

📝 Type: 'Enhancement' - not supported yet.
  • Sourcery currently only approves 'Typo fix' PRs.
✅ Issue addressed: this change correctly addresses the issue or implements the desired feature.
No details provided.
✅ Small diff: the diff is small enough to approve with confidence.
No details provided.

General suggestions:

  • Consider future-proofing the getSaleStatus function to easily accommodate additional sale statuses as the application evolves.
  • Ensure consistency in the handling and representation of sale statuses across different parts of the application to maintain code clarity and ease of maintenance.
  • Review the naming conventions used for the new constants and functions to ensure they are intuitive and consistent with existing patterns within the project.
packages/plugin-posclient-api/src/graphql/resolvers/mutations/orders.ts: Consider centralizing sale status logic to reduce complexity and improve maintainability.

The recent changes introduce additional complexity, primarily due to the introduction of ORDER_SALE_STATUS and its associated logic spread across multiple parts of the codebase. While the intent to manage sale statuses more granularly is clear, the current approach increases the cognitive load for developers by adding more conditional logic and spreading related logic across various functions.

A potential way to simplify this would be to encapsulate the sale status logic within a smaller number of functions or classes. This could help in centralizing the logic related to sale statuses, making the code easier to maintain and understand. For example, creating a class like OrderStatusManager that handles all sale status updates and validations could reduce the need for scattered logic and checks throughout the codebase.

Here's a simplified example of how this could look:

class OrderStatusManager {
  constructor(order) {
    this.order = order;
  }

  updateSaleStatus(newStatus) {
    if (this.isValidSaleStatus(newStatus)) {
      this.order.saleStatus = newStatus;
      this.order.save(); // Assuming a method to persist changes.
    }
  }

  isValidSaleStatus(status) {
    return [ORDER_SALE_STATUS.CONFIRMED, ORDER_SALE_STATUS.CART].includes(status);
  }
}

Usage of such a class would centralize the handling of sale statuses, potentially making the system easier to extend and maintain. This is just a suggestion and might need adjustments to fit into the existing architecture, but the principle of centralizing related logic could be beneficial in managing complexity.

packages/plugin-posclient-api/src/models/definitions/constants.ts: The code change maintains consistency with existing patterns, not increasing complexity and aligning well with the current structure.

After reviewing the changes, it appears that the introduction of ORDER_SALE_STATUS follows the existing pattern used for constants like ORDER_STATUSES and ORDER_ITEM_STATUSES. This consistency in structuring constants is beneficial for maintainability and understanding, as it leverages a familiar pattern for developers working within this codebase. The change does not significantly increase the complexity of the code. It's clear that the approach taken aligns well with the current code structure, ensuring that new and existing developers can easily grasp and work with these constants.

packages/plugin-posclient-api/src/models/definitions/orders.ts: The code change is justified and maintains clarity, introducing necessary complexity for new functionality in a structured manner.

The recent changes introduce a new saleStatus field to both the IOrder interface and the schema, along with importing ORDER_SALE_STATUS from ./constants. While these modifications do increase the code's complexity, it's a justified and necessary addition to support the new functionality of tracking the sale status of an order. Each change is directly related to implementing this feature and follows best practices for extending functionality within a MongoDB/Mongoose context, such as using enums for validation and indexing new fields for performance.

Adding a new field to the interface and schema is a common practice when new features or requirements are introduced, and the way you've handled it—by specifying type, label, enum, default value, and indexing—is clear and maintainable. It's important for new code to remain as understandable and manageable as possible, and your changes adhere to this principle.

As we continue to extend our models and schemas, let's ensure we maintain this level of clarity and purpose in our changes, keeping in mind the balance between necessary complexity for new features and overall code maintainability. Great job on implementing this new feature in a clean and structured way.

Thanks for using Sourcery. We offer it for free for open source projects and would be very grateful if you could help us grow. If you like it, would you consider sharing Sourcery on your favourite social media? ✨

Share Sourcery

Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

Comment on lines +128 to +136
export const getSaleStatus = (config, doc, order) => {
if (order.saleStatus) {
if (order.saleStatus === ORDER_SALE_STATUS.CONFIRMED) {
return ORDER_SALE_STATUS.CONFIRMED;
}
return ORDER_SALE_STATUS.CART;
}
return ORDER_SALE_STATUS.CART;
};
Copy link

Choose a reason for hiding this comment

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

suggestion (llm): The getSaleStatus function implementation is straightforward and aligns well with the existing pattern of status determination functions. However, it might be beneficial to consider if there are more states that saleStatus could take in the future and if this function's design will accommodate such changes without significant modifications.

@munkhsaikhan munkhsaikhan merged commit 561cda0 into dev Mar 11, 2024
3 of 4 checks passed
@munkhsaikhan munkhsaikhan deleted the pos-sale-status branch March 11, 2024 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants