@@ -12,7 +12,6 @@ const ss = require('simple-statistics');
1212
1313const config = require ( '../config' ) ;
1414const db = require ( '../api/models' ) ;
15- const { start } = require ( 'repl' ) ;
1615
1716db . init ( function ( err ) {
1817 if ( err ) throw err ;
@@ -123,13 +122,13 @@ db.init(function(err) {
123122 async next => {
124123 /* Get all service info */
125124 db . Serviceinfo . find ( { } ) . exec ( ( err , services ) => {
125+ if ( err ) return next ( err ) ;
126126 services . forEach ( async ( service ) => {
127127 let countData ;
128128 const currentDate = new Date ( ) ;
129129 if ( ! service . monthlyCounts || ! service . monthlyCounts . length ) {
130130 service . monthlyCounts = [ ] ;
131131 //if no monthly count then add data from 2017
132- // add if statement if current month and current year then stop
133132 for ( let year = 2017 ; year <= currentDate . getFullYear ( ) ; year ++ ) {
134133 for ( let month = 1 ; month <= 12 ; month ++ ) {
135134 if ( year == currentDate . getFullYear ( ) && month > currentDate . getMonth ( ) + 1 ) break ;
@@ -152,11 +151,10 @@ db.init(function(err) {
152151 else service . monthlyCounts . push ( countData [ 0 ] . count ) ;
153152 }
154153 }
155- console . log ( service . service , service . monthlyCounts . length ) ;
154+ // console.log(service.service,service.monthlyCounts.length);
156155 service . save ( ) ;
157156 } else {
158157 //if the month is already marked then updating it instead of pushing element
159- console . log ( "exists monthly Count" , service . service ) ;
160158 const start = currentDate ;
161159 const end = new Date ( start ) ;
162160 start . setMonth ( end . getMonth ( ) - 1 ) ;
@@ -184,7 +182,7 @@ db.init(function(err) {
184182 }
185183 service . save ( ) ;
186184 }
187- } )
185+ } ) ;
188186 } ) ;
189187 } ,
190188
0 commit comments