Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
707d12e
Create database interaction methods
JakeMinor Feb 1, 2022
8b2ac24
Create bill business logic
JakeMinor Feb 1, 2022
19ec81e
Update bill model to have paid property
JakeMinor Feb 1, 2022
f5613af
Create bill controllers
JakeMinor Feb 1, 2022
aea9e86
Create bill routes and add to router
JakeMinor Feb 1, 2022
adc78f7
Merge branch 'develop' into HT-14-create-bill-endpoints
JakeMinor Feb 1, 2022
17cf974
Add package-lock.json
JakeMinor Feb 1, 2022
e5e08b6
Fix bugs with bill endpoints
JakeMinor Feb 1, 2022
3796b39
Add tests for bill endpoints
JakeMinor Feb 1, 2022
0af299e
Add console logs to debug pipeline
JakeMinor Feb 1, 2022
be78a36
Add more console logs to debug pipeline
JakeMinor Feb 1, 2022
893f619
Add catch to getall endpoint
JakeMinor Feb 1, 2022
4b7d742
Attempt to fix pipeline #3
JakeMinor Feb 1, 2022
d74c6e6
Attempt to fix pipeline #4
JakeMinor Feb 1, 2022
1bd20bf
Merge branch 'develop' into HT-14-create-bill-endpoints
JakeMinor Feb 1, 2022
5f9f933
Remove pipeline debugging and update workflow
JakeMinor Feb 1, 2022
47a1f50
Add coverage report to build pipeline
JakeMinor Feb 1, 2022
9732dd1
HT-14 Update yml to authenticate coverage report
jarrodback Feb 1, 2022
a9e6c50
HT-14 Attempt to fix sonar and deployment
jarrodback Feb 1, 2022
ea707b3
HT-14 Rename action
jarrodback Feb 1, 2022
58b4fd6
HT-14 Run pipeline on every commit
jarrodback Feb 1, 2022
1b8e315
Remove lcov folder and add to .gitignore
JakeMinor Feb 2, 2022
861c6e6
Merge branch 'HT-14-create-bill-endpoints' of https://github.com/jarr…
JakeMinor Feb 2, 2022
154fc4f
Make changes based on code review and calculate cost based on haversi…
JakeMinor Feb 2, 2022
55c2a7e
remove unneeded package.json
JakeMinor Feb 2, 2022
a69488a
Debug pipeline
JakeMinor Feb 2, 2022
defca38
HT-14 Set default object for dbConfig
JakeMinor Feb 2, 2022
d1fc89e
HT-14 Add driver id to bill and update tests
JakeMinor Feb 2, 2022
0251236
HT-14 Fix pipeline tests
JakeMinor Feb 2, 2022
9c86473
HT-14 Update price on insert many hook
JakeMinor Feb 2, 2022
6481249
HT-14 remove unneeded console.log and fix code smells
JakeMinor Feb 2, 2022
3f211e0
HT-14 Fix code smell
JakeMinor Feb 2, 2022
120bb76
HT-14 Fix code smell
JakeMinor Feb 2, 2022
0ddd851
HT-14 Add unit tests for utilities function
JakeMinor Feb 2, 2022
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
17 changes: 8 additions & 9 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI
name: Build-Test-Deploy Pipeline

on:
push:
branches: [ develop ]
pull_request:
branches: [ develop ]

Expand Down Expand Up @@ -36,25 +34,26 @@ jobs:
cd server
npm ci
npm run build --if-present
- name: Server - run tests
run: |
cd server
npm test
- name: UI - run build
run: |
cd ui
npm ci
npm run build --if-present
- name: Server - run tests
run: |
cd server
npm test
- name: UI - run tests
run: |
cd ui
npm test
- name: Code Coverage
uses: romeovs/lcov-reporter-action@v0.2.16
with:
lcov-file: ./coverage/lcov.info
lcov-file: ./server/coverage/lcov.info
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Deploy
uses: JamesIves/github-pages-deploy-action@v4.2.3
with:
branch: gh-pages
folder: develop
folder: ./ui/dist/
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ node_modules
/dist
server/.nyc_output/*.json
server/.nyc_output/processinfo/*.json
server/coverage/lcov-report

# local env files
.env.local
Expand All @@ -22,5 +23,4 @@ pnpm-debug.log*
*.ntvs*
*.njsproj
*.sln
*.sw?
*.env
*.sw?
1 change: 1 addition & 0 deletions server/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TOKEN_SECRET=test
2 changes: 1 addition & 1 deletion server/.nyc_output/processinfo/index.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"processes":{"ecd4285b-d9dc-4104-b850-fcf81a763c89":{"parent":null,"children":[]}},"files":{"C:\\Users\\Jarrod\\Documents\\AAF\\CSSD\\server\\app.js":["ecd4285b-d9dc-4104-b850-fcf81a763c89"],"C:\\Users\\Jarrod\\Documents\\AAF\\CSSD\\server\\database\\index.js":["ecd4285b-d9dc-4104-b850-fcf81a763c89"],"C:\\Users\\Jarrod\\Documents\\AAF\\CSSD\\server\\config\\db.config.js":["ecd4285b-d9dc-4104-b850-fcf81a763c89"],"C:\\Users\\Jarrod\\Documents\\AAF\\CSSD\\server\\models\\user.model.js":["ecd4285b-d9dc-4104-b850-fcf81a763c89"],"C:\\Users\\Jarrod\\Documents\\AAF\\CSSD\\server\\routes\\auth.routes.js":["ecd4285b-d9dc-4104-b850-fcf81a763c89"],"C:\\Users\\Jarrod\\Documents\\AAF\\CSSD\\server\\controllers\\auth.controller.js":["ecd4285b-d9dc-4104-b850-fcf81a763c89"],"C:\\Users\\Jarrod\\Documents\\AAF\\CSSD\\server\\business\\user.business.js":["ecd4285b-d9dc-4104-b850-fcf81a763c89"],"C:\\Users\\Jarrod\\Documents\\AAF\\CSSD\\server\\datalayer\\mongo.js":["ecd4285b-d9dc-4104-b850-fcf81a763c89"]},"externalIds":{}}
{"processes":{"4d150775-f277-4c3e-a138-a2031d24611b":{"parent":null,"children":[]}},"files":{"C:\\Projects\\CSSD-Assignment\\server\\app.js":["4d150775-f277-4c3e-a138-a2031d24611b"],"C:\\Projects\\CSSD-Assignment\\server\\database\\index.js":["4d150775-f277-4c3e-a138-a2031d24611b"],"C:\\Projects\\CSSD-Assignment\\server\\config\\db.config.js":["4d150775-f277-4c3e-a138-a2031d24611b"],"C:\\Projects\\CSSD-Assignment\\server\\models\\journey.model.js":["4d150775-f277-4c3e-a138-a2031d24611b"],"C:\\Projects\\CSSD-Assignment\\server\\models\\bill.model.js":["4d150775-f277-4c3e-a138-a2031d24611b"],"C:\\Projects\\CSSD-Assignment\\server\\utilities.js":["4d150775-f277-4c3e-a138-a2031d24611b"],"C:\\Projects\\CSSD-Assignment\\server\\models\\location.model.js":["4d150775-f277-4c3e-a138-a2031d24611b"],"C:\\Projects\\CSSD-Assignment\\server\\models\\user.model.js":["4d150775-f277-4c3e-a138-a2031d24611b"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\auth.routes.js":["4d150775-f277-4c3e-a138-a2031d24611b"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\auth.controller.js":["4d150775-f277-4c3e-a138-a2031d24611b"],"C:\\Projects\\CSSD-Assignment\\server\\business\\user.business.js":["4d150775-f277-4c3e-a138-a2031d24611b"],"C:\\Projects\\CSSD-Assignment\\server\\datalayer\\mongo.js":["4d150775-f277-4c3e-a138-a2031d24611b"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\bill.routes.js":["4d150775-f277-4c3e-a138-a2031d24611b"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\bill.controller.js":["4d150775-f277-4c3e-a138-a2031d24611b"],"C:\\Projects\\CSSD-Assignment\\server\\business\\bill.business.js":["4d150775-f277-4c3e-a138-a2031d24611b"]},"externalIds":{}}
7 changes: 4 additions & 3 deletions server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const cookieParser = require("cookie-parser");
require("./database");
require("dotenv").config();

var app = express();
const app = express();

app.use(
cookieSession({
Expand All @@ -24,8 +24,8 @@ app.use(cors({ origin: "http://localhost:8080", credentials: true }));
/**
* Router setup
*/
var authRouter = require("./routes/auth.routes");

const authRouter = require("./routes/auth.routes");
const billRouter = require("./routes/bill.routes");
/**
* View Engine setup
*/
Expand All @@ -40,5 +40,6 @@ app.use(cookieParser());

// Configuring the main routes
app.use("/auth", authRouter);
app.use("/bill", billRouter)

module.exports = app;
39 changes: 39 additions & 0 deletions server/business/bill.business.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const DataLayer = require("../datalayer/mongo");
const Utilities = require("../utilities")
const model = require("../database").getModel("bill");
const httpError = require("http-errors");

module.exports = class BillBusiness {
constructor() {
// Create an instance of the data layer.
this.dataLayer = new DataLayer(model);
}

/**
* Get all bills.
*/
async getAllBills(queryString) {
const filter = {
driver: queryString.driver,
paid: queryString.paid,
limit: queryString.limit ?? 10,
offset: queryString.offset ?? 0
}
return this.dataLayer
.findAllAndPopulate(filter, [{ path: 'journey', populate: { path: 'entryLocation exitLocation' }}, {path: 'driver', select: 'username type email'}])
.catch((error) => {
throw httpError(500, error.message)})
}

/**
* Get a bill by ID.
*/
async payBill(id) {
const record = {
paid: true
}
return this.dataLayer.update(id, record)
.catch((error) => {throw httpError(404, error.message)
})
}
}
12 changes: 3 additions & 9 deletions server/business/user.business.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const httpError = require("http-errors");
const jwt = require("jsonwebtoken");
const bcrypt = require("bcryptjs");

class UserBusiness {
module.exports = class UserBusiness {
constructor() {
// Create an instance of the data layer.
this.dataLayer = new DataLayer(model);
Expand Down Expand Up @@ -47,8 +47,7 @@ class UserBusiness {
id: user._id,
};
})
.catch(() => {
throw httpError(400, "Your email or password is incorrect.");
.catch(() => {throw httpError(400, "Your email or password is incorrect.");
});
}

Expand Down Expand Up @@ -104,15 +103,10 @@ class UserBusiness {
});
}
}
module.exports = UserBusiness;

/**
* Validates the data in a User.
*/
function isUserDataValid(user) {
if (!user || !user.username || !user.email || !user.password) {
return false;
} else {
return true;
}
return !(!user || !user.username || !user.email || !user.password);
}
23 changes: 23 additions & 0 deletions server/controllers/bill.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const BillBusiness = require("../business/bill.business");
const billBusiness = new BillBusiness();

/**
* Get all bills
*/
exports.getAllBills = async (req, res) => {
billBusiness.getAllBills(req.query)
.then((data) => {return res.status(200).send(data)})
.catch((error) => {
res.status(error.status).send({message: error.message})
})

}

/**
* Pay bill
*/
exports.payBill = async (req, res) => {
billBusiness.payBill(req.params.id)
.then(() => {res.status(200).send({message: "Bill paid."})})
.catch((error) => {res.status(error.status).send({message: error.message})})
}
Loading