feat: ability to re-order topic thumbnails

This commit is contained in:
Julian Lam
2021-02-16 11:54:04 -05:00
parent db027170a8
commit 7223074f1d
6 changed files with 63 additions and 14 deletions

View File

@@ -166,6 +166,25 @@ Topics.deleteThumb = async (req, res) => {
helpers.formatApiResponse(200, res, await topics.thumbs.get(req.params.tid));
};
Topics.reorderThumbs = async (req, res) => {
await checkThumbPrivileges({ tid: req.params.tid, uid: req.user.uid, res });
if (res.headersSent) {
return;
}
const exists = await topics.thumbs.exists(req.params.tid, req.body.path);
if (!exists) {
return helpers.formatApiResponse(404, res);
}
await topics.thumbs.associate({
id: req.params.tid,
path: req.body.path,
score: req.body.order,
});
helpers.formatApiResponse(200, res);
};
async function checkThumbPrivileges({ tid, uid, res }) {
// req.params.tid could be either a tid (pushing a new thumb to an existing topic)
// or a post UUID (a new topic being composed)