/** * Required External Modules and Interfaces */ import express, {Request, Response} from 'express'; import {requireAdminAuth} from '../feedback.auth.js'; import {sendServerError} from '../feedback.errors.js'; import {eventsAdminRouter} from './events.admin.router.js'; import {songsAdminRouter} from './songs.admin.router.js'; import {questionsAdminRouter} from './questions.admin.router.js'; import {reportsAdminRouter} from './reports.admin.router.js'; import * as ReportsAdminService from './reports.admin.service.js'; /** * Router Definition */ export const adminRouter = express.Router(); // Applied once at the top of the admin router tree - every route below // requires a valid admin session. adminRouter.use(requireAdminAuth); /** * @swagger * /feedback/admin/me: * get: * summary: Validate the current admin session * description: Used by the Next.js middleware/proxy to gate /admin. Returns the authenticated admin's identity. * tags: [feedback-admin] * parameters: * - $ref: '#/components/parameters/SessionIdHeader' * - $ref: '#/components/parameters/SessionKeyHeader' * responses: * 200: * description: Success * content: * application/json: * schema: * type: object * properties: * email: * type: string * fullName: * type: string * 401: * description: Unauthorized */ adminRouter.get('/me', (req: Request, res: Response) => { res.status(200).send({email: res.locals.admin.email, fullName: res.locals.admin.displayName}); }); /** * @swagger * /feedback/admin/submissions/{submissionId}: * delete: * summary: Delete a single submission * description: Removes the submission and everything under it (its answers, guest book entry, newsletter signup) - for removing an individual abusive or inappropriate entry. Not a bulk moderation tool. * tags: [feedback-admin] * parameters: * - $ref: '#/components/parameters/SessionIdHeader' * - $ref: '#/components/parameters/SessionKeyHeader' * - in: path * name: submissionId * required: true * schema: * type: integer * responses: * 204: * description: Deleted * 404: * description: Unknown submission * 401: * description: Unauthorized */ adminRouter.delete('/submissions/:submissionId', async (req: Request, res: Response) => { try { const deleted = await ReportsAdminService.deleteSubmission(Number(req.params.submissionId)); if (!deleted) { res.status(404).send({status: 'NOT_FOUND'}); return; } res.status(204).send(); } catch (e: any) { sendServerError(res, e); } }); adminRouter.use('/events', eventsAdminRouter); adminRouter.use('/events', reportsAdminRouter); adminRouter.use('/songs', songsAdminRouter); adminRouter.use('/questions', questionsAdminRouter);