<commit_before>var baucis = require('baucis'),
    page = require('./model');

var pageController = baucis.rest({
    singular:'Page', 
    select:'_type name route title label parentId path'
});

var getTree = function (request, response, next) {
    // Setting pageId to null finds root
    var pageId = request.params.id;

    var query = {};
    if (pageId) {
        query['_id'] = pageId;
    } else {
        query['_parentId'] = null;
    }

    page.model.findOne(query, function (err, doc) {

        doc.getTree(function (err, tree) {
            response.json({tree: tree});
        });
    });
};

pageController.get('/getTree/:id?', getTree);

module.exports = baucis({swagger:true});<commit_msg>Fix root query<commit_after>var baucis = require('baucis'),
    page = require('./model');

var pageController = baucis.rest({
    singular:'Page', 
    select:'_type name route title label parentId path'
});

var getTree = function (request, response, next) {
    // Setting pageId to null finds root
    var pageId = request.params.id;

    var query = {};
    if (pageId) {
        query['_id'] = pageId;
    } else {
        query['parentId'] = null;
    }

    page.model.findOne(query, function (err, doc) {
        doc.getTree(function (err, tree) {
            response.json({tree: tree});
        });
    });
};

pageController.get('/getTree/:id?', getTree);

module.exports = baucis({swagger:true});
{'fraction_non_alphanumeric': 0.15926708949964763, 'fraction_numerical': 0.0, 'mean_word_length': 2.817204301075269, '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': '1006486', 'n_tokens_mistral': 455, 'n_tokens_neox': 449, 'n_words': 107}