Skip to content

Instantly share code, notes, and snippets.

@hmpmarketing
Created October 3, 2018 13:07
Show Gist options
  • Save hmpmarketing/44a215f4052717f3ffab15b897ee090a to your computer and use it in GitHub Desktop.
Save hmpmarketing/44a215f4052717f3ffab15b897ee090a to your computer and use it in GitHub Desktop.
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