import { Handler, Router } from '@/mission-control'; import { createBoard, getAdminBoards, setBoardDeleted, setBoardDescription, setBoardName, setBoardType, } from '~/db/admin/queries'; import withQuery from '~/middleware/withQuery'; import AdminBoardsPage from '~/views/admin/AdminBoardsPage'; const router = new Router(); router.use('/', (_, res, { tb }) => { const boards = getAdminBoards(); res.send(tb.include(AdminBoardsPage, { boards })); res.end(); }); router.use('/create', withQuery('Board name'), (req, res) => { const name = req.query!; createBoard(name); res.redirect('/admin/boards'); }); router.use('/:id/name', withQuery('Board name'), (req, res, { params }) => { const id = parseInt(params.id, 10); const name = req.query!; setBoardName(id, name); res.redirect('/admin/boards'); }); router.use( '/:id/description', withQuery('Board description'), (req, res, { params }) => { const id = parseInt(params.id, 10); const description = req.query!; setBoardDescription(id, description); res.redirect('/admin/boards'); }, ); router.use('/:id/type/:type', (_, res, { params }) => { const id = parseInt(params.id, 10); const type = parseInt(params.type, 10); setBoardType(id, type); res.redirect('/admin/boards'); }); router.use('/:id/enable', (_, res, { params }) => { const id = parseInt(params.id, 10); setBoardDeleted(id, false); res.redirect('/admin/boards'); }); router.use( '/:id/disable', withQuery("Are you sure? (type 'confirm')"), (req, res, { params }) => { if (req.query === 'confirm') { const id = parseInt(params.id, 10); setBoardDeleted(id, true); } res.redirect('/admin/boards'); }, ); export default router;