check deletedCount when removing custompage and show error when deleting invalid named pages, rather than doing an extra db call to check if they exist

indiachan-spamvector
Thomas Lynch 3 years ago
parent 5e4c1b197f
commit 1785b70d68
  1. 2
      db/custompages.js
  2. 10
      models/forms/deletecustompage.js

@ -43,7 +43,7 @@ module.exports = {
'$in': pages
},
'board': board
})
});
},
deleteBoard: (board) => {

@ -7,7 +7,15 @@ const uploadDirectory = require(__dirname+'/../../helpers/files/uploadDirectory.
module.exports = async (req, res, next) => {
await CustomPages.deleteMany(req.body.checkedcustompages, req.params.board);
const deletedCount = await CustomPages.deleteMany(req.body.checkedcustompages, req.params.board).then(res => res.deletedCount);
if (deletedCount === 0) {
return dynamicResponse(req, res, 400, 'message', {
'title': 'Bad Request',
'message': 'Invalid custom pages selected',
'redirect': `/${req.params.board}/manage/custompages.html`
});
}
await Promise.all(req.body.checkedcustompages.map(page => {
remove(`${uploadDirectory}/html/${req.params.board}/custompage/${page}.html`)

Loading…
Cancel
Save