Skip to content
Snippets Groups Projects
Commit fd5cca78 authored by Vytor Calixto's avatar Vytor Calixto :space_invader:
Browse files

Add download middleware to school route

parent e4677112
No related branches found
No related tags found
1 merge request!116Release v1.0.0
Pipeline #
......@@ -20,6 +20,10 @@ const request = require(`request`);
const config = require(`${libs}/config`);
const passport = require('passport');
const download = require(`${libs}/middlewares/downloadDatabase`);
const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware;
let rqf = new ReqQueryFields();
......@@ -471,42 +475,6 @@ schoolApp.get('/count', cache('15 day'), rqfCount.parse(), rqfCount.build(), (re
next();
}, query, id2str.transform(), response('school'));
schoolApp.get('/count/download', (req, res, next) => {
// first, query the mapping
req.sql.from('mapping_escola')
.field('target_name')
.field('name');
next();
}, query, (req, res, next) => {
req.resetSql();
next();
}, rqfCount.parse(), rqfCount.build(), (req, res, next) => {
let username = req.query.user;
let email = req.query.email;
req.sql.from('escola').field('*');
let header = '';
req.result.forEach((result) => {
req.sql.field(result.name, result.target_name);
if(header === '') header += result.target_name;
else header = header + ';' + result.target_name;
});
let form = {
query: req.sql.toString(),
table: req.sql.tableFrom,
name: req.sql.tableFrom,
username,
email,
header
};
request.post(config.cdn.url + '/api/v1/file', {form}, (err, response, body) => {
if(err) {
log.error(err);
return res.json({error: err});
}
res.json({msg: 'Wait for download email'});
});
});
schoolApp.get('/count/download', passport.authenticate('bearer', { session: false }), rqfCount.parse(), rqfCount.build(), download('escola', 'mapping_escola'));
module.exports = schoolApp;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment