Route | Method | Parameters | Description | BL Explanation |
---|
/admin/orders | GET | - start: optional
- limit: optional
| This API lists all the orders made by the users, so the admin can manage them by confirming or rejecting each order | This API hits the orders collection to count its entries. If the count is >0, it proceeds to get the records and return them with the total number. The total number will be used for the pagination alongside the start and limit parameters |
/orders | GET | | This API lists all orders made by a logged in user, so he can check his previous orders | This API checks if the user id of the current session has the same id of the urac object then returns this user orders only |
/cart | GET | | This API lists all pets added by a user to an anonymous cart or a user cart. An anonymous cart is created if you are not logged in. | This API checks if there is a urac object, in other terms if someone is logged in. In case no urac object found, it checks for any records in the session and returns them with their count. The count is used to show the user that the cart isn't empty. In case of urac object, checks if the user id of the current session has the same id of the urac object then returns this user cart only |
/mergeCart | GET | | This API merges an anonymous cart saved in the session to the user who's logging in | This API checks for items in the session, in case of no items found it won't change anything. Else, it checks if the user id of the current session has the same id of the urac object. If they match, it checks if the user has items in his cart, if not it will enter all the records directly, else it checks if there is a common item so it will just modify the quantity ordered. |
/cart | POST | - userId: optional
- petId: required
- pet: required
| This API adds a pet to an anonymous or logged in user cart | This API checks if the user is logged in or not. If not, it adds the pet to the session object after checking if the pet doesn't exists in the cart, or it modifies the quantity ordered in case the pet exists. If the user is logged in, it checks if the user id of the current session has the same id of the urac object then it adds the pet to the orders collection after checking if the pet doesn't exists in the cart, or it modifies the quantity ordered in case the pet exists |
/cart/checkout/:id | POST | - userId: optional
- id: required
- petId: required
- quantity: required
- infos: required
| This API checks out all items in the cart for the logged in user, in case the user is logged in, he will be redirected to the login page | This API checks if there is a urac object, in other terms if someone is logged in then it checks if the user id of the current session has the same id of the urac object. If so, the quantity ordered of each item will get reduced from the pets collection using the petId and it adds the user infos to each record in the orders collection related to the logged in user |
/order/:id | POST | - id: required
- pickupDate: required
| This API confirms an order by changing it status to ready and adding a pickup date to the record | This API will update the pet status from pending to ready, add a pickup date to the record and finally send a mail to the client pointing that the order is confirmed with the pickup date from the store |
/cart/:id | DELETE | - id: required
- userId: optional
| This API deletes a pet from an anonymous or logged in user cart | This API checks if the user is logged in. If not, it will check the session and delete the item from the cart. Else, it checks if the user id of the current session has the same id of the urac object then deletes the item from the user cart |
/order/:id | DELETE | - id: required
- petId: required
| This API rejects an order of a client | This API gets the record of the rejected order then using the petId found in the record, it increments the quantity in stock by the quantity ordered in the pets collection. AT the end, it sends an email to the client saying that the order has been rejected |