See #924. Add JavaScript test that is reported to crash Atom

This commit is contained in:
Glavin Wiechert 2016-04-16 16:15:47 -03:00
parent 1009945b8a
commit 3bc3c6d3a7
2 changed files with 131 additions and 0 deletions

View File

@ -0,0 +1,65 @@
/**
* Created by Pierre on 05.04.16.
*/
var express = require("express");
var router = express.Router({
mergeParams: true
});
var Customer = require("../../models/customers");
var middleware = require("../../middleware/index.js");
//TODO add a way for pagination
//INDEX - show all Customers
router.get("/", function (req, res) {
var regexid = /^[a-f\d]{24}$/i;
var search = req.query.search;
if (regexid.exec(search) !== null) {
Customer.findById(search, function (err, foundCustomer) {
if (err) {
console.log(err);
} else {
res.end(JSON.stringify([foundCustomer]));
}
});
} else {
var re = new RegExp(search);
var offset = 0;
if (req.query.offset) {
offset = req.query.offset;
}
Customer.find().or([{
'name': {
$regex: re
}
}, {
'mail': {
$regex: re
}
}, {
'phone': {
$regex: re
}
}, {
'customernumber': {
$regex: re
}
}, {
'street': {
$regex: re
}
}]).skip(parseInt(offset)).limit(20).exec(function (err, allCustomers) {
if (err) {
console.log(err);
} else if (allCustomers.length === 0) {
res.sendStatus(404);
} else {
res.end(JSON.stringify(allCustomers));
}
});
}
});
// TODO add findsingle for id
module.exports = router;

View File

@ -0,0 +1,66 @@
/**
* Created by Pierre on 05.04.16.
*/
var express = require("express");
var router = express.Router({
mergeParams: true
});
var Customer = require("../../models/customers");
var middleware = require("../../middleware/index.js");
//TODO add a way for pagination
//INDEX - show all Customers
router.get("/", function(req, res) {
var regexid = /^[a-f\d]{24}$/i;
var search = req.query.search;
if (regexid.exec(search) !== null) {
Customer.findById(search, function(err, foundCustomer) {
if (err) {
console.log(err);
} else {
res.end(JSON.stringify([foundCustomer]));
}
});
} else {
var re = new RegExp(search);
var offset = 0;
if (req.query.offset) {
offset = req.query.offset;
}
Customer.find().or([{
'name': {
$regex: re
}
}, {
'mail': {
$regex: re
}
}, {
'phone': {
$regex: re
}
}, {
'customernumber': {
$regex: re
}
}, {
'street': {
$regex: re
}
}]).skip(parseInt(offset)).limit(20).exec(function(err, allCustomers) {
if (err) {
console.log(err);
} else if (allCustomers.length === 0) {
res.sendStatus(404);
} else {
res.end(JSON.stringify(allCustomers));
}
});
}
});
// TODO add findsingle for id
module.exports = router;