Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let function_one(data) = function(){
- return new Promise( function(resolve, reject) {
- {do stuff...
- resolve('howdy');
- }
- });
- };
- let function_two(some_data) = function(){
- return new Promise( function(resolve, reject) {
- { do stuff...
- resolve('howdy');
- }
- });
- };
- let function_three(some_data) = function(){
- return new Promise( function(resolve, reject) {
- {do stuff...
- resolve('howdy');
- }
- });
- };
- let function_four(some_data) = function(){
- return new Promise( function(resolve, reject) {
- {do stuff...
- resolve('howdy');
- }
- });
- };
- function_one(data).then(function(result){
- return function_two(result);
- }).then(function(result){
- return function_three(result);
- }).then(function(result){
- return function_four(result);
- }).then(function(result){
- console.log(result);
- }).catch(err => console.log("Caught " + err));
- let gettheinformation = function(invoicelist3){
- return new Promise( function(resolve, reject) {
- // console.log(invoicelist3);
- Product.aggregate([
- {
- $match: {
- Priced: true
- }
- }
- ,
- {
- $group: {
- _id: "$Invoice",
- pricedcount: {$sum: 1}
- }
- }
- ], function (err, result) {
- if (err) {
- console.log(err);
- } else {
- resolve(result);
- }
- });
- });
- };
- let getinvprodspriced = function(invlist){
- return new Promise( function(resolve, reject) {
- // console.log(invlist);
- for(var oo = 0; oo < invlist.length; oo++){
- Invoicestatus.update({Invoice:invlist[oo]._id}, {Noofitemspriced: invlist[oo].pricedcount}, {upsert: true}, function (err) {});
- }
- resolve(invlist);
- });
- };
- let getinvprodcount = function(invprodcount){
- return new Promise( function(resolve, reject) {
- Product.aggregate([
- {
- $group: {
- _id: "$Invoice",
- pradcount: {$sum: 1}
- }
- }
- ], function (err, result) {
- if (err) {
- console.log(err);
- } else {
- // console.log(result);
- resolve(result);
- }
- });
- });
- }
- let saveinvprodcount = function(invprodcount){
- return new Promise( function(resolve, reject) {
- for(var ok = 0; ok < invprodcount.length; ok++){
- Invoicestatus.update({Invoice:invprodcount[ok]._id}, {Noofitems: invprodcount[ok].pradcount}, {upsert: true}, function (err) {});
- }
- resolve(invprodcount);
- });
- };
- let getarrdocs = function(result){
- return new Promise( function(resolve, reject) {
- Invoicestatus.find({}, function(err, docs){
- resolve(docs);
- });
- });
- };
- router.get('/fetcharrdata', function(req, res) {
- gettheinformation().then(function(result){
- return getinvprodspriced(result);
- }).then(function(result){
- return getinvprodcount(result);
- }).then(function(result){
- return saveinvprodcount(result);
- }).then( function(result){
- return getarrdocs(result);
- }).then(function(result){
- res.json({status: 200, data: result});
- }).catch(err => console.log("Caught " + err));
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement