<commit_before>'use strict';

var router = require('express').Router();
var Lecture = require('../models/model_lecture');

// on routes that end in /rooms
router.route('/')

    /*
     * Returns all rooms, if free or not doesn't matter.
     */
    .get(function(req, res) {
        // querys for all rooms and aggregate to one doc
        Lecture.aggregate([ { $unwind: '$rooms' }, { $group: { _id: 'rooms', rooms: { $addToSet: '$rooms' } } } ]).exec(function(err, rooms) {
            if (err) { res.status(500).send(err); }
            res.status(200).json(rooms[0].rooms);
            res.end();
        });
    });

// on routes that end in /rooms/free
router.route('/free')

    /*
     * Returns all rooms, which are based on our information, should be free.
     */
    .get(function(req, res, next) {

        // get all rooms (in db)
        Lecture.aggregate([ { $unwind: '$rooms' }, { $group: { _id: 'rooms', rooms: { $addToSet: '$rooms' } } } ]).exec(function(err, rooms) {
            if (err) { next(err); return; }

            // get rooms currently in use
            Lecture.aggregate([ { $match: { startTime: { '$lte': new Date() }, endTime: { '$gte': new Date() } } }, { $unwind: '$rooms' }, { $group: { _id: 'rooms', rooms: { $addToSet: '$rooms' } } } ]).exec(function(err, usedRooms) {
                if (err) { next(err); return; }

                // filter used rooms by comparing both arrays
                var freeRooms;
                if(usedRooms[0] && usedRooms[0].rooms) {
                    freeRooms = rooms[0].rooms.filter(function(e) {
                        if(e) {
                            return (e.match(/\d\/\d\d\d ?.*/) && usedRooms[0].rooms.indexOf(e) < 0);
                        }
                    });
                } else {
                    // all rooms free
                    freeRooms = rooms[0].rooms;
                }

                res.status(200).json(freeRooms);
                res.end();
            });
        });
    });

module.exports = router;
<commit_msg>rooms: sorte the free rooms<commit_after>'use strict';

var router = require('express').Router();
var Lecture = require('../models/model_lecture');

// on routes that end in /rooms
router.route('/')

    /*
     * Returns all rooms, if free or not doesn't matter.
     */
    .get(function(req, res) {
        // querys for all rooms and aggregate to one doc
        Lecture.aggregate([ { $unwind: '$rooms' }, { $group: { _id: 'rooms', rooms: { $addToSet: '$rooms' } } } ]).exec(function(err, rooms) {
            if (err) { res.status(500).send(err); }
            res.status(200).json(rooms[0].rooms);
            res.end();
        });
    });

// on routes that end in /rooms/free
router.route('/free')

    /*
     * Returns all rooms, which are based on our information, should be free.
     */
    .get(function(req, res, next) {

        // get all rooms (in db)
        Lecture.aggregate([ { $unwind: '$rooms' }, { $group: { _id: 'rooms', rooms: { $addToSet: '$rooms' } } } ]).exec(function(err, rooms) {
            if (err) { next(err); return; }

            // get rooms currently in use
            Lecture.aggregate([ { $match: { startTime: { '$lte': new Date() }, endTime: { '$gte': new Date() } } }, { $unwind: '$rooms' }, { $group: { _id: 'rooms', rooms: { $addToSet: '$rooms' } } } ]).exec(function(err, usedRooms) {
                if (err) { next(err); return; }

                // filter used rooms by comparing both arrays
                var freeRooms;
                if(usedRooms[0] && usedRooms[0].rooms) {
                    freeRooms = rooms[0].rooms.filter(function(e) {
                        if(e) {
                            return (e.match(/\d\/\d\d\d ?.*/) && usedRooms[0].rooms.indexOf(e) < 0);
                        }
                    });
                } else {
                    // all rooms free
                    freeRooms = rooms[0].rooms;
                }

                // js sorting, maybe do it on mongo
                freeRooms = freeRooms.sort();

                res.status(200).json(freeRooms);
                res.end();
            });
        });
    });

module.exports = router;

{'fraction_non_alphanumeric': 0.17052229906987837, 'fraction_numerical': 0.0076317672310994514, 'mean_word_length': 1.6544303797468354, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6669417', 'n_tokens_mistral': 1325, 'n_tokens_neox': 1254, 'n_words': 313}