<commit_before>'use strict';

const log = require('../lib/logger');
const express = require('express');
const router = express.Router();
const cel = require('connect-ensure-login');
const mongoose = require('mongoose');

const dbTeam = require('../lib/db/Team');

const Team = mongoose.model('Team');
const User = mongoose.model('User');
const Event = mongoose.model('Event');
const TeamUser = mongoose.model('TeamUser');
const TeamEvent = mongoose.model('TeamEvent');
const Invoice = mongoose.model('Invoice');

module.exports = router;

router.param('id', async function (req, res, next){
    const id = req.params.id;

    console.log("Team id=",id);
    try {
        let r = await Team.findById(id);

        if (r) {
            console.log("Team id=", r.id, " name=", r.name);

            if (req.user) {
                let q = {teamId: id, userId: req.user.id, role: 'coach'};
                let tu = await TeamUser.findOne(q);
                if (tu) {
                    console.log('User is team coach');
                    req.user.isCoach = true;
                }
            } else {
                req.user = {isCoach:false};
            }

            r = await dbTeam.getTeamDetails(req.user, id);
            req.team = r;

        } else {
            console.log('team not found ',id);
            throw new Error("team not found");
        }
        next();
    } catch (err) {
        res.render('message',{title:"Tím nenájdený",error:{status:err.message}});
    }

});

router.get('/', cel.ensureLoggedIn('/login'), async function (req, res, next) {
    const cmd = req.query.cmd;
    const progId = req.query.programId;
    console.log("/team - get");
    console.log(req.query);

    var r = {result:"error", status:200};
    try {
        switch (cmd) {
            case 'getList':
                console.log('Going to get list of teams');
                let q = {};
                if (progId)
                    q.programId = progId;

                const tc = await Team.find(q,{name:1, programId:1, foundingOrg:1, foundingAdr:1});
                r.result = "ok";
                r.list = tc;
                break;

            default:
                console.log('cmd=unknown');

        }
    } catch(err) {
        r.error = {message:err.message};
        log.ERROR(err);
    }
    res.json(r);
    res.end();

});
<commit_msg>showing active teams only<commit_after>'use strict';

const log = require('../lib/logger');
const express = require('express');
const router = express.Router();
const cel = require('connect-ensure-login');
const mongoose = require('mongoose');

const dbTeam = require('../lib/db/Team');

const Team = mongoose.model('Team');
const User = mongoose.model('User');
const Event = mongoose.model('Event');
const TeamUser = mongoose.model('TeamUser');
const TeamEvent = mongoose.model('TeamEvent');
const Invoice = mongoose.model('Invoice');

module.exports = router;

router.param('id', async function (req, res, next){
    const id = req.params.id;

    console.log("Team id=",id);
    try {
        let r = await Team.findById(id);

        if (r) {
            console.log("Team id=", r.id, " name=", r.name);

            if (req.user) {
                let q = {teamId: id, userId: req.user.id, role: 'coach'};
                let tu = await TeamUser.findOne(q);
                if (tu) {
                    console.log('User is team coach');
                    req.user.isCoach = true;
                }
            } else {
                req.user = {isCoach:false};
            }

            r = await dbTeam.getTeamDetails(req.user, id);
            req.team = r;

        } else {
            console.log('team not found ',id);
            throw new Error("team not found");
        }
        next();
    } catch (err) {
        res.render('message',{title:"Tím nenájdený",error:{status:err.message}});
    }

});

router.get('/', cel.ensureLoggedIn('/login'), async function (req, res, next) {
    const cmd = req.query.cmd;
    const progId = req.query.programId;
    console.log("/team - get");
    console.log(req.query);

    var r = {result:"error", status:200};
    try {
        switch (cmd) {
            case 'getList':
                console.log('Going to get list of teams');
                let q = {recordStatus:'active'};
                if (progId)
                    q.programId = progId;

                const tc = await Team.find(q,{name:1, programId:1, foundingOrg:1, foundingAdr:1});
                r.result = "ok";
                r.list = tc;
                break;

            default:
                console.log('cmd=unknown');

        }
    } catch(err) {
        r.error = {message:err.message};
        log.ERROR(err);
    }
    res.json(r);
    res.end();

});

{'fraction_non_alphanumeric': 0.15630885122410546, 'fraction_numerical': 0.002929483155471856, 'mean_word_length': 1.8657074340527577, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1409925', 'n_tokens_mistral': 1489, 'n_tokens_neox': 1444, 'n_words': 336}