route.patch("/", async (req, res) => {
const vote = req.body as NewHubVote;
console.log(req.userId, vote.hubPostId)
//* Check The Existing Vote
const existingvote = await searchHubVote(req.userId);
if (existingvote) {
//* If the vote are same, remove the votes
if (existingvote.vote === vote.vote) {
await removeHubVote({ userId: req.userId });
res.status(200)
return res.send("OK");
}
await updateHubVote({
userId: req.userId,
hubPostId: vote.hubPostId,
vote: vote.vote,
});
res.status(200)
return res.send("OK");
}
//* If no Vote Existed, Create a New One
await createHubVote({
userId: req.userId,
hubPostId: vote.hubPostId,
vote: vote.vote,
});
res.status(200)
return res.send("OK")
});
}
route.patch("/", async (req, res) => {
const vote = req.body as NewHubVote;
console.log(req.userId, vote.hubPostId)
//* Check The Existing Vote
const existingvote = await searchHubVote(req.userId);
if (existingvote) {
//* If the vote are same, remove the votes
if (existingvote.vote === vote.vote) {
await removeHubVote({ userId: req.userId });
res.status(200)
return res.send("OK");
}
await updateHubVote({
userId: req.userId,
hubPostId: vote.hubPostId,
vote: vote.vote,
});
res.status(200)
return res.send("OK");
}
//* If no Vote Existed, Create a New One
await createHubVote({
userId: req.userId,
hubPostId: vote.hubPostId,
vote: vote.vote,
});
res.status(200)
return res.send("OK")
});
}