Skip to content

NW6 | Pedro Ricciardi | Databases Module | [TECH ED] E-Commerce API | Sprint 4 #175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0663e12
.env files added in .gitignore
PERicci May 29, 2024
2c9e95e
package-lock.json created
PERicci May 29, 2024
78fd436
created db.js to access my database
PERicci May 29, 2024
057f5b8
basic route added
PERicci May 29, 2024
0561393
port added as a variable
PERicci May 29, 2024
29468d1
db access test success
PERicci May 29, 2024
fc0dfda
added --watch on start script
PERicci May 29, 2024
8462829
test using port 3001, list of products organised with correct propert…
PERicci May 29, 2024
783aa6e
test now disconnect server and db
PERicci May 29, 2024
8b1efa5
get products by name now is case insenstitive and returns results wit…
PERicci May 29, 2024
b68b298
get customer by id done
PERicci May 29, 2024
e50e31d
added done mark on user story 3
PERicci May 29, 2024
e8a7399
routes splitted
PERicci May 29, 2024
b3544db
get product by name error solved
PERicci May 30, 2024
637b83b
customer not found error implemente
PERicci May 30, 2024
b342019
create new customer implemented
PERicci May 30, 2024
82abee0
change some comments
PERicci May 30, 2024
6759cbb
tests divided by group
PERicci May 30, 2024
d44680e
tests organised using jest.setup and jest.config
PERicci May 30, 2024
4663566
old code deleted from test files
PERicci May 30, 2024
209c655
changed country in post customers to match the standard
PERicci May 30, 2024
accd8ad
add new product test implemented and some bug fixed
PERicci May 30, 2024
d0376cc
add product implemented
PERicci May 30, 2024
50dd759
product-availability post implemented, positive and first negative te…
PERicci May 30, 2024
e11c0dd
post product-availability endpoint and test implemented, minor change…
PERicci May 30, 2024
4b80db8
orders first test implemented
PERicci May 30, 2024
9d239b4
add order route and test implemented, some date errors still need to …
PERicci May 30, 2024
a6b56ac
create order implemented
PERicci May 30, 2024
4184e86
update customer implemented
PERicci May 30, 2024
1bd5f67
delete order and related order items
PERicci May 30, 2024
2d254df
delete customer without orders
PERicci May 31, 2024
179a2bf
get all detailed orders from a customer by customer_id
PERicci May 31, 2024
f309db1
last user story checked on readme.md
PERicci May 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@

E-Commerce-API/node_modules/
.env
23 changes: 18 additions & 5 deletions E-Commerce-API/app.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
const express = require("express");
const productsRoute = require("./routes/productsRoute");
const customersRoute = require("./routes/customersRoute");
const productAvailabilityRoute = require("./routes/productAvailabilityRoute");
const ordersRoute = require("./routes/ordersRoute")

const app = express();
// Your code to run the server should go here
// Don't hardcode your DB password in the code or upload it to GitHub! Never ever do this ever.
// Use environment variables instead:
// https://www.codementor.io/@parthibakumarmurugesan/what-is-env-how-to-set-up-and-run-a-env-file-in-node-1pnyxw9yxj
const port = process.env.PORT || 3000;

app.use(express.json());

app.use("/products", productsRoute);
app.use("/customers", customersRoute);
app.use("/product-availability", productAvailabilityRoute)
app.use("/orders", ordersRoute)

const server = app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});

module.exports = app;
module.exports = server;
25 changes: 25 additions & 0 deletions E-Commerce-API/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const { Pool } = require('pg');
require('dotenv').config();

const db = new Pool({
connectionString: process.env.DATABASE_URL,
})

async function connect() {
await db.connect();
console.log('Connected to Postgres database');
}

async function end() {
if (db) {
await db.end();
console.log('Disconnected from Postgres database');
}
}

async function query(sql, params = []) {
const result = await db.query(sql, params);
return result;
}

module.exports = { connect, end, query };
5 changes: 5 additions & 0 deletions E-Commerce-API/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
testEnvironment: "node",
testMatch: ["**/tests/**/*.test.js"],
setupFilesAfterEnv: ["<rootDir>/jest.setup.js"],
};
22 changes: 22 additions & 0 deletions E-Commerce-API/jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const request = require("supertest");
const { end } = require("./db");
const { Client } = require("pg");
process.env.NODE_ENV = "test";
process.env.PORT = 3001;
const server = require("./app");

global.request = request;
global.server = server;
global.dbClient = new Client({
connectionString: process.env.DATABASE_URL
})

beforeAll(async () => {
await global.dbClient.connect();
});

afterAll(async () => {
await end();
await global.dbClient.end();
server.close();
});
Loading