diff --git a/src/libs/routes/api.js b/src/libs/routes/api.js index 898d565cb878074908452fe6e46477f37f757b20..2e7c9a3efd4267a6e75f5e53ed187eebde464e2a 100644 --- a/src/libs/routes/api.js +++ b/src/libs/routes/api.js @@ -6,8 +6,6 @@ const libs = `${process.cwd()}/libs`; const config = require(`${libs}/config`); -const log = require(`${libs}/log`)(module); - const classes = require('./class'); const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware; @@ -32,24 +30,6 @@ const classroom = require('./classroom'); const teacher = require('./teacher'); -const workerpool = require('workerpool'); - -const pool = workerpool.pool(); - -function add(a, b) { - return a+b; -} - -api.get('/add', (req, res) => { - pool.exec(add, [3,4]) - .then((result) => { - log.debug('result'); - log.debug(result); - pool.clear(); - }); - res.json({msg: 'Está sendo feito'}); -}); - api.get('/', (req, res) => { res.json({ msg: 'SimCAQ API is running' }); }); diff --git a/src/libs/routes/region.js b/src/libs/routes/region.js index a752fa1b6169522d1f2f0983f3c4b7d94748f551..a6263ddf7cebadaab98d34fd3e5366c0bbc02cd8 100644 --- a/src/libs/routes/region.js +++ b/src/libs/routes/region.js @@ -4,6 +4,8 @@ const regionApp = express.Router(); const libs = `${process.cwd()}/libs`; +const log = require(`${libs}/log`)(module); + const squel = require('squel'); const query = require(`${libs}/middlewares/query`); @@ -51,4 +53,36 @@ regionApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { next(); }, query, response('region')); +const workerpool = require('workerpool'); +const pool = workerpool.pool(); +const execQuery = require(`${libs}/db/query_exec`); + +function add(a, b) { + return a+b; +} + +function download(query) { + console.log(query); + // return add(3,4); + // return execQuery(query.text, query.values); + return new Promise(function (resolve, reject) { + setTimeout(function () { + resolve(3 + 4); + }, 1000); + }); +} + +regionApp.get('/download', (req, res) => { + req.sql.from('regiao').field('*'); + let params = req.sql.toParam(); + pool.exec(download, [params]) + .then((result) => { + console.log('PEPO'); + log.debug('RESULT'); + log.debug(result); + pool.clear(); + }); + res.json({msg: 'Wait for it...'}); +}); + module.exports = regionApp;