- Clone the repository and in the same folder use
npm i
to install the packages - Set up an environment variable with name
AdminEmail
for a specific email that can be used as an admin or super user. - In the terminal, type
nodemon start
to run the code.
- I assumed that there has to be an order management system to be made where Admin can add Services which are then ordered by customers.
- Customer/user will add services they choose to buy in a cart where they see their total amount and service selected names.
- Admin can see all orders and add new services that are to be offered.
- For testing i have used to Postman on my local system to validate the working.
- Nodejs
- Expressjs
- MongoDB
localhost:2000/register
withPOST
Request- Use this to register new users.
- Takes two fields
email
andpassword
localhost:2000/login
withPOST
Request- Use this to login a user
- Take two fields
email
andpassword
localhost:2000/service/addservice
withPOST
Request- Use this to add new services
- Takes three fields
name
,cost
andindex
- This is Admin specific feature. Use the same email for login as AdminEmail
localhost:2000/service/all
withGET
Request- Use this to view all the services currently present
localhost:2000/order/currentorder
withPOST
Request- Use this to make new order
- Takes one field
serviceIndices
as an array eg:[1,2,3]
where elements of this array are the service index for a specific service. - Returns order object
localhost:2000/order/update/:id
withPOST
Request- Use this to remove one service at a time from the current order
- Takes one field
serviceToRemove
with the service index to be removed. - Takes order id as paramater
localhost:2000/order/delete/:id
withDELETE
Request- Use this to remove the whole order
- Takes order id as paramater
localhost:2000/order/userOrders
withGET
Request- Returns the logged in user's orders
localhost:2000/order/all
withGET
Request- Returns orders from all users
- Can only be used by Admin with AdminEmail
- New user registers and logins which set a
user_id
in the cookie. user_id
is used to authenticate user implemented using middleware- User can see all services, create new order, see all of their orders, update order, and delete order.
- Admin can add new services and see all orders.
There are alot of impprovements that can be made and are necesarry as well. Here are a few:
- Login/register should have password authentication, email verification, password encryption.
- Instead of having just one Admin user we can have multiple role based users having access to specific data and routes.
- More CRUD operations in the Order section can be added that will be more useful
- Error handling can be more precise and easy
- User validation through middleware should be added to be fool proof