コード例 #1
0
exports.getAll = function (req, res) {
    logger.info('requesting all measurements');
    var ids = req.query.ids;
    db.instance().collection('measurements', function (err, collection) {
        if (err) {
            logger.error('no table by name measurements found in db');
            res.send(500, { message: err });

        }
        else {
            if (ids) {
                var idArr = [];
                ids.forEach(function (id) {
                    idArr.push(BSON.ObjectID(id));
                });

                collection.find({ '_id': { $in: idArr }}).sort({ name: 1 }).toArray(function (err, items) {
                    var matchMeasurements = {
                        measurements: items
                    };
                    res.send(matchMeasurements);
                });
            }
            else {
                collection.find().sort({ name: 1 }).toArray(function (err, items) {
                    var allMeasurements = {
                        measurements: items
                    };
                    res.send(allMeasurements);
                });
            }
        }
    });
};
コード例 #2
0
ファイル: orders.js プロジェクト: kpurusho/OrderTracking
exports.add = function (req, res) {
    var order = req.body.order;
    logger.info('order add body - ' + req.body);
    logger.info('requesting add order - ' + order.name);
    db.instance().collection('orders', function (err, collection) {
        collection.find().sort({ orderno: -1 }).limit(1).toArray(function (err, items) {
            if (items.length > 0)
                order.orderno = items[0].orderno + 1;
            else
                order.orderno = 1;

            collection.insert(order, { safe: true }, function (err, result) {
                if (err) {
                    logger.error('failed to add order' + order);
                    res.send(500, { message: err });

                }
                else {
                    logger.info('successfully added order - ' + order);
                    res.send({ order: result[0] });
                }
            });
        });
    });
};
コード例 #3
0
ファイル: orders.js プロジェクト: kpurusho/OrderTracking
exports.getSummary = function (req, res) {
    var keyf = function (doc) { duedate: doc.duedate };
    db.instance().collection('orders', function (err, collection) {
        collection.group(
            { duedate: true },
            { status: { $ne: 'Delivered' } },
            { "_id": 0, "newcount": 0, "inprogresscount": 0, "donecount": 0 },
            function (curr, result) {
                if (curr.status === 'New')
                    result.newcount += 1;
                if (curr.status === 'InProgress')
                    result.inprogresscount += 1;
                if (curr.status === 'Done')
                    result.donecount += 1;
            },
	    function (result) {
	    	result._id = (new Date(result.duedate)).getTime().toString();
	    },
            true,
            function (err, results) {
                results.sort(function (a, b){
                    var d1 = new Date(a.duedate).getTime();
                    var d2 = new Date(b.duedate).getTime();
                    return d1 - d2;
                });
                var ordersummary = {
                    ordersummarys: results
                };
                res.send(ordersummary);
            }
        );
    });
};
コード例 #4
0
ファイル: orders.js プロジェクト: kpurusho/OrderTracking
exports.getById = function (req, res) {
    var id = req.params.id;
    logger.info('requesting order id ' + id);
    db.instance().collection('orders', function (err, collection) {
        if (err) {
            logger.error('no table by name orders found in db');
            res.send(500, { message: err });

        }
        else {
            collection.findOne({ '_id': BSON.ObjectID(id) }, function (err, item) {
                res.json({ order: item });
            });
        }
    });
};
コード例 #5
0
ファイル: orders.js プロジェクト: kpurusho/OrderTracking
exports.delete = function (req, res) {
    var orderId = req.params.id;
    logger.info('requesting delete order with id ' + orderId);
    db.instance().collection('orders', function (err, collection) {
        collection.remove({ '_id': new BSON.ObjectID(orderId) }, { safe: true }, function (err, result) {
            if (err) {
                logger.error('Error deleting Order: ' + err);
                res.send(500, { message: err });

            } else {
                logger.log('' + result + ' document(s) deleted');
                res.send(req.body);
            }
        });
    });
};
コード例 #6
0
ファイル: orders.js プロジェクト: kpurusho/OrderTracking
exports.getAll = function (req, res) {
    logger.info('requesting all orders');
    var status = req.query.status;
    var phno = req.query.customerphoneno;
    db.instance().collection('orders', function (err, collection) {
        if (err) {
            logger.error('no table by name orders found in db');
            res.send(500, { message: err });

        }
        else {
            if (status && phno) {
                collection.find({ 'status': status, 'customerphoneno': phno}).sort({ orderno: 1 }).toArray(function (err, items) {
                    var allOrders = {
                        orders: items
                    };
                    res.send(allOrders);
                });
            }
            else if (status) {
                collection.find({ 'status': { $in: status }}).sort({ orderno: 1 }).toArray(function (err, items) {
                    var allOrders = {
                        orders: items
                    };
                    res.send(allOrders);
                });
            } else if (phno) {
                collection.find({ 'customerphoneno':{$in: phno}}).sort({ orderno: 1 }).toArray(function (err, items) {
                    var allOrders = {
                        orders: items
                    };
                    res.send(allOrders);
                });
            }
            else {

                collection.find().sort({ orderno: -1 }).toArray(function (err, items) {
                    var allOrders = {
                        orders: items
                    };
                    res.send(allOrders);
                });
            }
        }
    });
};
コード例 #7
0
exports.update = function (req, res) {
    var measurementId = req.params.id;
    var measurementInfo = req.body.measurement;
    logger.info('requesting update measurement with id ' + measurementId);
    db.instance().collection('measurements', function (err, collection) {
        collection.update({ '_id': new BSON.ObjectID(measurementId) }, measurementInfo, { safe: true }, function (err, result) {
            if (err) {
                logger.error('Error updating measurement: ' + err);
                res.send(500, { message: err });

            } else {
                logger.log('' + result + ' document(s) updated');
                res.send({ measurement: result[0] });
            }
        });
    });
};
コード例 #8
0
exports.add = function (req, res) {
    var measurement = req.body.measurement;
    logger.info('requesting add measurement - ' + measurement.name);
    db.instance().collection('measurements', function (err, collection) {
        collection.insert(measurement, { safe: true }, function (err, result) {
            if (err) {
                logger.error('failed to add measurement' + measurement);
                res.send(500, { message: err });

            }
            else {
                logger.info('successfully added measurement - ' + measurement);
                res.send({measurement: result[0]});
            }
        });
    });
};
コード例 #9
0
ファイル: customers.js プロジェクト: kpurusho/OrderTracking
exports.update = function (req, res) {
    var customerId = req.params.id;
    var customerInfo = req.body.customer;
    logger.info('requesting update customer with id ' + customerId);
    db.instance().collection('customers', function (err, collection) {
        collection.update({ '_id': new BSON.ObjectID(customerId) }, customerInfo, { safe: true }, function (err, result) {
            if (err) {
                logger.error('Error updating customer: ' + err);
                res.send(500, { message: err });

            } else {
                logger.log('' + result + ' document(s) updated');
                res.send({customer: result[0]});
            }
        });
    });
};
コード例 #10
0
ファイル: orders.js プロジェクト: kpurusho/OrderTracking
exports.update = function (req, res) {
    var orderId = req.params.id;
    var orderInfo = req.body.order;
    logger.info('requesting update order with id ' + orderId);
    db.instance().collection('orders', function (err, collection) {
        collection.update({ '_id': new BSON.ObjectID(orderId) }, orderInfo, { safe: true }, function (err, result) {
            if (err) {
                logger.error('Error updating order: ' + err);
                res.send(500, { message: err });

            } else {
                logger.log('' + result + ' document(s) updated');
                //sendmail('karthik.purushothaman@gmail.com');
                res.send({order: result[0]});
            }
        });
    });
};
コード例 #11
0
ファイル: customers.js プロジェクト: kpurusho/OrderTracking
exports.add = function (req, res) {
    var customer = req.body.customer;
    logger.info('customer add body - ' + req.body);
    logger.info('requesting add customer - ' + customer.name);
    db.instance().collection('customers', function (err, collection) {
        collection.insert(customer, { safe: true }, function (err, result) {
            if (err) {
                logger.error('failed to add customer' + customer);
                res.send(500, { message: err });

            }
            else {
                logger.info('successfully added customer - ' + customer);
                res.send({customer: result[0]});
            }
        });
    });
};
コード例 #12
0
ファイル: orders.js プロジェクト: kpurusho/OrderTracking
exports.getByOrderName = function (req, res) {
    var Name = req.param('name', 'undefined');
    logger.info('requesting order Name ' + Name);
    db.instance().collection('orders', function (err, collection) {
        if (err) {
            logger.error('no table by name orders found in db');
            res.send(500, { message: err });

        }
        else {
            collection.find({ 'name': Name }).toArray(function (err, items) {
                var matchOrders = {
                    orders: items
                };
                res.send(matchOrders);
            });
        }
    });
};
コード例 #13
0
ファイル: customers.js プロジェクト: kpurusho/OrderTracking
exports.getAll = function (req, res) {
    logger.info('requesting all customers');
    var phoneno = req.query.phoneno;
    var name = req.query.name;

    logger.info('phoneno = ' + phoneno);
    logger.info('name = ' + name);
    //var phno = req.param('phoneno', 'undefined');
    db.instance().collection('customers', function (err, collection) {
        if (err) {
            logger.error('no table by name customers found in db');
            res.send(500, { message: err })
        }
        else {
            if (name) {
                collection.find({ 'name': name }).toArray(function (err, items) {
                    var matchCustomers = {
                        customers: items
                    };
                    res.send(matchCustomers);
                });
            }
            else if (phoneno) {
                collection.find({ 'phoneno': phoneno }).toArray(function (err, items) {
                    var matchCustomers = {
                        customers: items
                    };
                    res.send(matchCustomers);
                });
            }
            else {
                collection.find().sort({ name: 1 }).toArray(function (err, items) {
                    var allCustomers = {
                        customers: items
                    };
                    res.send(allCustomers);
                });
            }
        }
    });
};