src/chartmogul/chartmogul-feeder.js
/**
   * The middleware in chargin of fetch the leads.
   *
   * @param {Object} config - The config require for the fetch
   * @return {Promise} - The promisified geckoFormatted result of the fetch.
   *
   */
The middleware in chargin of fetch the leads.
@param {Object} config - The config require for the fetch
@return {Promise} - The promisified geckoFormatted result of the fetch.
The middleware in chargin of fetch the leads . @param { Object } config - The config require for the fetch @return { Promise } - The promisified geckoFormatted result of the fetch .
async fetchNbLeads(config) {
    const {
      firstInMonth, firstInPastMonth, dateInPastMonth,
    } = Util.getAllDates();
    firstInMonth.setHours(0, 0, 0, 0);
    firstInPastMonth.setHours(0, 0, 0, 0);
    const [leads, nbLastMonth] = await Promise.all([
      this.fetchAndFilterCustomers(this.leads_.startPage, {
        onlyLead: true,
      }),
      this.getCached(KEY_NB_LEADS_LAST_MONTH),
    ]);
    const item = leads.reduce((item, lead) => {
      const leadDateInMs = new Date(lead['lead_created_at']).getTime();
      if (leadDateInMs >= firstInMonth) {
        item[0].value += 1;
      }
      if (nbLastMonth === null
        &&
        leadDateInMs >= firstInPastMonth &&
        leadDateInMs <= dateInPastMonth) {
        item[1].value += 1;
      }
      return item;
    }, [{
        'value': 0,
      },
      {
        'value': (nbLastMonth) ? Number.parseInt(nbLastMonth) : 0,
      },
    ]);
    if (nbLastMonth === null) { 
      super.setInCache(KEY_NB_LEADS_LAST_MONTH, item[1].value);
    }
    return GeckoFormatter.toNumberAndSecondStat(item[0], item[1]);
  }
async fetchNbLeads ( config ) { const { firstInMonth , firstInPastMonth , dateInPastMonth , } = Util . getAllDates ( ) ; firstInMonth . setHours ( 0 , 0 , 0 , 0 ) ; firstInPastMonth . setHours ( 0 , 0 , 0 , 0 ) ; const [ leads , nbLastMonth ] = await Promise . all ( [ this . fetchAndFilterCustomers ( this . leads_ . startPage , { onlyLead : true , } ) , this . getCached ( KEY_NB_LEADS_LAST_MONTH ) , ] ) ; const item = leads . reduce ( ( item , lead ) => { const leadDateInMs = new Date ( lead [ 'lead_created_at' ] ) . getTime ( ) ; if ( leadDateInMs >= firstInMonth ) { item [ 0 ] . value += 1 ; } if ( nbLastMonth === null && leadDateInMs >= firstInPastMonth && leadDateInMs <= dateInPastMonth ) { item [ 1 ] . value += 1 ; } return item ; } , [ { 'value' : 0 , } , { 'value' : ( nbLastMonth ) ? Number . parseInt ( nbLastMonth ) : 0 , } , ] ) ; if ( nbLastMonth === null ) { super . setInCache ( KEY_NB_LEADS_LAST_MONTH , item [ 1 ] . value ) ; } return GeckoFormatter . toNumberAndSecondStat ( item [ 0 ] , item [ 1 ] ) ; }
The middleware in chargin of fetch the leads.
The middleware in chargin of fetch the leads .
// The first day in this month at 00:00:00:00 // The first day in the prev. month at 00:00:00:00 // console.log('Nb Filtered : ' + leads.length, nbLastMonth); // const leadDate = Util.convertDate(lead['lead_created_at']); // ? No cached value for the lastMonth ? // Only the Leads made within the previous month // ? Nothing in cache ?