lib/tasks/get-space-data.js
function pagedGet ({source, method, skip = 0, aggregatedResponse = null, query = null}) {
  const fullQuery = Object.assign({},
    {
      skip: skip,
      limit: pageLimit,
      order: 'sys.createdAt,sys.id'
    },
    query
  )

  return source[method](fullQuery)
    .then((response) => {
      if (!aggregatedResponse) {
        aggregatedResponse = response
      } else {
        aggregatedResponse.items = aggregatedResponse.items.concat(response.items)
      }
      const page = Math.ceil(skip / pageLimit) + 1
      const pages = Math.ceil(response.total / pageLimit)
      logEmitter.emit('info', `Fetched ${aggregatedResponse.items.length} of ${response.total} items (Page ${page}/${pages})`)
      if (skip + pageLimit <= response.total) {
        return pagedGet({source, method, skip: skip + pageLimit, aggregatedResponse, query})
      }
      return aggregatedResponse
    })
}
function pagedGet ({source, method, skip = 0, aggregatedResponse = null, query = null}) {
  const fullQuery = Object.assign({},
    {
      skip: skip,
      limit: pageLimit,
      order: 'sys.createdAt,sys.id'
    },
    query
  )

  return source[method](fullQuery)
    .then((response) => {
      if (!aggregatedResponse) {
        aggregatedResponse = response
      } else {
        aggregatedResponse.items = aggregatedResponse.items.concat(response.items)
      }
      const page = Math.ceil(skip / pageLimit) + 1
      const pages = Math.ceil(response.total / pageLimit)
      logEmitter.emit('info', `Fetched ${aggregatedResponse.items.length} of ${response.total} items (Page ${page}/${pages})`)
      if (skip + pageLimit <= response.total) {
        return pagedGet({source, method, skip: skip + pageLimit, aggregatedResponse, query})
      }
      return aggregatedResponse
    })
}
function pagedGet ( { source , method , skip = 0 , aggregatedResponse = null , query = null } ) { const fullQuery = Object . assign ( { } , { skip : skip , limit : pageLimit , order : 'sys.createdAt,sys.id' } , query ) return source [ method ] ( fullQuery ) . then ( ( response ) => { if ( ! aggregatedResponse ) { aggregatedResponse = response } else { aggregatedResponse . items = aggregatedResponse . items . concat ( response . items ) } const page = Math . ceil ( skip / pageLimit ) + 1 const pages = Math . ceil ( response . total / pageLimit ) logEmitter . emit ( 'info' , ` ${ aggregatedResponse . items . length } ${ response . total } ${ page } ${ pages } ` ) if ( skip + pageLimit <= response . total ) { return pagedGet ( { source , method , skip : skip + pageLimit , aggregatedResponse , query } ) } return aggregatedResponse } ) }
Gets all the existing entities based on pagination parameters.
The first call will have no aggregated response. Subsequent calls will
concatenate the new responses to the original one.
Gets all the existing entities based on pagination parameters . The first call will have no aggregated response . Subsequent calls will concatenate the new responses to the original one .