fixed findall raw query

This commit is contained in:
bill bittner 2018-06-27 17:56:28 -07:00
parent a3df219684
commit aed4e05b24
2 changed files with 27 additions and 18 deletions

View file

@ -32,8 +32,8 @@ const getTorList = (req, res) => {
.then(() => { .then(() => {
return db.Tor.findAll({ return db.Tor.findAll({
attributes: ['address', 'fingerprint'], attributes: ['address', 'fingerprint'],
}) raw: true,
.map(el => el.get({ plain: true })); });
}) })
.then( result => { .then( result => {
logger.debug('number of records', result.length); logger.debug('number of records', result.length);

View file

@ -1,23 +1,32 @@
const logger = require('winston'); const logger = require('winston');
const db = require('../models');
function ipIsInTorList (ip) {
return true;
}
const torCheck = ({ ip, headers, body }, res, next) => { const torCheck = ({ ip, headers, body }, res, next) => {
logger.debug(`tor check for:`, { logger.debug(`tor check for: ${ip}`);
ip, return db.Tor.findAll(
headers, {
body, where: {
}); address: ip,
// check the tor node list },
if (ipIsInTorList(ip)) { raw: true,
return res.status('400').json({ })
.then(result => {
logger.debug('tor check results:', result);
if (result.length >= 1) {
logger.debug('this is a tor ip');
const failureResponse = {
success: 'false', success: 'false',
message: 'Unfortunately this api route is not currently available for tor users. We are working on a solution that will allow tor users to use this endpoint in the future.', message: 'Unfortunately this api route is not currently available for tor users. We are working on a solution that will allow tor users to use this endpoint in the future.',
}); };
} return res.status(400).json(failureResponse);
} else {
logger.debug('this is not a tor ip');
return next(); return next();
}
})
.catch(error => {
logger.error(error);
});
}; };
module.exports = torCheck; module.exports = torCheck;