Removed old dbQuery calls to native mongo

react_convert
Mark Moffat 2018-02-03 13:20:35 +01:00
parent 931e8c7239
commit d506969cbf
2 changed files with 7 additions and 26 deletions

View File

@ -16,7 +16,7 @@ router.get('/orders', common.restrict, (req, res, next) => {
const db = req.app.db;
// Top 10 products
common.dbQuery(db.orders, {}, {'orderDate': -1}, 10, (err, orders) => {
db.orders.find({}).sort({'orderDate': -1}).limit(10).toArray((err, orders) => {
if(err){
console.info(err.stack);
}
@ -44,7 +44,7 @@ router.get('/orders/bystatus/:orderstatus', common.restrict, (req, res, next) =>
// case insensitive search
let regex = new RegExp(['^', req.params.orderstatus, '$'].join(''), 'i');
common.dbQuery(db.orders, {orderStatus: regex}, {'orderDate': -1}, 10, (err, orders) => {
db.orders.find({orderStatus: regex}).sort({'orderDate': -1}).limit(10).toArray((err, orders) => {
if(err){
console.info(err.stack);
}
@ -101,7 +101,7 @@ router.get('/orders/filter/:search', common.restrict, (req, res, next) => {
});
// we search on the lunr indexes
common.dbQuery(db.orders, {_id: {$in: lunrIdArray}}, null, null, (err, orders) => {
db.orders.find({_id: {$in: lunrIdArray}}).toArray((err, orders) => {
if(err){
console.info(err.stack);
}
@ -154,7 +154,7 @@ router.post('/order/statusupdate', common.restrict, (req, res) => {
router.get('/products', common.restrict, (req, res, next) => {
const db = req.app.db;
// get the top results
common.dbQuery(db.products, {}, {'productAddedDate': -1}, 10, (err, topResults) => {
db.products.find({}).sort({'productAddedDate': -1}).limit(10).toArray((err, topResults) => {
if(err){
console.info(err.stack);
}
@ -320,7 +320,7 @@ router.get('/products/filter/:search', common.restrict, (req, res, next) => {
});
// we search on the lunr indexes
common.dbQuery(db.products, {_id: {$in: lunrIdArray}}, null, null, (err, results) => {
db.products.find({_id: {$in: lunrIdArray}}).toArray((err, results) => {
if(err){
console.error(colors.red('Error searching', err));
}
@ -941,7 +941,7 @@ router.get('/settings/menu', common.restrict, async (req, res) => {
// settings page list
router.get('/settings/pages', common.restrict, (req, res) => {
const db = req.app.db;
common.dbQuery(db.pages, {}, null, null, async (err, pages) => {
db.pages.find({}).toArray(async (err, pages) => {
if(err){
console.info(err.stack);
}

View File

@ -42,7 +42,7 @@ exports.addSitemapProducts = (req, res, cb) => {
let config = exports.getConfig();
let hostname = config.baseUrl;
exports.dbQuery(db.products, {productPublished: 'true'}, null, null, (err, products) => {
db.products.find({productPublished: 'true'}).toArray((err, products) => {
let posts = [];
if(err){
cb(null, posts);
@ -402,25 +402,6 @@ exports.getId = (id) => {
return ObjectId(id);
};
// run the DB query
exports.dbQuery = (db, query, sort, limit, callback) => {
if(sort && limit){
db.find(query).sort(sort).limit(parseInt(limit)).toArray((err, results) => {
if(err){
console.error(colors.red(err));
}
callback(null, results);
});
}else{
db.find(query).toArray((err, results) => {
if(err){
console.error(colors.red(err));
}
callback(null, results);
});
}
};
exports.getData = (req, page, query) => {
let db = req.app.db;
let config = exports.getConfig();