router-sms.js
1018 Bytes
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
"use strict";
const moment = require('moment');
const express = require('express');
const localDb = require('../local-db');
const router = express.Router();
module.exports = router;
function pageSmsIndex(req, res, next) {
if (!req.query.input_date) {
req.query.input_date = moment().format('YYYY-MM-DD');
}
res.render(
'sms.index.html',
{
page_title: 'Histori SMS',
input_date: req.query.input_date
}
)
}
function pageSmsDataTables(req, res, next) {
const db = localDb.getConnection();
const created_date = req.query.input_date || moment().format('YYYY-MM-DD');
const query = "SELECT rowid, * FROM sms WHERE created_date = ? ORDER BY created DESC, rowid DESC";
db.all(query, created_date, function (err, rows) {
if (err) {
res.end("Ada error: " + err);
return;
}
res.json({data: rows});
});
}
router.get('/', pageSmsIndex);
router.get('/datatables', pageSmsDataTables);