DAF backend coding task.
1️⃣ The applicaiton is unit and integration tested using jasmine
2️⃣ The application is built on top of NodeJs
, Express
, and PostgreSQL
, I've not used any ORM, it's a pure raw sql.
:three: Login/Signup are using JWT authentication
📦src
┣ 📂controllers
┃ ┣ 📜auth.controller.js
┃ ┣ 📜order.controller.js
┃ ┗ 📜product.controller.js
┣ 📂database
┃ ┗ 📜database.init.js
┣ 📂middlewares
┃ ┣ 📜auth.js
┃ ┗ 📜jwt.js
┣ 📂models
┃ ┣ 📜Order.model.js
┃ ┣ 📜Product.model.js
┃ ┗ 📜User.model.js
┣ 📂routes
┃ ┣ 📜auth.routes.js
┃ ┣ 📜order.routes.js
┃ ┣ 📜product.routes.js
┃ ┗ 📜user.routes.js
┣ 📂utils
┣ 📜app.js
┗ 📜index.js
method | endpoint | action | params |
---|---|---|---|
POST | /auth/signup | signup user | - |
POST | /auth/login | login user | - |
method | endpoint | action | params | query params |
---|---|---|---|---|
POST | /orders/create | create new order | - | - |
POST | /orders/:orderId/products/:productId | add product to an order | orderId, productId | - |
GET | /orders/users/:userId/ | get user's orders | userId | - |
PUT | /orders/:orderId/ | change order status | orderId | status |
method | endpoint | action | params | query params |
---|---|---|---|---|
POST | /products/create | create new product | - | - |
Install the project dependencies
npm install
- creating user
CREATE USER daf_user WITH PASSWORD 'password123';
- create both development and testing db
CREATE DATABASE daf;
CREATE DATABASE daf_test;
- grant all privileges on both databases
\c daf;
GRANT ALL PRIVILEGES ON DATABASE DAF To daf_user;
\c daf_test
GRANT ALL PRIVILEGES ON DATABASE DAF_test To daf_user;
- setting enviroment variables
touch .env
nano .env
## place the enviroment variables below inside the .env file
# .env
APP_PORT=3000
POSTGRES_HOST=localhost
POSTGRES_USER=daf_user
POSTGRES_DB=daf
POSTGRES_PASSWORD=password123
POSTGRES_TEST_DB=daf_test
ENV=dev
BCRYPT_PASS=thisissupersecretpassword
SALT_ROUNDS=10
PEPPER=password
JWT_SECRET_KEY=thisissupersecretpassword
- port of the posgres database server
5432
- port of the backend: the server runs localhost
- to run the application
npm run dev
To run tests, you need only two steps
- Export ENV to test
export ENV=test
- Run testing command, which will set the ENV to test if you've forgotten to do the first step, and will run the testing database migrations, then running the test suits
npm run test
npm run migrate # running testing migrations
npm run jasmine # running jasmine for testing
npm run migrate-down # down the migrations
npm run dev # run the application
- 🚀 Signup
- 🚀 Login
- 🚀 accept/reject order
- 🚀 create order
- 🚀 get user order
- 🚀 add product to order
- 🚀 setup testing
- Unit testing
- Integration testing