REST API for e-commerce marketplace
Tech Used: NodeJS, Postgres
Check list of available APIs here https://documenter.getpostman.com/view/3660544/2s8YzQX4NB
Postgres installation guide https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-20-04
Test coverage: Stmts 95.36 | Branch 75.67 | Funcs 100 | Lines 97.28
After cloning the project, install the packages:
npm install
Then, run the development server:
npm run dev
Run test cases npm t
Run tests and watch live changes npm run test:watch
We are using fake timer for tests. Also we have fresh DB after each test. These two are managed in global setup file setupTests.ts
.
Check for migrations knex migrate:list --env dev
(Available DB envs: dev
, prod
, test
)
Run all pending migrations knex migrate:latest --env dev
Rollback last migration knex migrate:rollback
- API response format
{ success: boolean, message: string, data?: Object, error?: string }
- Either
data
orerror
is must on API response.
- Either
- An user (means an unique email ID) can register as
buyer
orseller
. username
isn't unique at this moment.- User can sell products and also buy products. But for that need to register twice as different roles.
- Assuming the user won't buy from themselves. If
buyer.email == seller.email
, reject the order. - Don't have any separate Entity for
catalog
as we can only have one catalog per seller at a time. So keeping the list of products along withuser
entity to make it simple.- The downside is there are no DB-level check for whether the catalog products belong to the seller i.e the seller can sell products from other seller, or non-existent products. But there are checks at API controller level against that.
- For now no option to delete products. User can deactivate it.
- No API for completing order now, out of scope.