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(() => {
return db.Tor.findAll({
attributes: ['address', 'fingerprint'],
})
.map(el => el.get({ plain: true }));
raw: true,
});
})
.then( result => {
logger.debug('number of records', result.length);

View file

@ -1,23 +1,32 @@
const logger = require('winston');
function ipIsInTorList (ip) {
return true;
}
const db = require('../models');
const torCheck = ({ ip, headers, body }, res, next) => {
logger.debug(`tor check for:`, {
ip,
headers,
body,
});
// check the tor node list
if (ipIsInTorList(ip)) {
return res.status('400').json({
logger.debug(`tor check for: ${ip}`);
return db.Tor.findAll(
{
where: {
address: ip,
},
raw: true,
})
.then(result => {
logger.debug('tor check results:', result);
if (result.length >= 1) {
logger.debug('this is a tor ip');
const failureResponse = {
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.',
});
}
};
return res.status(400).json(failureResponse);
} else {
logger.debug('this is not a tor ip');
return next();
}
})
.catch(error => {
logger.error(error);
});
};
module.exports = torCheck;