Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
taugk committed Dec 16, 2023
2 parents 8ccd443 + d65ad0d commit 1ddf973
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions routes/postsRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ router.get("/recommendation/homefood", async (req, res) => {
};
const distance = geolib.getDistance(userLocation, locationPosts, 1);

// Convert timestamps to Unix format
const pickupTimeUnix = moment(post.pickupTime).unix();
const createdAtUnix = moment(post.createdAt).unix();
const updateAtUnix = moment(post.updatedAt).unix();
Expand All @@ -317,7 +316,6 @@ router.get("/recommendation/homefood", async (req, res) => {
return responseHomefoodPost;
});

// Sort by distance after timestamp conversion
const sortHomefood = withDistance.sort((a, b) => a.distance - b.distance);

const homefoodPost = sortHomefood.slice(0, 5);
Expand All @@ -342,7 +340,7 @@ router.get("/recommendation/rawIngredients", async (req, res) => {
};
const rawIngredientsPosts = await Post.findAll({
where: {
categoryId: 3, // Category ID for "raw ingredients"
categoryId: 3,
},
});
const withDistance = rawIngredientsPosts.map((post) => {
Expand All @@ -352,12 +350,11 @@ router.get("/recommendation/rawIngredients", async (req, res) => {
};
const distance = geolib.getDistance(userLocation, locationPosts, 1);

// Convert timestamps to Unix format
const pickupTimeUnix = moment(post.pickupTime).unix();
const createdAtUnix = moment(post.createdAt).unix();
const updateAtUnix = moment(post.updatedAt).unix();

// Create the response object with Unix timestamps and distance

const responseRawIngredientsPost = {
...post.dataValues,
pickupTime: pickupTimeUnix,
Expand All @@ -369,7 +366,7 @@ router.get("/recommendation/rawIngredients", async (req, res) => {
return responseRawIngredientsPost;
});

// Sort by distance after timestamp conversion

const sort = withDistance.sort((a, b) => a.distance - b.distance);

const rawIngredientsPost = sort.slice(0, 5);
Expand Down

0 comments on commit 1ddf973

Please sign in to comment.