feat(writeapi): post bookmarking

This commit is contained in:
Julian Lam
2020-10-07 10:19:27 -04:00
parent 9942c248eb
commit 0973feea16
5 changed files with 63 additions and 22 deletions

View File

@@ -171,6 +171,24 @@ Posts.unvote = async (req, res) => {
helpers.formatApiResponse(200, res);
};
Posts.bookmark = async (req, res) => {
const tid = await posts.getPostField(req.params.pid, 'tid');
const data = { pid: req.params.pid, room_id: `topic_${tid}` };
const socketMock = { uid: req.user.uid };
await socketPostHelpers.postCommand(socketMock, 'bookmark', 'bookmarked', '', data);
helpers.formatApiResponse(200, res);
};
Posts.unbookmark = async (req, res) => {
const tid = await posts.getPostField(req.params.pid, 'tid');
const data = { pid: req.params.pid, room_id: `topic_${tid}` };
const socketMock = { uid: req.user.uid };
await socketPostHelpers.postCommand(socketMock, 'unbookmark', 'bookmarked', '', data);
helpers.formatApiResponse(200, res);
};
async function isMainAndLastPost(pid) {
const [isMain, topicData] = await Promise.all([
posts.isMain(pid),