Может быть, вы решили, но если кто-то может помочь, мой подход был:
/**
* Promise to fetch all near shops.
*
* @return {Promise}
*/
fetchAllNear: async (params) => {
const convertedParams = strapi.utils.models.convertParams('shops', params)
let data = {}
let populatedShopsActive = {}
data = await new Promise((resolve, reject) => {
Shops.aggregate([
{
'$geoNear': {
'near': { type: 'Point', coordinates: [ parseFloat(params._lon), parseFloat(params._lat) ] },
'limit': 100,
'maxDistance': parseFloat(params._distance),
'distanceField': 'distance',
'distanceMultiplier': 0.001,
'spherical': true
}
}
]).exec(async (err, shops) => {
await Shops.populate(shops, {
path: _.keys(_.groupBy(_.reject(strapi.models.shops.associations, {autoPopulate: false}), 'alias')).join(' '),
populate: {
path: 'shop image',
populate: {
path: 'image'
}
}
}, async (err, populatedShops) => {
if (err) {
reject(err)
} else {
if (params._todayOffers === 'true') {
populatedShopsActive = await _.forEach(populatedShops, async (shop) => {
await _.remove(shop.offers, (offer) => {
return !(_moment(offer.end_date).isSame(new Date(), 'day'))
})
})
} else {
populatedShopsActive = await _.forEach(populatedShops, async (shop) => {
await _.remove(shop.offers, (offer) => {
return !(_moment(new Date()).isBetween(offer.start_date, offer.end_date, null, '[]'))
})
})
}
resolve(populatedShopsActive)
}
})
})
})
return data
},