From ce8aed613a2f624f2c8d0aa46696e0e151856b18 Mon Sep 17 00:00:00 2001 From: Luiz Felipe Neves Date: Mon, 26 Aug 2019 18:23:20 -0300 Subject: [PATCH] Update index.js --- graphql/resolvers/Freight/index.js | 39 ++++++++++++++++++------------ 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/graphql/resolvers/Freight/index.js b/graphql/resolvers/Freight/index.js index 52e956c..8c03df6 100644 --- a/graphql/resolvers/Freight/index.js +++ b/graphql/resolvers/Freight/index.js @@ -130,22 +130,31 @@ export default { const conditions = { ...resto }; if (vehicles) conditions.vehicles = { vehicles: { $in: vehicles } }; if (bodies) conditions.bodies = { bodies: { $in: bodies } }; - const res = await Freight.aggregate([ - { - $geoNear: { - near: { type: "Point", coordinates }, - distanceField: "dist.calculated", - spherical: true, - key: "origin.location", - includeLocs: "location", - maxDistance: range, - query: conditions - } - }, - ...freightquery, - { $skip: (page - 1) * perpage }, - { $limit: perpage } + const list = await Freight.aggregate([ + ...freightquery + // { $out: "aggr_out" } ]).exec(); + + console.log(list); + + const res = await list + .aggregate( + { + $geoNear: { + near: { type: "Point", coordinates }, + distanceField: "dist.calculated", + spherical: true, + key: "origin.location", + // includeLocs: "location", + maxDistance: range, + query: conditions + } + }, + { $skip: (page - 1) * perpage }, + { $limit: perpage } + ) + .exec(); + return freightfinalquery(res, conditions, page, perpage); } },