This project implements a Grocery Booking API using Node.js and TypeScript. The API allows for the management and booking of grocery items. There are two roles: Admin and User. Admins can manage grocery items, including adding, updating, and removing items, as well as managing inventory levels. Users can view and book grocery items.
- Add new grocery items to the system.
- View existing grocery items.
- Remove grocery items from the system.
- Update details (e.g., name, price, inventory) of existing grocery items.
- Manage inventory levels of grocery items.
- View the list of available grocery items.
- Book multiple grocery items in a single order.
Ensure you have the following installed:
- Node.js
- npm (Node Package Manager)
- PostgreSQL
git clone https://github.com/SarveshK16/qp-assessment.git
cd qp-assessment
npm install
Create a .env
file in the root directory with the following content:
DB_USER=your_db_user
DB_HOST=your_db_host
DB_DATABASE=your_db_name
DB_PASSWORD=your_db_password
DB_PORT=5432
Ensure your PostgreSQL server is running and the database specified in the .env
file exists.
tsc -b
npm app.js
The server should now be running on http://localhost:3000
.
-
Add New Grocery Item
- Endpoint:
POST /admin/items
- Body:
{ "name": "Item Name", "price": 10.99, "inventory": 100 }
- Endpoint:
-
View Existing Grocery Items
- Endpoint:
GET /admin/items
- Endpoint:
-
Remove Grocery Item
- Endpoint:
DELETE /admin/items/:id
- Body:
{ "id": 1 }
- Endpoint:
-
Update Grocery Item Details
- Endpoint:
PUT /admin/items/:id
- Body:
{ "name": "Item Name", "price": 10.99, "inventory": 100 }
- Endpoint:
-
Update Inventory Levels
- Endpoint:
PATCH /admin/items/:id/inventory
- Body:
{ "id": 1, "inventory": 50 }
- Endpoint:
-
View Available Grocery Items
- Endpoint:
GET /user/items
- Endpoint:
-
Book Multiple Grocery Items
- Endpoint:
POST /user/orders
- Body:
{ "items": [ { "itemId": 1, "quantity": 2 }, { "itemId": 2, "quantity": 1 } ], "totalPrice": 34.97 }
- Endpoint:
This README provides an overview of the Grocery Booking API, setup instructions, and examples of how to use the API endpoints. Follow these instructions to get the API up and running on your local machine. If you encounter any issues, refer to the project's source code for further details.