Skip to content

Feature/stock management implementation #39

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

Merged

Conversation

BravarDev
Copy link
Contributor

🚀 StarShop Pull Request

Mark with an x all the checkboxes that apply (like [x])


📌 Type of Change

  • Documentation (updates to README, docs, or comments)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

📝 Changes description

I implemented two key functions in a service responsible for managing product variants' stock levels:

updateStockAfterPurchase(id: number, amount: number): Promise<ProductVariant | null>
  • Retrieves a ProductVariant by its ID.
  • Checks if the stock is sufficient for the purchase.
  • If the stock is insufficient, throws an error ("Insufficient stock").
  • If sufficient, decreases the stock by the purchased amount.
  • Saves the updated product variant and returns it.
restoreAfterOrderCanceled(id: number, amount: number): Promise<boolean>
  • Retrieves a ProductVariant by its ID.
  • If the product does not exist, returns false.
  • If found, restores the stock by adding the canceled order’s quantity.
  • Saves the updated product variant and returns true upon success.

Both functions ensure data consistency when managing product stock during purchases and order cancellations. Also I implement unit test for both functions in the productVariantService.spec.ts file, when running this test I had to fix some configurations in the assert functions but everything went fine.


📸 Evidence (A photo is required as evidence)

All tests succesfully approved
image


⏰ Time spent breakdown

It took me around 20 minutes to explore the project and understand the connections, also to see if the project was full NestJS or if it is configured to be in express.
Once adapted i invest like hour and a half to create the functions and then build the tests


🌌 Comments

The service is not conected to any controller, so in case of real testing, the api does not support product operations.

@Villarley
Copy link
Member

@BravarDev solve conflicts

@Villarley Villarley self-requested a review March 3, 2025 19:20
@Villarley
Copy link
Member

Villarley commented Mar 3, 2025

@BravarDev any updates?

@BravarDev
Copy link
Contributor Author

Sorry for the time, i will fix it.
I didn't see the message before

@Villarley
Copy link
Member

@BravarDev pls also solve conflicts

@BravarDev
Copy link
Contributor Author

Finished, check it out

Copy link
Member

Choose a reason for hiding this comment

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

delete this change, it's not necesary

Copy link
Member

Choose a reason for hiding this comment

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

delete this change, it's not necesary

Copy link
Member

Choose a reason for hiding this comment

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

delete this change, it's not necesary

Copy link
Member

Choose a reason for hiding this comment

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

delete this change, it's not necesary

Copy link
Member

Choose a reason for hiding this comment

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

delete this change, it's not necesary

Copy link
Member

Choose a reason for hiding this comment

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

delete this change, it's not necesary

Copy link
Member

Choose a reason for hiding this comment

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

delete this change, it's not necesary

Copy link
Member

Choose a reason for hiding this comment

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

delete this change, it's not necesary

@Villarley Villarley merged commit 4e54d7c into StarShopCr:main Mar 5, 2025
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.

[BK]: Implement Stock Management for Product Variants
2 participants