clear all wishlists button

This commit is contained in:
Wingy 2021-09-13 16:47:56 -04:00
parent 9d979b6825
commit ccfc10002d
3 changed files with 28 additions and 0 deletions

View file

@ -195,5 +195,21 @@ module.exports = (db) => {
res.redirect('/admin-settings') 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 return router
} }

View file

@ -0,0 +1,9 @@
extends layout.pug
block content
h2 Wishlist Deletion
p This will instantly <b>irreversibly delete all wishlists!</b> 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`)

View file

@ -21,6 +21,9 @@ block content
.field .field
.control .control
input.button.is-primary(type='submit' value='Add User') input.button.is-primary(type='submit' value='Add User')
h3 Data Destruction
p <b>Warning</b>: These options <b>destroy data</b>! 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 h3 Version Info
p Christmas Community: v#{_CC.require('./package.json').version} p Christmas Community: v#{_CC.require('./package.json').version}
p Get Product Data: v#{_CC.package.version} p Get Product Data: v#{_CC.package.version}