var express = require('express');
var router = express.Router();

//var mongoose = require('mongoose');
var TestCase = require('../models/TestCase.js');

/* GET /testcases listing. */
router.get('/', function (req, res, next) {
    var query = TestCase.find();

    if (req.query.name) {
        query.where("name").equals(req.query.name)
    }
    if (req.query.status) {
        query.where("status").equals(req.query.status)
    }
    if (req.query.tags) {
        var tags = req.query.tags.split(/[, ]/);
        for ( var i = 0; i < tags.length; i++){
            query.where("tags").equals(tags[i])
        }
    }
    if (req.query.job_name) {
        query.where("job_name").equals(req.query.job_name)
    }
    if (req.query.build_id) {
        query.where("build_id").equals(req.query.build_id)
    }
    if (req.query.feature) {
        query.where("feature").equals(req.query.feature)
    }
    if (req.query.environment) {
        query.where("environment").equals(req.query.environment)
    }
    if (req.query.project) {
        query.where("project").equals(req.query.project)
    }
    if (req.query.functionality) {
        query.where("functionality").equals(req.query.functionality)
    }
    if (req.query.release) {
        query.where("release").equals(req.query.release)
    }
    query.limit(1000);
    query.exec(function (err, todos) {
        if (err) return next(err);
        res.json(todos);
    });
});

/* POST /testcases */
router.post('/', function (req, res, next) {
    TestCase.create(req.body, function (err, post) {
        if (err) return next(err);
        res.json(post);
    });
});

/* GET /testcases/id */
router.get('/:id', function (req, res, next) {
    TestCase.findById(req.params.id, '+steps', function (err, post) {
        if (err) return next(err);
        res.json(post);
    });
});

/* DELETE /testcases/:id */
router.delete('/:id', function (req, res, next) {
    TestCase.findByIdAndRemove(req.params.id, req.body, function (err, post) {
        if (err) return next(err);
        res.json(post);
    });
});

module.exports = router;

@@ -327,24 +327,25 @@
 .query.name)
+;
 %0A    %7D%0A    i
@@ -421,16 +421,17 @@
 .status)
+;
 %0A    %7D%0A 
@@ -599,16 +599,17 @@
 tags%5Bi%5D)
+;
 %0A       
@@ -705,16 +705,17 @@
 ob_name)
+;
 %0A    %7D%0A 
@@ -801,16 +801,60 @@
 uild_id)
+;%0A    %7D%0A    else %7B%0A        query.limit(100);
 %0A    %7D%0A 
@@ -937,16 +937,17 @@
 feature)
+;
 %0A    %7D%0A 
@@ -1042,16 +1042,17 @@
 ronment)
+;
 %0A    %7D%0A 
@@ -1135,16 +1135,17 @@
 project)
+;
 %0A    %7D%0A 
@@ -1246,16 +1246,17 @@
 onality)
+;
 %0A    %7D%0A 
@@ -1339,16 +1339,17 @@
 release)
+;
 %0A    %7D%0A 
@@ -1355,26 +1355,146 @@
     
-query.limit(1000);
+if (req.query.limit) %7B%0A        query.limit(req.query.limit);%0A    %7D%0A    if (req.query.offset) %7B%0A        query.skip(req.query.offset);%0A    %7D
 %0A   

Add default limit of query and limit and offset filter paramaters