<commit_before>'use strict';

let express = require('express');
let mongoose = require('mongoose');

let Response = require('../response');

let router = express.Router();

router.get('/users', (req, res) => {
    mongoose.model('User').aggregate([{
        $group : {_id: '_id', users : {$sum : 1}}
    }], (err, result) => {
        if (err){
            return Response.selectError(res, err);
        }

        Response.success(res, 'Statistics of users', {
            users: result[0].users
        });
    });
});

router.get('/teams', (req, res) => {
    mongoose.model('Team').aggregate([{
        $group : {_id: '_id', teams : {$sum : 1}}
    }], (err, result) => {
        if (err){
            return Response.selectError(res, err);
        }

        Response.success(res, 'Statistics of teams', {
            teams: result[0].teams
        });
    });
});

module.exports = router;<commit_msg>fix(server): Fix GET /statistics/users and /statistics/teams when there's no user/team<commit_after>'use strict';

let express = require('express');
let mongoose = require('mongoose');

let Response = require('../response');

let router = express.Router();

router.get('/users', (req, res) => {
    mongoose.model('User').aggregate([{
        $group : {_id: '_id', users : {$sum : 1}}
    }], (err, result) => {
        if (err){
            return Response.selectError(res, err);
        }
        if (!result[0] || !result[0].users){
            return Response.notFound(res, 'users');
        }

        Response.success(res, 'Statistics of users', {
            users: result[0].users
        });
    });
});

router.get('/teams', (req, res) => {
    mongoose.model('Team').aggregate([{
        $group : {_id: '_id', teams : {$sum : 1}}
    }], (err, result) => {
        if (err){
            return Response.selectError(res, err);
        }

        if (!result[0] || !result[0].teams){
            return Response.notFound(res, 'teams');
        }

        Response.success(res, 'Statistics of teams', {
            teams: result[0].teams
        });
    });
});

module.exports = router;
{'fraction_non_alphanumeric': 0.19362511893434825, 'fraction_numerical': 0.005708848715509039, 'mean_word_length': 2.317034700315457, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '344275', 'n_tokens_mistral': 663, 'n_tokens_neox': 657, 'n_words': 144}