- Table of Contents
- Application is deployed on Heroku for ease of use
- Application documentation built with Swagger UI
-
Overall project architecture utilises a component style architecture, where each individual component consists of three parts:
-
Controller - Controls routing endpoints and which service paths to route API call to
-
Model - Consists of all the models required for an individual component
-
Service - Consists of all the business logic and communication with the database
-
-
CRUD operations
- Create inventory items
- POST to
/inventory/
with item in request body to create a new item - create function
- POST to
- Edit
- PATCH to
/inventory/{itemId}
with item in request body to update item - edit function
- PATCH to
- Delete
- DELETE to
/inventory/{itemId}
with adeleteReason
that can be specified in the request body - delete function
- DELETE to
- View a list of them
- GET to
/inventory/
to get all items - getItems function
- GET to
- Create inventory items
-
Extra feature chosen:
- When deleting, allow deletion comments and undeletion
- Undo
- PATCH to
/inventory/undo-delete
to undo last delete event - undo function
- PATCH to
- Getting history
- GET to
/inventory/deleted
to get deletion history - getDeleteEvents function
- GET to
- Undo
- When deleting, allow deletion comments and undeletion
- Each delete is an event inserted into the
delete-events
collection- Deletion occurs by setting a
deleted
boolean in an Item totrue
GET /inventory/
endpoint queries the database only for documents withdeleted
set tofalse
- By setting
deleted
totrue
, these documents will not be retrieved
- Documents can be cleaned up on a monthly schedule, i.e. daily cron job to clean up documents which have deleted flag set to
true
for over a month
- Deletion occurs by setting a
- Undo is simply getting the most recent delete event, deleting the event from the
delete-events
collection and settingdeleted
boolean of corresponding item with id specified to befalse
- Setting up locally consists of two steps,
- A. Setting up Database
- B. Setting up Express Application
- Please follow instructions on MongoDB Install to install MongoDB on your local environment, MongoDB is required to run the application
-
Install
nvm
node version manager to install node js and npm, instructions here -
Install node v15.11.0 with nvm
nvm install 15.11.0
- Use node v15.11.0 in nvm
nvm use 15.11.0
- Install yarn globally with npm
sudo npm i -g yarn
- Install dependencies with yarn
yarn
- Starting dev server
yarn dev
- App docs endpoint
http://localhost:3000/docs/
for Swagger UI playground and API documentation
- Item Schema
interface Item {
name: String,
description: String,
quanity: Number,
deleted: Boolean // if deleted is true, item will not show up in get all items endpoint
}
- Delete Event Schema
interface DeleteEvent {
itemId: String, // _id of Item that has been deleted
reason: String // Reason specified for Item deletion
}