Created
October 3, 2018 13:07
-
-
Save hmpmarketing/44a215f4052717f3ffab15b897ee090a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
knex('campaigns') | |
.leftJoin('campaign_plays', function() { | |
this.on('campaigns.id', '=','campaign_plays.campaign_id') | |
.on('campaign_plays.campaign_date', '=', knex.raw('?', [today])) | |
}) | |
.where('campaigns.start_date', '<=', today) | |
.where('campaigns.end_date', '>=', today) | |
.where('campaigns.status', '=', 'RUNNING') | |
.whereRaw('IFNULL(campaign_plays.play_count, 0) < campaigns.daily_goal') | |
.count('id as count') | |
.then(function(count){ | |
if(count[0].count>0) return res.json({keep_playing:false,msg:`0 Campaigns Running.`}) | |
}) | |
knex('proxies') | |
.innerJoin('b_proxies', function() { | |
this.on('proxies.id', '=','b_proxies.proxy_id') | |
}) | |
.where('b_id', '=', req.params.b_id) | |
.whereRaw('last_tested < now() - interval 60 minute') | |
.count('proxies.id as count') | |
.then(function(count){ | |
if(count[0].count==0) return res.json({keep_playing:false,msg:`Proxy has not gone throught test for more than 1h.`}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment