<commit_before>/////////////////////////////////////////
// Send a mail with all user's tickets //
/////////////////////////////////////////

'use strict';

module.exports = function (db, config) {
    return function (req, res) {
        var logger = require('../../lib/log')(config);
        var mailer = require('../../lib/mailer')(config);
        var rest   = require('../../lib/rest')(config, logger);

        // Get username from mail
        rest.get('users?mail=' + req.params.mail).success(function (user) {
            if (!user) {
                return Error.emit(res, 400, '400 - Bad Request', 'No mail');
            }

            var username = user.id;

            // Get tickets
            db.Ticket.findAll({
                where: {
                    username: username
                }
            }).done(function (err, tickets) {
                if (err) {
                    return Error.emit(res, 500, '500 - SQL Server error', err);
                }

                if (!tickets) {
                    res.status(404);
                    res.end();
                    return;
                }

                var places = {};
                var todo = tickets.length;
                tickets.forEach(function (ticket) {
                    ticket.getEvent().then(function (event) {
                        --todo;

                        places[event.name] = 'http//www.google.fr/';

                        if (todo === 0) {
                            mailer.places('<EMAIL>', places);
                            res.json({
                                status: 200
                            });
                        }
                    }, function (err) {
                        console.log(err);
                    });
                });
            });
        }).error(function () {
            Error.emit(res, 500, '500 - Buckutt server error', 'Get mail');
        });
    };
};
<commit_msg>Use callback<commit_after>/////////////////////////////////////////
// Send a mail with all user's tickets //
/////////////////////////////////////////

'use strict';

module.exports = function (db, config) {
    return function (req, res) {
        var logger = require('../../lib/log')(config);
        var mailer = require('../../lib/mailer')(config);
        var rest   = require('../../lib/rest')(config, logger);

        // Get username from mail
        rest.get('users?mail=' + req.params.mail).success(function (user) {
            if (!user) {
                return Error.emit(res, 400, '400 - Bad Request', 'No mail');
            }

            var username = user.id;

            // Get tickets
            db.Ticket.findAll({
                where: {
                    username: username
                }
            }).done(function (err, tickets) {
                if (err) {
                    return Error.emit(res, 500, '500 - SQL Server error', err);
                }

                if (!tickets) {
                    res.status(404);
                    res.end();
                    return;
                }

                var places = {};
                var todo = tickets.length;
                tickets.forEach(function (ticket) {
                    ticket.getEvent().then(function (event) {
                        --todo;

                        places[event.name] = 'http//www.google.fr/';

                        if (todo === 0) {
                            mailer.places(req.params.mail, places, function (okay) {
                                if (!okay) {
                                    return Error.emit(res, 500, '500 - Could\'t send mail');
                                }

                                res.json({
                                    status: 200
                                });
                            });
                        }
                    }, function (err) {
                        console.log(err);
                    });
                });
            });
        }).error(function () {
            Error.emit(res, 500, '500 - Buckutt server error', 'Get mail');
        });
    };
};

{'fraction_non_alphanumeric': 0.16566192428261395, 'fraction_numerical': 0.013503737641668677, 'mean_word_length': 0.8534405719392315, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2210219', 'n_tokens_mistral': 1063, 'n_tokens_neox': 942, 'n_words': 220}