-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
89 lines (76 loc) · 2.82 KB
/
app.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
// server.js
// setup
// setup
var express = require('express');
var session = require('express-session');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var morgan = require('morgan');
var exphbs = require('express-handlebars')
var app = express();
var port = process.env.PORT || 3000;
var passport = require('passport');
var flash = require('connect-flash');
const pool = require('./app/model/pg');
require('./config/passport')(passport,pool);
var hbs = exphbs.create({ defaultLayout: 'main-user' ,
helpers: {
inc : function(value, options)
{
return parseInt(value) + 1;
},
ifCond: function (v1, operator, v2, options) {
console.log(v2);
//console.log(v1);
switch (operator) {
case '==':
return (v1 == v2) ? options.fn(this) : options.inverse(this);
case '===':
return (v1 === v2) ? options.fn(this) : options.inverse(this);
case '!=':
return (v1 != v2) ? options.fn(this) : options.inverse(this);
case '!==':
return (v1 !== v2) ? options.fn(this) : options.inverse(this);
case '<':
return (v1 < v2) ? options.fn(this) : options.inverse(this);
case '<=':
return (v1 <= v2) ? options.fn(this) : options.inverse(this);
case '>':
return (v1 > v2) ? options.fn(this) : options.inverse(this);
case '>=':
return (v1 >= v2) ? options.fn(this) : options.inverse(this);
case '&&':
return (v1 && v2) ? options.fn(this) : options.inverse(this);
case '||':
return (v1 || v2) ? options.fn(this) : options.inverse(this);
default:
return options.inverse(this);
}
},
fmNum: function(value) {
var parts = value.toString().split(".");
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ".");
return parts.join(".");
},
tenPercent: function(value) {
return parseInt(value) + parseInt(value*0.1);
},
total: function(value,qty) {
value = value*qty;
var parts = value.toString().split(".");
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ".");
return parts.join(".");
},
section: function(name, options){
if(!this._sections) this._sections = {};
this._sections[name] = options.fn(this);
return null;
}
},
});
require('./config/express')(app,hbs,express, session,morgan,cookieParser,bodyParser,passport,flash);
// routes ======================================================================
require('./route/routes.js')(app, passport,pool); // load our routes and pass in our app and fully configured passport
// launch ======================================================================
app.listen(port);
console.log('Server started on port ' + port);