store json after every generate

This commit is contained in:
Thomas Ruoff
2018-02-01 01:23:58 +01:00
parent fda3df8df1
commit 9052c7b0eb
9 changed files with 3761 additions and 19 deletions

View File

@@ -3,8 +3,8 @@ const bodyParser = require('body-parser');
const app = express();
const templates = require('./templates');
const renderer = require('./renderer');
const {getPdfPath} = require('./utils');
const store = require('./store');
const { getPdfPath } = require('./utils');
app.use(bodyParser.json());
@@ -15,6 +15,15 @@ app.post('/api/pdf/generate/:template', (req, res) => {
templates.get(templateName, options)
.then(renderer)
.then(id => {
const storeData = Object.assign({}, options, {
id,
created: new Date().toISOString()
});
return store
.add(storeData)
.then(() => id);
})
.then(id => {
res.send({id: id});
res.end();
@@ -25,6 +34,14 @@ app.post('/api/pdf/generate/:template', (req, res) => {
});
});
app.get('/api/pdf/latest', (req, res) => {
store
.list()
.then(results => res.json(results))
.catch(err => res.sendStatus(500).end(err));
});
app.options('/api/pdf/:id');
app.get('/api/pdf/:id', (req, res) => {
const {id} = req.params;