-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
55 lines (49 loc) · 1.83 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
const express = require('express')
const app = express()
const port = 3001
let sentimentController = require('./controller/sentimentController.js')
// let departmentController = require('./controller/departmentController.js')
let departmentModel = require('./models/departmentModel.js')
let complaintModel = require('./models/complaintModel.js')
let trackModel = require('./models/trackModel.js')
const bodyParser = require('body-parser');
app.use(bodyParser());
app.set('view engine', 'ejs');
app.get('/',(req, res) => {
res.render('home');
});
app.post('/submit',(req, res) => {
sentimentController.findUrgency(req,res);
})
app.get('/tracking', (req, res) => {
res.render('tracking');
})
app.post('/tracking', (req, res) => {
trackModel.getTrack(req.body['track-id'])
.then(status => res.render('trackDetails', {status}))
.catch(err => res.send("Error: "+err))
})
app.get('/department',(req,res) => {
res.render('login');
})
app.post('/department',(req,res)=>{
if(req.body['id'] == undefined){
departmentModel.authenticate(req.body['department'],req.body['password'])
.then(department => complaintModel.list(department))
.then(data => data['data']['complain_details'])
.then(data => {
department = req.body['department'];
res.render('department', {data, department})})
.catch(err => res.send("Error: "+err))
}
else{
complaintModel.update(req.body['id'], req.body.status, req.body['department'])
.then(department => complaintModel.list(department))
.then(data => data['data']['complain_details'])
.then(data => {
department = req.body['department'];
return res.render('department', {data, department});})
.catch(err => res.send("Error "+err))
}
})
app.listen(port, () => console.log(`App listening on port ${port}!`))