<commit_before>'use strict';

let helpers = require('../helpers'),
    Mail = require('../config/mail');

module.exports = function (data) {
    return {
        getAll(req, res) {
            data.getAllOrganizations()
                .then((result) => {
                    return res.status(200).json(result);
                });
        },
        getById(req, res) {
            let id = req.params.id;

            data.getOrganizationById(id)
                .then((result) => {
                    return res.status(200).json(result);
                });
        },
        getByUser(req, res) {
            let id = req.user._id;

            data.getOrganizationsByUserId(id)
                .then((result) => {
                    return res.status(200).json(result);
                });
        },
        create(req, res, next) {
            let organization = req.body;

            data.createOrganization(organization)
                .then((organization) => {
                    return res.status(201).json({
                        success: true,
                        organization: organization,
                        message: 'Organization created!'
                    });
                })
                .catch(errors => {
                    res.status(400)
                        .json({
                            success: false,
                            validationErrors: helpers.errorHelper(errors)
                        });
                });
        },
        addMember(req, res, next) {
            let organizationId = req.params.id,
                userData = req.body;

            // Generate random password for the new member
            userData.password = helpers.utilsHelper.generateRandomPassword();

            // Set member role
            userData.role = 'member';

            return Promise.resolve()
                .then(() => {
                    return data.createUser(userData); 
                })
                .then((user) => {
                    let options = {
                        to: '<EMAIL>',
                        subject: 'Your theSlyfer account has been created',
                        message: `Credentials: username ${user.email} password: ${<PASSWORD>}`<commit_msg>fixed email for new members<commit_after>'use strict';

let helpers = require('../helpers'),
    Mail = require('../config/mail');

module.exports = function (data) {
    return {
        getAll(req, res) {
            data.getAllOrganizations()
                .then((result) => {
                    return res.status(200).json(result);
                });
        },
        getById(req, res) {
            let id = req.params.id;

            data.getOrganizationById(id)
                .then((result) => {
                    return res.status(200).json(result);
                });
        },
        getByUser(req, res) {
            let id = req.user._id;

            data.getOrganizationsByUserId(id)
                .then((result) => {
                    return res.status(200).json(result);
                });
        },
        create(req, res, next) {
            let organization = req.body;

            data.createOrganization(organization)
                .then((organization) => {
                    return res.status(201).json({
                        success: true,
                        organization: organization,
                        message: 'Organization created!'
                    });
                })
                .catch(errors => {
                    res.status(400)
                        .json({
                            success: false,
                            validationErrors: helpers.errorHelper(errors)
                        });
                });
        },
        addMember(req, res, next) {
            let organizationId = req.params.id,
                userData = req.body;

            // Generate random password for the new member
            userData.password = <PASSWORD>();

            // Set member role
            userData.role = 'member';

            return Promise.resolve()
                .then(() => {
                    return data.createUser(userData); 
                })
                .then((user) => {
                    let options = {
                        to: `${user.email}`,
                        subject: 'Your theSlyfer account has been created',
                        message: `Credentials: username ${user.email} password: ${<PASSWORD>}`
{'fraction_non_alphanumeric': 0.11401952085181899, 'fraction_numerical': 0.006654835847382431, 'mean_word_length': 1.0913729128014842, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, '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': '6604759', 'n_tokens_mistral': 1115, 'n_tokens_neox': 1026, 'n_words': 211}