-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
142 lines (119 loc) · 3.27 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
const express = require('express');
const nocache = require('nocache');
const hbs = require('hbs');
const path = require('path');
const mongoose = require('mongoose');
const session = require('express-session');
const mongoStore = require('connect-mongo')(session);
const routes = require('./routes/routes.js');
const db = require('./models/db.js');
const powerzone = express();
port = process.env.PORT || 3000;
hostname = process.env.HOSTNAME || 3000;
url = process.env.DB_URL;
db.connect();
powerzone.set('view engine', 'hbs');
hbs.registerPartials(__dirname + '/views/partials');
hbs.handlebars.registerHelper('getRole', function(dbRole) {
if (dbRole == 'inventory-manager') {
return 'Inventory Manager';
} else if (dbRole == 'transaction-cashier') {
return 'Transaction Cashier';
} else {
return 'Delivery Manager';
}
});
hbs.handlebars.registerHelper('getStatus', function(status) {
if (status == 'Accepted') {
return '/assets/accepted.png';
} else if (status == 'Pending') {
return '/assets/pending.png';
} else {
return '/assets/rejected.png';
}
});
hbs.handlebars.registerHelper('getFullName', function(firstName, lastName) {
return firstName.concat(' ', lastName);
});
hbs.handlebars.registerHelper('getType', function(type) {
if (type == 'gasoline') {
return 'Gasoline';
} else if (type == 'premium-gasoline-95') {
return 'Premium Gasoline 95';
} else if (type == 'diesel') {
return 'Diesel';
} else if (type == 'premium-gasoline-97') {
return 'Premium Gasoline 97';
} else {
return 'Kerosene';
}
});
hbs.handlebars.registerHelper('validInventoryRole', function(role) {
if (role == 'administrator' || role == 'inventory-manager') {
return true;
} else {
return false;
}
});
hbs.handlebars.registerHelper('validTransactionRole', function(role) {
if (role == 'administrator' || role == 'transaction-cashier') {
return true;
} else {
return false;
}
});
hbs.handlebars.registerHelper('getStatusIcon', function(status) {
if (status == 'completed') {
return '/assets/accepted.png';
} else if (status == 'pending') {
return '/assets/pending.png';
} else {
return '/assets/rejected.png';
}
});
hbs.handlebars.registerHelper('getStatusString', function(status) {
if (status == 'completed') {
return 'Completed';
} else if (status == 'pending') {
return 'Pending';
} else {
return 'Cancelled';
}
});
hbs.handlebars.registerHelper('openTransaction', function(status) {
if (status == 'completed') {
return false;
} else {
return true;
}
});
hbs.handlebars.registerHelper('validDeliveryRole', function(role) {
if (role == 'administrator' || role == 'delivery-manager' || role == 'transaction-cashier') {
return true;
} else {
return false;
}
});
powerzone.use(express.static(path.join(__dirname, '/public')));
powerzone.use(express.json());
powerzone.use(
express.urlencoded({
extended: true
})
);
powerzone.use(nocache());
powerzone.use(
session({
secret: process.env.session_secret,
resave: false,
saveUninitialized: false,
store: new mongoStore({mongooseConnection: mongoose.connection})
})
);
powerzone.use('/', routes);
powerzone.listen(port, hostname, function() {
console.log('Server is running at: ');
console.log('http://' + hostname + ':' + port);
});
/* For unit testing of REST API */
module.exports = powerzone;