<commit_before>var User = require('../models/user.js').model;

exports.allUsers = function (req, res) {
    User.find({}, function (err, docs) {
            if (!err) {
                var users = [];
                for (var i = 0; i < docs.length; i++) {
                    users.push(docs[i].toDTO());
                }
                res.status(200).send(users);
            } else {
                console.error(err);
                res.status(500).send(err);
            }
        }
    );
};

exports.findById = function (req, res) {
    User.findById(req.params.id, function (err, user) {
        if (!err) {
            if (user) {
                res.status(200).send(user.toDTO(true));
            } else {
                res.status(404).send({
                    errorCode: 'USER_NOT_FOUND',
                    message: 'User ' + req.params.id + ' was not found'
                });
            }
        } else {
            console.error(err);
            if (err.name === 'CastError') {
                res.status(404).send({
                    errorCode: 'USER_NOT_FOUND',
                    message: 'User ' + req.params.id + ' was not found'
                });
            } else {
                res.status(500).send(err);
            }
        }
    });
};

exports.findByName = function (req, res) {
    var name = req.query.q;
    User.find({
        name: new RegExp(name, 'i')
    }, function (err, users) {
        if (!err) {
            if (users) {
                var formattedUsers = [];
                for (var i = 0; i < users.length; i++) {
                    formattedUsers.push(users[i].toDTO(true));
                }
                res.status(200).send(formattedUsers);
            } else {
                res.status(404).send({
                    errorCode: 'USER_NOT_FOUND',
                    message: 'User ' + req.params.id + ' was not found'
                });
            }
        } else {
            console.error(err);
            if (err.name === 'CastError') {
                res.status(404).send({
                    errorCode: 'USER_NOT_FOUND',
                    message: 'User ' + req.params.id + ' was not found'
                });<commit_msg>! Quick fix to prevent ubeat crash....<commit_after>var User = require('../models/user.js').model;

exports.allUsers = function (req, res) {
    User.find({}, function (err, docs) {
            if (!err) {
                var users = [];
                for (var i = 0; i < docs.length; i++) {
                    users.push(docs[i].toDTO());
                }
                res.status(200).send(users);
            } else {
                console.error(err);
                res.status(500).send(err);
            }
        }
    );
};

exports.findById = function (req, res) {
    try {
        User.findById(req.params.id, function (err, user) {
            if (!err) {
                if (user) {
                    res.status(200).send(user.toDTO(true));
                } else {
                    res.status(404).send({
                        errorCode: 'USER_NOT_FOUND',
                        message: 'User ' + req.params.id + ' was not found'
                    });
                }
            } else {
                console.error(err);
                if (err.name === 'CastError') {
                    res.status(404).send({
                        errorCode: 'USER_NOT_FOUND',
                        message: 'User ' + req.params.id + ' was not found'
                    });
                } else {
                    res.status(500).send(err);
                }
            }
        });
    } catch (e) {
        console.log(e);
    }
    
};

exports.findByName = function (req, res) {
    var name = req.query.q;
    User.find({
        name: new RegExp(name, 'i')
    }, function (err, users) {
        if (!err) {
            if (users) {
                var formattedUsers = [];
                for (var i = 0; i < users.length; i++) {
                    formattedUsers.push(users[i].toDTO(true));
                }
                res.status(200).send(formattedUsers);
            } else {
                res.status(404).send({
                    errorCode: 'USER_NOT_FOUND',
                    message: 'User ' + req.params.id + ' was not found'
                });
            }
        } else {
            console.error(err);
            if (err.name === 'CastError') {
                res.status(404).send({
                    errorCode: 'USER_NOT_FOUND',
                    message: 'User ' + req.params.id + ' was not found'
                });
{'fraction_non_alphanumeric': 0.14146447140381282, 'fraction_numerical': 0.012564991334488735, 'mean_word_length': 1.0957784838856106, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '2431611', 'n_tokens_mistral': 1373, 'n_tokens_neox': 1268, 'n_words': 250}