diff --git a/routes/adminSettings/index.js b/routes/adminSettings/index.js index 1666d07..8901263 100644 --- a/routes/adminSettings/index.js +++ b/routes/adminSettings/index.js @@ -195,5 +195,21 @@ module.exports = (db) => { res.redirect('/admin-settings') }) + router.get('/clear-wishlists', verifyAuth(), async (req, res) => { + if (!req.user.admin) return res.redirect('/') + res.render('admin-clear-wishlists') + }) + + router.post('/clear-wishlists', verifyAuth(), async (req, res) => { + if (!req.user.admin) return res.redirect('/') + const { rows } = await db.allDocs({ include_docs: true }) + for (const row of rows) { + row.doc.wishlist = [] + await db.put(row.doc) + } + req.flash('success', 'Cleared all wishlists.') + res.redirect('/admin-settings') + }) + return router } diff --git a/views/admin-clear-wishlists.pug b/views/admin-clear-wishlists.pug new file mode 100644 index 0000000..2fcc01f --- /dev/null +++ b/views/admin-clear-wishlists.pug @@ -0,0 +1,9 @@ +extends layout.pug + +block content + h2 Wishlist Deletion + p This will instantly irreversibly delete all wishlists! Consider making a backup of the database before using this. + form(method='POST', action=`${_CC.config.base}admin-settings/clear-wishlists`) + .field + .control + input.button.is-danger(type='submit' value=`Clear all wishlists`) \ No newline at end of file diff --git a/views/adminSettings.pug b/views/adminSettings.pug index c08cdb5..390fa66 100644 --- a/views/adminSettings.pug +++ b/views/adminSettings.pug @@ -21,6 +21,9 @@ block content .field .control input.button.is-primary(type='submit' value='Add User') + h3 Data Destruction + p Warning: These options destroy data! You may want to back up the database before using these options. + a.button.is-danger(href=`${_CC.config.base}admin-settings/clear-wishlists`) Clear Wishlists h3 Version Info p Christmas Community: v#{_CC.require('./package.json').version} p Get Product Data: v#{_CC.package.version}