Dears i have the below services
/* GET home page. */ router.get('/orders',function (req,res,next) { models.configuration.findOne( // to get the order limit and render it for ops guys { where : { name : "Get order limit for ops" } }).then(function(configurations) { models.Order.findAll({ where : { userId : { $and : { $notIn: ['null'] } }, serviceId : { $and : { $notIn: ['null'] } } }, attributes : ['id','userId','providerId','orderStatus','isUsingBalance','serviceId','reason','createdAt'] , limit : parseInt(configurations.detail), pageLength : parseInt(configurations.detail), // order: 'id DESC' order: '`id` DESC', include: [ { model: models.Provider, attributes : ['id'], include: [{ model : models.User, attributes : ['firstName','lastName','phoneNumber','rankId','rate'] } ]} //{model: OrderHasWarranty, as: 'warranty1'}, {model: OrderHasWarranty, as: 'warranty2'} , { model : models.User, include :[{ model : models.Order, attributes : ['id'] }, { model: models.Balance, attributes: ['balance'] }], attributes : ['firstName','lastName','phoneNumber','id'] } ] }).then(function (orders) { var starTime = moment("00:00:00", "hh:mm:ss"); var endTime=moment("23:59:59", "hh:mm:ss"); models.Order.count({ where:{createdAt:{$lte: endTime,$gte: starTime}} }).then(function (all) { models.Order.count({ where: {orderStatus:4 ,createdAt:{$lte: endTime,$gte: starTime}} }).then(function (completed) { models.Order.count({ where: {orderStatus:{$notIn: [4]},createdAt:{$lte: endTime,$gte: starTime}} }).then(function (notCompleted) { // get all orders having service ID = 28 which is warntty orders models.Order.findAll({ where : { userId : { $and : { $notIn: ['null'] } },orderStatus : { $notIn : [4] }, serviceId : { $and : { $notIn: ['null'] } }, serviceId : 28 // means warranty orders, }, order: '`id` DESC', include: [ { model: models.Provider, attributes : ['id'], include: [{ model : models.User, attributes : ['firstName','lastName','phoneNumber','rankId','rate'] } ]}, { model : models.User, include :[{ model : models.Order, attributes : ['id'] }, { model: models.Balance, attributes: ['balance'] }], attributes : ['firstName','lastName','phoneNumber','id'] } ] }).then(function(warrantyOrders){ sequelize.query( "SELECT services.`professionDecrption` AS 'Service', "+ "sum(if(users.`status` = 4,1,0)) AS 'Online',"+ "sum(if(users.`status` = 8,1,0)) AS 'Offline',"+ "count(providers_has_services.`serviceId`) AS 'Total' "+ "FROM providers, "+ "providers_has_services, "+ "users, "+ "services "+ "WHERE providers.`id` = providers_has_services.`id` "+ "AND users.id = providers.`userId` "+ "AND services.`id` = `providers_has_services`.`serviceId` "+ "AND services.`id` IN (1,"+ "2,"+ "3,"+ "4) "+ "GROUP BY providers_has_services.`serviceId`") ,{ type: sequelize.QueryTypes.SELECT}}).then(function (providerReport,warrantyOrders) { /* res.render('orders',{ orders : orders, status : models.Order.ORDER_STATUS, service : models.Service.SERVICES, ranks : models.Rank.RANKS, Cancel_reason : models.Order.ORDER_CANCELLATION_REASON_AR, all:all, completed:completed, notCompleted:notCompleted, warranty_orders : warrantyOrders, providerReport : providerReport }); */ res.status(200).send({ orders : orders, status : models.Order.ORDER_STATUS, service : models.Service.SERVICES, ranks : models.Rank.RANKS, Cancel_reason : models.Order.ORDER_CANCELLATION_REASON_AR, all:all, completed:completed, notCompleted:notCompleted, warranty_orders : warrantyOrders, providerReport : providerReport, }); }); }) }) }) }) }); }); after executing the service, nodejs execute the whole query except the raw one, so nodejs return the result for everything except (providerReport)
below result from nodejs output
so how can i tell nodejs to wait untill the raw query finish and then send the res.stats or res.render with whole details
