<commit_before>var config = require(__dirname + '/../config/config'),
    logger = require(__dirname + '/../lib/logger'),
	util = require(__dirname + '/../helpers/util'),
	as_helper = require(__dirname + '/../helpers/auth_server'),
	Channel_earnings = require(__dirname + '/../helpers/channel_earnings'),
    qs = require('querystring'),
    http = require('http'),
	mysql = require(__dirname + '/../lib/mysql'),
	mongo = require(__dirname + '/../lib/mongoskin');

exports.get_channel_earnings = function (req, res, next) {
	var data = util.get_data([
			'report_id'
		], [], req.query),
		scopes = 'payout.view',
		report_ids = [],
		earnings,
		done = function(err, _data) {
			if (err) return next(err);
			res.send(_data);
		},
		get_earnings = function (err, _data) {
			if (err) return next(err);
			if(!_data.user_data[config.app_id+'_data'].channels_owned) return res.send({});
			req.query.report_id.split(',').forEach(function (ri) {
				if (ri.trim() !== '')
					report_ids.push(ri.trim());
			});
			earnings = new Channel_earnings (report_ids, _data.user_data[config.app_id + '_data'].channels_owned ,done).get_earnings();
		},
		get_user_info = function (status, _data) {
			if (status !== 200) return next(_data);
			if (req.query.user_id)
				as_helper.get_info({access_token:req.access_token, user_id:req.query.user_id}, get_earnings);
			else
				as_helper.get_info({access_token:req.access_token, self:true}, get_earnings);
		};

	if (typeof data === 'string')
		return next(data);
	if (!req.access_token)
		return next('Missing access_token');

	// to be used by other calling function, 
	if (res === null)
		return as_helper.get_info({access_token:req.access_token, user_id:req.user_id}, get_earnings);

	req.query.user_id && (scopes = 'payout.view, admin.view_all');
	as_helper.has_scopes(req.access_token, scopes, get_user_info, next);

};

exports.net_networks_earnings = function (req, res, next) {


};

exports.get_recruiter_earnings = function (req, res ,next) {

	var data = util.get_data([
			'report_id'
		], [], req.query),
		scopes = 'payout.view',
		report_ids = [],
		earnings,
		done = function(err, _data) {
			if (err) return next(err);
			res.send(_data);
		},
		get_earnings = function (err, _data) {
			if (err) return next(err);			
			if (_data.length === 0) 
				return res.send([]);
			req.query.report_id.split(',').forEach(function (ri) {
				if (ri.trim() !== '')
					report_ids.push(ri.trim());
			});
			earnings = new Channel_earnings (report_ids, _data.map( function (a) { return a._id }), done).get_earnings();
		},
		get_recruited_channels = function (err, _data) {
			if (err) return next(err);
			mysql.open(config.db_freedom)
				.query('SELECT _id, recruiter, recruited_date from channel where recruiter = ? and partnership_status and recruited_date is not null and recruited_date > ?', [_data.user_data._id, +new Date() - 31556926000 ], get_earnings)<commit_msg>fixed some stuff<commit_after>var config = require(__dirname + '/../config/config'),
    logger = require(__dirname + '/../lib/logger'),
	util = require(__dirname + '/../helpers/util'),
	as_helper = require(__dirname + '/../helpers/auth_server'),
	Channel_earnings = require(__dirname + '/../helpers/channel_earnings'),
    qs = require('querystring'),
    http = require('http'),
	mysql = require(__dirname + '/../lib/mysql'),
	mongo = require(__dirname + '/../lib/mongoskin');

exports.get_channel_earnings = function (req, res, next) {
	var data = util.get_data([
			'report_id'
		], [], req.query),
		scopes = 'payout.view',
		report_ids = [],
		earnings,
		done = function(err, _data) {
			if (err) return next(err);
			res.send(_data);
		},
		get_earnings = function (err, _data) {
			if (err) return next(err);
			if(!_data.user_data[config.app_id+'_data'].channels_owned) return res.send({});
			req.query.report_id.split(',').forEach(function (ri) {
				if (ri.trim() !== '')
					report_ids.push(ri.trim());
			});
			earnings = new Channel_earnings (report_ids, _data.user_data[config.app_id + '_data'].channels_owned ,done).get_earnings();
		},
		get_user_info = function (status, _data) {
			if (status !== 200) return next(_data);
			if (req.query.user_id)
				as_helper.get_info({access_token:req.access_token, user_id:req.query.user_id}, get_earnings);
			else
				as_helper.get_info({access_token:req.access_token, self:true}, get_earnings);
		};

	if (typeof data === 'string')
		return next(data);
	if (!req.access_token)
		return next('Missing access_token');

	// to be used by other calling function, 
	if (res === null)
		return as_helper.get_info({access_token:req.access_token, user_id:req.user_id}, get_earnings);

	req.query.user_id && (scopes = 'payout.view, admin.view_all');
	as_helper.has_scopes(req.access_token, scopes, get_user_info, next);

};

exports.net_networks_earnings = function (req, res, next) {


};

exports.get_recruiter_earnings = function (req, res ,next) {

	var data = util.get_data([
			'report_id'
		], [], req.query),
		scopes = 'payout.view',
		report_ids = [],
		earnings,
		done = function (err, _data) {
			if (err) return next(err);
			res.send(_data);
		},
		get_earnings = function (err, _data) {
			if (err) return next(err);			
			if (_data.length === 0) 
				return res.send([]);
			req.query.report_id.split(',').forEach(function (ri) {
				if (ri.trim() !== '')
					report_ids.push(ri.trim());
			});
			earnings = new Channel_earnings (report_ids, _data.map( function (a) { return a._id }), done).get_earnings();
		},
		get_recruited_channels = function (err, _data) {
			if (err) return next(err);
			mysql.open(config.db_freedom)
				.query('SELECT _id, recruiter, recruited_date from channel where recruiter = ? and partnership_status and recruited_date is not null and recruited_date > ?', [_data.user_data._id, +new Date() - 31556926000 ], get_earnings)
{'fraction_non_alphanumeric': 0.16963064295485636, 'fraction_numerical': 0.005129958960328317, 'mean_word_length': 4.148767605633803, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2450657', 'n_tokens_mistral': 2263, 'n_tokens_neox': 2039, 'n_words': 418}