<commit_before>'use strict';


/**
 * Validate params fields
 * @param {apiService} service
 * @param {Object} params
 */
function validate(service, params)
{

    if (service.needRequiredFields(params, ['user', 'lastname', 'firstname', 'email'])) {
        return;
    }

    saveUser(service, params);
}





function saveAccount(service, params, user) {

    let AccountModel = service.app.db.models.Account;

    if (undefined === params.roles.account.notify) {
        return Promise.resolve(null);
    }

    let fieldsToSet = {
        notify: {
            approvals: params.roles.account.notify.approvals
        }
    };

    return AccountModel.findById(user.roles.account).exec()
    .then(account => {
        account.set(fieldsToSet);
        return account.save();
    });

}


/**
 * Update/create the user document<commit_msg>Fix password modification from account<commit_after>'use strict';


/**
 * Validate params fields
 * @param {apiService} service
 * @param {Object} params
 */
function validate(service, params)
{

    if (service.needRequiredFields(params, ['user', 'lastname', 'firstname', 'email'])) {
        return;
    }

    saveUser(service, params);
}





function saveAccount(service, params, user) {

    let AccountModel = service.app.db.models.Account;

    if (undefined === params.roles.account || undefined === params.roles.account.notify) {
        return Promise.resolve(null);
    }

    let fieldsToSet = {
        notify: {
            approvals: params.roles.account.notify.approvals
        }
    };

    return AccountModel.findById(user.roles.account).exec()
    .then(account => {
        account.set(fieldsToSet);
        return account.save();
    });

}


/**
 * Update/create the user document
{'fraction_non_alphanumeric': 0.13893653516295026, 'fraction_numerical': 0.0, 'mean_word_length': 2.8293216630196936, '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': '6867953', 'n_tokens_mistral': 528, 'n_tokens_neox': 505, 'n_words': 105}