{"size": 1191, "ext": "js", "max_stars_repo_path": "src/server/lib/clans/lib/modify.js", "max_stars_repo_name": "sean3z/cncnet-api", "max_stars_repo_stars_event_min_datetime": "2016-03-21T21:00:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-05T01:41:38.000Z", "max_issues_repo_path": "src/server/lib/clans/lib/modify.js", "max_issues_repo_name": "sean3z/cncnet-api", "max_issues_repo_issues_event_min_datetime": "2016-07-10T21:40:51.000Z", "max_issues_repo_issues_event_max_datetime": "2017-04-02T14:35:38.000Z", "max_forks_repo_path": "src/server/lib/clans/lib/modify.js", "max_forks_repo_name": "sean3z/cncnet-api", "max_forks_repo_forks_event_min_datetime": "2016-02-12T20:09:35.000Z", "max_forks_repo_forks_event_max_datetime": "2017-04-01T18:12:33.000Z"}
{"max_stars_count": 11, "max_issues_count": 17, "max_forks_count": 2, "avg_line_length": 32.1891891892, "max_line_length": 80, "alphanum_fraction": 0.5709487825}
var debug = require('debug')('wol:leaderboard');
var $db = require(global.cwd + '/lib/mongo');
var _sanitize = require(global.cwd + '/lib/player/lib/sanitize');

module.exports = function modify(game, clan, options) {
    var player = (options.player || '').toLowerCase();
    delete options.player;

    var $clans = $db.get(game +'_clans');

    return new Promise(function(resolve, reject) {
        $clans.findOne({name: _sanitize(clan, true)}, function(err, clan_data) {
            if (!clan_data) return reject();

            // ensure player is founder of clan
            if (clan_data.founder !== player) return reject();

            // disallow certain changes
            delete options.name;
            delete options.nam;
            delete options.created;
            delete options.points;
            delete options.games;
            delete options.members;
            delete options.founder;

            // TODO: allow clan founders to kick members
            // TODO: allow clan founder to change founder

            $clans.update({name: _sanitize(clan, true)}, {
                $set: options
            });

            return resolve();
        });
    });
};