-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
executable file
·76 lines (69 loc) · 1.77 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
let express = require('express');
let app = express();
let fs = require('fs');
let path = require('path');
let bodyParser = require('body-parser');
let cal = require('./public/assets/cal');
let port = process.env.PORT || 8080;
let gradeNum = {
"S" : 10,
"A" : 9,
"B" : 8,
"C" : 7,
"D" : 6,
"E" : 5,
"F" : 0,
"P" : 0,
"I" : 0,
"MP": 0,
"DT": 0,
"PASS": 1,
"FAIL": 0
}
app.use(express.static(__dirname + '/public'));
app.engine('html', require('ejs').renderFile);
app.use(bodyParser.urlencoded({extended:true}));
app.get('/', (req, res) => {
res.render('index.ejs');
});
app.post('/', (req, res) => {
let semester, resultObj, objResult, cgpaObj, regNum, result, name, cgpaFile, cgpa;
semester = req.body.semester;
resultObj = fs.readFileSync(semester+'.json');
objResult = JSON.parse(resultObj);
regNum = req.body.username;
result = objResult[regNum];
if(result){
cgpaFile = fs.readFileSync('CGPA.json');
cgpaObj = JSON.parse(cgpaFile);
name = cgpaObj[regNum][0];
cgpa = cgpaObj[regNum][1];
let gpa = cal(gradeNum, result);
if (gpa["3"] == "0")
gpa = gpa.slice(0, 3);
if (gpa == "10.")
gpa = gpa.slice(0, 2);
if (name) {
let nameStr = '';
let nameArr = name.split(' ');
if (nameArr[1] == undefined) {
nameStr = nameArr[0];
} else {
nameStr = nameArr[0] + " " + nameArr[1]
}
regNum = nameStr;
} else {
regNum = regNum;
}
res.render('result_page.ejs', { gpa: gpa, name: regNum, sresult: JSON.stringify(result), cgpa: cgpa });
}
else {
res.redirect('/');
}
});
app.get('/dev', (req, res) => {
res.render('developers.html');
});
app.listen(port, (req, res) => {
console.log('Server running on port : ' + port);
});