attendance.js 996 Bytes
var express = require('express');
var router = express.Router();
var mysql = require('mysql');
var conf = require('../conf/db');
var pool = mysql.createPool(conf.local)


/* GET home page. */
router.get('/:lecture_id', function(req, res, next) {
	var lecture_id = req.params.lecture_id;

	pool.getConnection(function(err, conn){
	conn.query('select a.student_id AS student_id, s.student_name AS student_name, a.status AS status, CONVERT_TZ(a.timestamp, "+00:00", "+09:00") AS timestamp FROM student_attendance a JOIN student s USING (student_id) WHERE (a.lecture_id=?) AND (DATE(timestamp) = CURDATE()) ORDER BY timestamp;', [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
		};
		console.log(msg)
		res.json(msg);
		});
	conn.release();	
	});
});

module.exports = router;