forked from notreallystatic/Student-Info
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
100 lines (81 loc) · 2.23 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
90
91
92
93
94
95
96
97
98
99
100
const express = require('express'),
app = express(),
mongoose = require('mongoose'),
bodyParser = require('body-parser'),
Schema = mongoose.Schema;
mongoose.connect('mongodb://localhost:27017/Student-info', {useNewUrlParser: true},function(error){
//console.log(error);
});
const StudentSchema = new Schema({
RegnNo: String ,
AadhaarNo: String,
Name:String,
Fname:String,
Gender:String,
AdmissionYear:String,
Course:String,
Branch:String,
AllotmentCategory:String,
AdmissionMode: String,
Contact1:String,
Contact2:String,
Email:String
});
const Student = mongoose.model('Students', StudentSchema);
app.use(bodyParser.urlencoded({extended: true}));
app.set('view engine', 'ejs');
app.use(express.static('public'));
// LOGIN ROUTE
app.get('/login', (req, res) => {
res.render('login');
})
// INDEX ROUTE
app.get('/', (req, res) => {
res.render('index');
})
// SHOW ROUTE
app.get('/show', (req, res) => {
res.render('findStudent');
})
app.post('/show', (req, res) => {
//Fetch the Student ID and show the coresponding details
let id = req.body.id;
// Search for this id in the DB and return the Student object
res.render('show', {student: id});
})
// Add Student Route
app.get('/addStudent', (req, res) => {
res.render('addStudent');
})
// Post route to add a new Student to our DB
app.post('/addStudent', (req, res) => {
console.log(req.body);
let student = new Student();
student.RegnNo=req.body.RegnNo;
student.AadhaarNo=req.body.AadhaarNo;
student.Name=req.body.Name;
student.Fname=req.body.Fname;
student.AdmissionYear=req.body.AdmissionYear;
student.Gender=req.body.Gender;
student.Course=req.body.Course;
student.AllotmentCategory=req.body.AllotmentCategory;
student.AdmissionMode=req.body.AdmissionMode;
student.Contact1=req.body.Contact1;
student.Contact2=req.body.Contact2;
student.Email=req.body.Email;
console.log(req.body.Branch);
if (req.body.Course === "BTech"){
student.Branch =req.body.Branch[0];
}
else if (req.body.Course === "MTech"){
student.Branch =req.body.Branch[1];
}
else{
student.Branch = req.body.Branch[2];
}
student.save();
res.send("Student post route");
})
app.listen(3000, () => {
console.log('Server is running...');
})