admin.js
3.67 KB
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
131
132
133
var express = require('express');
var router = express.Router();
var mysql = require('mysql');
var conf = require('../conf/db');
var pool = mysql.createPool(conf.local)
var moment = require('moment');
require('moment-timezone');
router.post('/attend', function(req, res, next) {
var request_id = req.body.request_id;
console.log(request_id)
var lecture_id = req.body.lecture_id;
console.log(lecture_id)
var student_id = req.body.student_id;
console.log(student_id);
var student_name = req.body.student_name;
console.log(student_name)
var status = req.body.status;
console.log(status)
moment.tz.setDefault("Asia/Seoul");
var now = moment().format('YYYY-MM-DD HH:mm:ss');
pool.getConnection(function(err, conn){
conn.query('INSERT INTO student_attendance(lecture_id,student_id,status,timestamp)VALUES(?,?,?,?)', [lecture_id, student_id, status, now], function (err, rows){
if (err){
console.log(err);
return res.status(500).json({error: err});
}
if (!rows) return res.status(400).json({error: 'not found'});
var msg = {
status: 'success',
err: '',
result: rows,
length: rows.length
};
res.json(msg);
});
conn.release();
});
console.log("ddd")
});
router.post('/solve', function(req, res, next) {
var request_id = req.body.request_id;
console.log(request_id)
var lecture_id = req.body.lecture_id;
console.log(lecture_id)
var student_id = req.body.student_id;
console.log(student_id);
var student_name = req.body.student_name;
console.log(student_name)
var status = req.body.status;
console.log(status)
moment.tz.setDefault("Asia/Seoul");
var now = moment().format('YYYY-MM-DD HH:mm:ss');
pool.getConnection(function(err, conn){
conn.query('Update student_request Set status=? where id=?', [status, request_id], function (err, rows){
if (err){
console.log(err);
return res.status(500).json({error: err});
}
if (!rows) return res.status(400).json({error: 'not found'});
var msg = {
status: 'success',
err: '',
result: rows,
length: rows.length
};
res.json(msg);
});
conn.release();
});
});
router.get('/:lecture_id', function(req, res, next) {
var lecture_id = req.params.lecture_id;
pool.getConnection(function(err, conn){
conn.query('select r.id, r.student_id AS student_id, r.student_name AS student_name, r.status AS status, CONVERT_TZ(r.timestamp, "+00:00", "+09:00") AS timestamp FROM student_request r WHERE (r.lecture_id=?) AND (DATE(timestamp) = CURDATE()) ORDER BY timestamp DESC;', [lecture_id], function (err, rows){
if (err){
console.log(err);
return res.status(500).json({error: err});
}
if (!rows) return res.status(400).json({error: 'not found'});
var msg = {
status: 'success',
err: '',
result: rows,
length: rows.length
};
res.json(msg);
});
conn.release();
});
});
router.post('/request/:lecture_id', function(req, res, next) {
var lecture_id = req.params.lecture_id;
console.log(lecture_id)
var student_id = req.body.student_id;
console.log(student_id);
var student_name = req.body.student_name;
console.log(student_name)
moment.tz.setDefault("Asia/Seoul");
var now = moment().format('YYYY-MM-DD HH:mm:ss');
pool.getConnection(function(err, conn){
conn.query('INSERT INTO student_request(lecture_id,student_id,student_name,status,timestamp)VALUES(?,?,?,?,?)', [lecture_id, student_id, student_name, "pending", now], function (err, rows){
if (err){
console.log(err);
return res.status(500).json({error: err});
}
if (!rows) return res.status(400).json({error: 'not found'});
var msg = {
status: 'success',
err: '',
result: rows,
length: rows.length
};
res.redirect('/');
});
conn.release();
});
});
module.exports = router;