Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
taugk committed Dec 15, 2023
1 parent c29e546 commit 5a731a9
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions routes/postsRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,44 @@ router.get("/recommendation/rawIngredients", async (req, res) => {
}
});

router.get(
"/user/posts",
authMiddleware.authenticateToken,
async (req, res) => {
try {
const userId = req.authData.id;

const posts = await Post.findAll({
where: { userId },
include: [
{
model: User,
attributes: ["id", "fullname", "email", "no_hp", "photo_url"],
},
],
});

const postsWithUnixTimestamps = posts.map((post) => {
const unixPickupTime = moment(post.pickupTime).unix();
const unixCreatedAt = moment(post.createdAt).unix();
const unixUpdatedAt = moment(post.updatedAt).unix();

return {
...post.dataValues,
pickupTime: unixPickupTime,
createdAt: unixCreatedAt,
updatedAt: unixUpdatedAt,
};
});

res.status(200).json({ posts: postsWithUnixTimestamps });
} catch (error) {
console.error("Error fetching user posts", error);
res.status(500).json({ message: "Internal server error" });
}
}
);

//Post Routes
router.post(
"/posts/food",
Expand Down

0 comments on commit 5a731a9

Please sign in to comment.