jobscraper/server/controllers/jobs.controller.js
Martin Donnelly 5001bbd798 init
2020-05-19 10:05:04 +01:00

63 lines
1.5 KiB
JavaScript

/**
* 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.'
});
});
};