-
Notifications
You must be signed in to change notification settings - Fork 58
Conversation
Hi, @BiswajitSahoo-tech Could you also check with the frontend and add an appropriate video or a screenshot? |
Ok @roopeshsn, Got it |
Hi @roopeshsn,
Actually initially there is 5 kg carrot in stock and user ordered 5 kg carrots, therefore after payment we have carrot out of stock |
@roopeshsn, Please have a look. |
Hi @BiswajitSahoo-tech Could you remove that .env.sample file and all its imports? We have .env in the root. Also, the code is not formatted. There is a prettier command to format the recursively check the package.json file. |
Hi @roopeshsn, |
package.json
Outdated
@@ -40,6 +40,7 @@ | |||
"mongoose": "^6.4.6", | |||
"multer": "^1.4.3", | |||
"nodemailer": "^6.6.5" | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You haven't added any packages in the package.json file right then why you have committed the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@roopeshsn I removed it, check it now please
} | ||
product.countInStock -= qty | ||
const updatedProduct = await product.save() | ||
return updateProduct |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain why this line is added?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return updateProduct
this line?
This is added such that the updated product will be in the resolved result of all promises that we awaiting in orderController.
But there is no requirement for this result, we can omit this.
Good work @BiswajitSahoo-tech Let me know if you're interested to become a collaborator for this project. |
Thanks, @roopeshsn, for giving me this opportunity. |
The work of a maintainer or owner of a project. Collaborator will raise issues for a feature or a bug, review and merge PRs. In short, Collaborator will work for the improvement of the project. |
Sorry, @roopeshsn, we have a term exam scheduled next week so, I don't think I can contribute much as a collaborator. Thank you very much for the offer. |
Fixes [ #55 ]
Hi @roopeshsn,
I have added inventory management, below is a brief of my solution:
First created a
updateStockCount
function onbackend/controller/productController/
few notes on the
updateStockCount
function and how it handles the edge casesvar product = await Product.findById(id)
- find the product by id passed as argumentOrderItem
corresponding to the given order.
Add the following code in
updateOrderToPaid
function underbackend/controller/orderController/
catch(err)
will catch the error thrown byupdateStockCount
and immediately send a response to the client havingan appropriate message of what actually happens also ends the request-response cycle such that in the case of a catch
there will be no update on these fields.
isPaid
andpaidAt
- these fields are updated only when all the promises atupdatePromises
will be resolved successfully.The above code will execute only when all the promises at
updatePromises
will be resolved successfully.I have tested the feature using Postman and it is working as expected.
No other breaking changes are made to the system
Thank You ❤️