2017-11-04 11:00:35 +08:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const express = require('express');
|
|
|
|
const router = express.Router();
|
|
|
|
const sql = require('../../services/sql');
|
|
|
|
|
|
|
|
router.get('', async (req, res, next) => {
|
|
|
|
await deleteOld();
|
|
|
|
|
2017-11-04 23:44:42 +08:00
|
|
|
const result = await sql.getResults("SELECT * FROM event_log ORDER BY date_added DESC");
|
2017-11-04 11:00:35 +08:00
|
|
|
|
|
|
|
res.send(result);
|
|
|
|
});
|
|
|
|
|
|
|
|
async function deleteOld() {
|
|
|
|
const cutoffId = await sql.getSingleValue("SELECT id FROM event_log ORDER BY id DESC LIMIT 1000, 1");
|
|
|
|
|
|
|
|
if (cutoffId) {
|
2017-11-29 06:04:47 +08:00
|
|
|
await sql.doInTransaction(async db => {
|
|
|
|
await sql.execute(db, "DELETE FROM event_log WHERE id < ?", [cutoffId]);
|
|
|
|
});
|
2017-11-04 11:00:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = router;
|