async function recentActivities(query) {
  const location = (query.location || defaultLocation).toLowerCase();
  const days = parseInt((query.days || config.days), 10);
  const limit = parseInt((query.perPage || config.perPage), 10);
  let skip = parseInt((query.page || 1), 10);

  // Validate days and location params
  if (
    Number.isNaN(days)
    || Number.isNaN(limit)
    || Number.isNaN(skip)
    || !isValidLocation(location)
  ) {
    const errorMsg = 'Invalid query param';
    captureSentry(
      errorMsg,
      '/api/v2/recentactivities',
      { extra: query },
    );
    return {
      error: true,
      data: errorMsg,
    };
  }
  skip = (skip - 1) * limit;

  // Ok cool, we're validated
  const afterDate = moment()
    .utc()
    .subtract(days, 'days')
    .format('YYYY-MM-DD');

  const activities = await Activity.find(
    {
      startDateUtc: { $gte: new Date(afterDate) },
      activityLocations: { $elemMatch: { location } },
    },
    'activityLocations startDateUtc',
    {
      limit,
      skip,
      sort: { startDateUtc: -1 },
    },
  ).lean();

  const transformedActivities = activities.map(
    ({ startDateUtc, activityLocations }) => ({
      date: startDateUtc,
      locations: activityLocations.map(
        ({ location: loc, laps }) => ({ location: loc, laps }),
      ),
    }),
  );

  return {
    error: false,
    data: transformedActivities,
  };
}
/**
 * API response for recent activities
 *
 * @param {Object} query
 */
API response for recent activities
@param {Object} query
API response for recent activities @param { Object } query
async function recentActivities(query) {
  const location = (query.location || defaultLocation).toLowerCase();
  const days = parseInt((query.days || config.days), 10);
  const limit = parseInt((query.perPage || config.perPage), 10);
  let skip = parseInt((query.page || 1), 10);
  if (
    Number.isNaN(days)
    || Number.isNaN(limit)
    || Number.isNaN(skip)
    || !isValidLocation(location)
  ) {
    const errorMsg = 'Invalid query param';
    captureSentry(
      errorMsg,
      '/api/v2/recentactivities',
      { extra: query },
    );
    return {
      error: true,
      data: errorMsg,
    };
  }
  skip = (skip - 1) * limit;
  const afterDate = moment()
    .utc()
    .subtract(days, 'days')
    .format('YYYY-MM-DD');
  const activities = await Activity.find(
    {
      startDateUtc: { $gte: new Date(afterDate) },
      activityLocations: { $elemMatch: { location } },
    },
    'activityLocations startDateUtc',
    {
      limit,
      skip,
      sort: { startDateUtc: -1 },
    },
  ).lean();
  const transformedActivities = activities.map(
    ({ startDateUtc, activityLocations }) => ({
      date: startDateUtc,
      locations: activityLocations.map(
        ({ location: loc, laps }) => ({ location: loc, laps }),
      ),
    }),
  );
  return {
    error: false,
    data: transformedActivities,
  };
}
async function recentActivities ( query ) { const location = ( query . location || defaultLocation ) . toLowerCase ( ) ; const days = parseInt ( ( query . days || config . days ) , 10 ) ; const limit = parseInt ( ( query . perPage || config . perPage ) , 10 ) ; let skip = parseInt ( ( query . page || 1 ) , 10 ) ; if ( Number . isNaN ( days ) || Number . isNaN ( limit ) || Number . isNaN ( skip ) || ! isValidLocation ( location ) ) { const errorMsg = 'Invalid query param' ; captureSentry ( errorMsg , '/api/v2/recentactivities' , { extra : query } , ) ; return { error : true , data : errorMsg , } ; } skip = ( skip - 1 ) * limit ; const afterDate = moment ( ) . utc ( ) . subtract ( days , 'days' ) . format ( 'YYYY-MM-DD' ) ; const activities = await Activity . find ( { startDateUtc : { $gte : new Date ( afterDate ) } , activityLocations : { $elemMatch : { location } } , } , 'activityLocations startDateUtc' , { limit , skip , sort : { startDateUtc : - 1 } , } , ) . lean ( ) ; const transformedActivities = activities . map ( ( { startDateUtc , activityLocations } ) => ( { date : startDateUtc , locations : activityLocations . map ( ( { location : loc , laps } ) => ( { location : loc , laps } ) , ) , } ) , ) ; return { error : false , data : transformedActivities , } ; }
API response for recent activities
 @param {Object} query
API response for recent activities @param { Object } query
// Validate days and location params // Ok cool, we're validated