1 - Create a .env file in the project's root folder that should contain
POSTGRES_HOST=127.0.0.1
POSTGRES_DB=online_store
POSTGRES_TEST_DB=online_store_test
POSTGRES_USER=<your_user>
POSTGRES_PASSWORD=<your_password>
NODE_ENV=dev
BCRYPT_PASSWORD=<your_bcrypt_password>
BCRYPT_SALT_ROUNDS=<number_of_salt_rounds>
TOKEN_SECRET=<your_token_secret>
2 - Edit the database.json file in the project's root folder with your database credentials. The file should look like this:
{
"dev": {
"driver": "pg",
"host": "127.0.0.1",
"database": "online_store",
"user": "your_user",
"password": "your_password"
},
"test": {
"driver": "pg",
"host": "127.0.0.1",
"database": "online_store_test",
"user": "your_user",
"password": "your_password"
}
}
3 - Connect to the pSQL default database by running the following command in your terminal:
psql -U postgres
4 - Create the dev and test databases by running the following commands in your terminal:
createdb online_store
createdb online_store_test
5 - Create a database user by running the following command:
createuser <your_user>
6 - Give the user full access to the dev and test databases by running the following commands:
psql online_store (or of you are already connected to the database, run \c online_store)
grant all privileges on database online_store to <your_user>;
psql online_store_test (or of you are already connected to the database, run \c online_store_test)
grant all privileges on database online_store_test to <your_user>;
7 - The backend port number is set to 3000. The database port number is set to 5432.
8 - To build the projext use npm run build
9 - To run the tests use npm run test
10 - To start your server locally use npm run start
The following tables have been created in the database:
status
- an enum type with valuesactive
,cancelled
, andcomplete
users
- a table with the following columns:id
- UUID primary key, default value is generated using theuuid_generate_v4()
functionfirst_name
- a required string with a maximum length of 50 characterslast_name
- a required string with a maximum length of 120 characterspassword
- a required string
products
- a table with the following columns:id
- UUID primary key, default value is generated using theuuid_generate_v4()
functionname
- a required string with a maximum length of 120 charactersprice
- an integer representing the price of the product in centscategory
- a string with a maximum length of 30 characters
orders
- a table with the following columns:id
- UUID primary key, default value is generated using theuuid_generate_v4()
functioncreated_at
- a required timestamp with a default value of the current timeuser_id
- UUID foreign key referencing theid
column of theusers
tablestatus
- a string with a maximum length of 20 characters representing the status of the order
product_order
- a table with the following columns:id
- UUID primary key, default value is generated using theuuid_generate_v4()
functionorder_id
- UUID foreign key referencing theid
column of theorders
tableproduct_id
- UUID foreign key referencing theid
column of theproducts
tablequantity
- an integer representing the quantity of the products ordered
GET - /products
: returns all products in the databaseGET - /products/:id
: returns a single product by IDPOST - /products
: creates a new product with the provided name, price, and category
GET - /users
: returns all users in the databaseGET - /users/:id
: returns a single user by IDGET - /users/authenticate
: authenticates a user with the id and passwordPOST - /users
: creates a new user with the provided first name, last name, and password
GET - /orders
: returns all orders in the databaseGET - /orders/:id
: returns a single order by IDGET - /orders/currentOrder/:userId
: returns the user's current orderGET - /orders/completedOrders/:userId
: returns all of the user's completed ordersPOST - /orders
: creates a new order with the provided user ID and statusPOST - /orders/:id/addProduct
: adds a product to the orderPOST - /orders/:id/complete
: completes the order with the provided order ID