-
Notifications
You must be signed in to change notification settings - Fork 0
/
a1_truck.js
executable file
·130 lines (116 loc) · 3.86 KB
/
a1_truck.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
require("dotenv").config({ path: __dirname + "/.env" });
require("./server/connection");
const morgan = require("morgan");
const express = require("express");
const bodyParser = require("body-parser");
const path = require("path");
const cors = require("cors");
const port = process.env.PORT;
const compression = require('compression');
const cronJob = require('node-cron');
const Bookings = require('./server/utils/Bookings/index');
const Common = require('./server/controllers/Common');
const expressWiston = require('express-winston');
const { transports,format } = require('winston');
// require('winston-mongodb');
const db = require('./server/connection/index');
const app = express();
// **********Logging Start*********
app.use(expressWiston.logger({
transports:[
new transports.File({
level:'warn',
filename:'logs/logWarning.log'
}),
new transports.File({
level:'error',
filename:'logs/logError.log'
}),
new transports.File({
level:'info',
filename:'logs/logInfo.log'
}),
new transports.File({
level:'http',
filename:'logs/logHttp.log'
}),
new transports.File({
level:'verbose',
filename:'logs/logVerbose.log'
}),
new transports.File({
level:'debug',
filename:'logs/logDebug.log'
}),
new transports.File({
level:'silly',
filename:'logs/logSilly.log'
}),
// new transports.MongoDB({
// db : db,
// collection: 'mylogs'
// })
],
format:format.combine(
format.json(),
format.timestamp(),
format.metadata(),
format.prettyPrint()
),
statusLevels:true
}))
app.use(expressWiston.errorLogger({
transports:[
new transports.File({
level:'error',
filename:'logs//logInternalError.log'
}),
],
format:format.combine(
format.json(),
format.timestamp()
),
statusLevels:true
}))
// **********Logging End*********
app.use(compression());
app.use(morgan("dev"));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cors({ origin: "*" }));
app.use(express.static(path.join(__dirname, "./server/views")));
app.use("/files", express.static(__dirname + "/server/uploads"));
app.get("/", (req, res) => {
res.sendFile(path.join("/index.html"));
});
//routers
const users = require("./server/routes/users");
const vehicles = require("./server/routes/vehicles");
const administration = require("./server/routes/administration");
const common = require("./server/routes/common");
const appdata = require("./server/routes/AppData");
const bookings = require("./server/routes/bookings");
app.use(process.env["API_V1"] + "admin", administration);
app.use(process.env["API_V1"] + "user", users);
app.use(process.env["API_V1"] + "vehicle", vehicles);
app.use(process.env["API_V1"] + "common", common);
app.use(process.env["API_V1"] + "appdata", appdata);
app.use(process.env["API_V1"] + "bookings", bookings);
cronJob.schedule('0 */1 * * * *', async function () { // expire job on expiration.
await Bookings.autoUpdateBooking();
});
cronJob.schedule('0 */1 * * * *', async function () { // 2 hours prior booking ends for daily booking.
await Common.fireNotificationOnDailyEvents();
});
cronJob.schedule('0 */1 * * * *', async function () { // upcoming booking half an hour ago or 30 min before.
await Common.fireNotificationOnUpcomingEvent();
});
cronJob.schedule('0 13 */1 * * *', async function () { // 2 days prior notification of weekly and monthly plan ends.
await Common.fireNotificationOnWeeklyAndMonthlyEvent();
});
cronJob.schedule('0 */5 * * * *', async function () { // notification fire every 5 min on active bookings.
await Common.fireNotificationOnActiveBookings();
});
app.listen(port, () => {
console.log(`https server running on port ${port}`);
});