/restaurantAPI

A restaurant management API written in Express.js

Primary LanguageJavaScript

restaurantAPI

A restaurant management API in Express.js that uses MongoDB as a database and Redis as session store. A basic frontend is written in EJS.

API Reference

Schema Validations to endpoints are done using JOI

/restaurants

Prepend /restaurants to access the following routes

GET - /

Get info about all the restaurants, for an index page

POST - /

Add a restaurant.
Will add data only if a user registered as a restaurant admin is logged in.
This endpoint can be accessed only is the user logged in is a restaurant admin.

GET - /:rest_id

Get info about a specific restaurant.

PUT - /:rest_id

Update info about a specific restaurant.
Will append data only if the restaurant's admin is logged in.

DELETE - /:rest_id

Delete a specific restaurant.
Will delete data only if the restaurant's admin is logged in.

GET - /:rest_id/totalRevenue

Get info about a specific restaurant's revenue.
Will send a result only if the restaurant's admin in logged in.

POST - /:rest_id/items

Add an item to a restaurant.
Will add data only if a user registered as a restaurant admin is logged in.

DELETE - /:rest_id/items

Remove an item from a restaurant.
Will add data only if a user registered as a restaurant admin is logged in.

GET - /:rest_id/currentOrders

Get info about a specific restaurant's active orders.
Will send a result only if the restaurant's admin in logged in.

GET - /:rest_id/pastOrders

Get info about a specific restaurant's past orders.
Will send a result only if the restaurant's admin in logged in.

PUT - /:rest_id/order/:order_id

Update the status of an active order.
The status can only be update sequentially : Received -> Confirmed -> Cooking -> Done
Will send a result only if the restaurant's admin in logged in.

DELETE - /:rest_id/order/:order_id

Cancel an active order.
Upon cancellation, the order amount will be refunded to the customer.
Will delete data only if the restaurant's admin is logged in.


/user

Prepend /user to access the following routes

POST - /restaurantAdminLogin

Validates the provided credentials and logs the user in.

POST - /restaurantAdminSignup

Creates a new user and logs the user in.

GET - /restaurantAdminLogin/google

For Google OAuth using PassportJS.

POST - /clientLogin

Validates the provided credentials and logs the user in.

POST - /clientSignup

Creates a new user and logs the user in.

GET - /clientLogin/google

For Google OAuth using PassportJS.

GET - /clientDetails

Get basic info and cart items of the currently active user.
This endpoint can be accessed only is the user logged in is a client.

POST - /cart/:item_id

Add an item to the currently active user's cart. Items from multiple restaurants cannot be added to the same cart.
This endpoint can be accessed only is the user logged in is a client.

PUT - /cart/:item_id

Update quantity of an item in the currently active user's cart.
This endpoint can be accessed only is the user logged in is a client.

DELETE - /cart/:item_id

Delete an item from the currently active user's cart.
This endpoint can be accessed only is the user logged in is a client.

POST - /addFundsToWallet

Add funds to the currently active user's wallet.
This endpoint can be accessed only is the user logged in is a client.

GET - /placeOrder

Place an order for the items in the user's cart.
Will work only if the user's wallet funds are sufficient for the order.
This endpoint can be accessed only is the user logged in is a client.

GET - /currentOrders

Get info about the currently active orders of the currently active user.
This endpoint can be accessed only is the user logged in is a client.

GET - /pastOrders

Get info about the past orders of the currently active user.
This endpoint can be accessed only is the user logged in is a client.

GET - /order/:order_id

Get the current status of an active order.
Will send a response only if the user who made the order is logged in.
This endpoint can be accessed only is the user logged in is a client.

DELETE - /order/:order_id

Remove an active order.
This is possible only if the order's status is Received/Confirmed
Upon cancellation, the order amount will be refunded to the customer.
Will delete only if the user who made the order is logged in.

POST - /review/:rest_id

Add a review to a restaurant.
Will add a review only if the currently active user has at least one completed order from the restaurant.
This endpoint can be accessed only is the user logged in is a client.

DELETE - /review/:rest_id

Remove a review from a restaurant.
Will delete data only if the restaurant's admin is logged in.

GET - /logout

Logs the active user out.

Environment Variables

Add the following to your .env file.

PORT
COOKIE_EXPIRY_TIME
JWT_EXPIRY_TIME
JWT_SECRET_KEY
SESSION_SECRET_KEY
DATABASE_URL
GOOGLE_PASSPORT_ID
GOOGLE_PASSPORT_SECRET
GOOGLE_PASSPORT_CLIENT_CALLBACKURL
GOOGLE_PASSPORT_RESADMN_CALLBACKURL
MAIL_ID
MAIL_PASS
MONGO_INITDB_ROOT_USERNAME
MONGO_INITDB_ROOT_PASSWORD
MAIL_HOST

Postman

The workspace can be accessed in this public collection :
https://elements.getpostman.com/redirect?entityId=19312206-561647fd-c7d4-49d6-ab55-144e25662c2c&entityType=collection