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

Implementation of view a Single Product Function #86

Merged
merged 1 commit into from
May 16, 2024

Conversation

maxCastro1
Copy link
Contributor

Description

This PR includes the implementation of the viewSingleProduct function in the Product service. The function is designed to fetch and return the details of a single product from the database.

Functionality

  • Function Definition: Defined the viewSingleProduct function which is an asynchronous function that takes in a request and response object.
  • Product ID Extraction: Extracted the product ID from the request parameters.
  • UUID Validation: Added a check to validate the UUID of the product before querying the database. This helps prevent errors when an invalid UUID is provided.
  • Database Query: Used the findOneBy method from the typeorm library to fetch the product from the database using the product ID.
  • Error Handling: Added error handling to return a 404 status code and error message when the product is not found, and a 500 status code and error message for other errors.
  • Product Expiration Check: Added a check for the product’s expiration date. If the product is expired, the function sends a response with the message ‘Product expired’.
  • Response: If the product is found and not expired, the function sends a 200 status code and the product data as a JSON response.

Test

Tests have been added to verify the new functionality:

  • A test to check if the endpoint correctly returns a single product.
  • A test to check if the endpoint correctly handles the case where the product does not exist.
  • A test to check if the endpoint correctly handles the case where the product is expired.

@coveralls
Copy link

coveralls commented May 16, 2024

Pull Request Test Coverage Report for Build 9111262881

Details

  • 19 of 22 (86.36%) changed or added relevant lines in 4 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.005%) to 81.484%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/services/productServices/viewSingleProduct.ts 15 18 83.33%
Files with Coverage Reduction New Missed Lines %
src/utils/roles.ts 1 50.0%
Totals Coverage Status
Change from base Build 9109943404: -0.005%
Covered Lines: 963
Relevant Lines: 1108

💛 - Coveralls

@maxCastro1 maxCastro1 added the Ready for reviews Pull request is ready for review label May 16, 2024
@maxCastro1 maxCastro1 added this to the Product Management milestone May 16, 2024
@maxCastro1 maxCastro1 linked an issue May 16, 2024 that may be closed by this pull request
14 tasks
Copy link
Collaborator

@faid-terence faid-terence left a comment

Choose a reason for hiding this comment

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

Nice Work @maxCastro1 !

@faid-terence faid-terence merged commit 5eb1e85 into develop May 16, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Good for newcomers Ready for reviews Pull request is ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feat: Buyer should be able to view a specific item
6 participants