/** * Created by WebStorm. * User: martin * Date: 18/05/2020 * Time: 13:39 */ const dbmanager = require('../../lib/dbmanager'); const killNLDoubleSpace = /(\\n)\s{2,}|(\\n)|\s{2,}/g; exports.getList = (req, res) => { console.log('>getList req', req.params); /* if(!req.params.id) return res.status(400).send({ 'message': 'Job id missing' });*/ dbmanager.getList() .then((data) => { const processed = data.map((item) => { const date = new Date( item.timestamp * 1000); item.date = date.toLocaleString(); item.title = item.title.replace(killNLDoubleSpace, ' '); return item; }); res.send(processed); }) .catch((err) => { res.status(500).send({ 'message': err.message || 'Some error occurred while querying the database.' }); }); }; exports.getJob = (req, res) => { console.log('>getJob req', req.params); if(!req.params.id) return res.status(500).send({ 'message': 'Job id missing' }); const id = req.params.id; dbmanager.getOne(id) .then((data) => { const item = Object.assign({}, data); const date = new Date( item.timestamp * 1000); item.date = date.toLocaleString(); item.title = item.title.replace(killNLDoubleSpace, ' '); res.send(item); }) .catch((err) => { res.status(500).send({ 'message': err.message || 'Some error occurred while querying the database.' }); }); }; exports.readJob = (req, res) => { console.log('>readJob req', req.params); if(!req.params.id) return res.status(500).send({ 'message': 'Job id missing' }); const rid = req.params.id; const d = new Date().getTime(); // touchOne dbmanager.touchOne({ rid, d }) .then((data) => { console.log(data); res.status(200).end(); }) .catch((err) => { res.status(500).send({ 'message': err.message || 'Some error occurred while querying the database.' }); }); };