Browse Source

Recalculate sort_time on deleting comment

pull/6/head
Menci 6 years ago
parent
commit
c34499c77e
  1. 11
      modules/discussion.js

11
modules/discussion.js

@ -238,9 +238,7 @@ app.post('/article/:id/comment', async (req, res) => {
await comment.save(); await comment.save();
article.sort_time = syzoj.utils.getCurrentDate(); await article.resetReplyCountAndTime();
article.comments_num += 1;
await article.save();
res.redirect(syzoj.utils.makeUrl(['article', article.id])); res.redirect(syzoj.utils.makeUrl(['article', article.id]));
} catch (e) { } catch (e) {
@ -264,12 +262,11 @@ app.post('/article/:article_id/comment/:id/delete', async (req, res) => {
if (!await comment.isAllowedEditBy(res.locals.user)) throw new ErrorMessage('您没有权限进行此操作。'); if (!await comment.isAllowedEditBy(res.locals.user)) throw new ErrorMessage('您没有权限进行此操作。');
} }
await comment.destroy(); const article = await Article.findById(comment.article_id);
let article = comment.article; await comment.destroy();
article.comments_num -= 1;
await article.save(); await article.resetReplyCountAndTime();
res.redirect(syzoj.utils.makeUrl(['article', comment.article_id])); res.redirect(syzoj.utils.makeUrl(['article', comment.article_id]));
} catch (e) { } catch (e) {

Loading…
Cancel
Save