{"size": 1508, "ext": "js", "max_stars_repo_path": "db/schemes.js", "max_stars_repo_name": "reubinoff/voting_app", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "db/schemes.js", "max_issues_repo_name": "reubinoff/voting_app", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "db/schemes.js", "max_forks_repo_name": "reubinoff/voting_app", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.5625, "max_line_length": 83, "alphanum_fraction": 0.5384615385}
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
const bcrypt = require('bcrypt')

const min_options_prt_poll = 2

module.exports.poll_scheme = new Schema({
    user: { type: String, required: true },
    name: { type: String, required: true },
    options: [{
        type: String,
        required: true,
        validate: [arrayLimit, '{PATH} under the limit of ' + min_options_prt_poll]
    }],
    results: [{
        type: String
    }],
})

user_model = new Schema({
    local            : {
        email        : String,
        password     : String,
    },
    facebook         : {
        id           : String,
        token        : String,
        email        : String,
        name         : String
    },
    twitter          : {
        id           : String,
        token        : String,
        displayName  : String,
        username     : String
    },
    google           : {
        id           : String,
        token        : String,
        email        : String,
        name         : String
    }
})

// methods ======================
// generating a hash
user_model.methods.generateHash = function(password) {
    return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
};

// checking if password is valid
user_model.methods.validPassword = function(password) {
    return bcrypt.compareSync(password, this.local.password);
};


function arrayLimit(val) {
    return val.length >= min_options_prt_poll;
}

module.exports.user_model = user_model


