const express = require('express'); const rateLimit = require('express-rate-limit'); const router = express.Router(); const { getConsent, answerConsent, listEventConsent, resendRequest, resendPending, rerequestConsent, medicalList } = require('../controllers/consentController'); const { protect, staff, supervisor } = require('../middleware/authMiddleware'); const { scopeEvent } = require('../utils/campusScope'); // The token in the link is the parent's only credential, so keep guessing slow. const consentLimiter = rateLimit({ windowMs: 60 * 1000, max: 30, message: { message: 'Too many attempts. Please try again in a minute.' } }); router.get('/events/:eventId', protect, staff, scopeEvent(), listEventConsent); router.post('/events/:eventId/resend-pending', protect, supervisor, scopeEvent(), resendPending); router.post('/events/:eventId/rerequest', protect, supervisor, scopeEvent(), rerequestConsent); router.get('/events/:eventId/medical', protect, supervisor, scopeEvent(), medicalList); router.post('/requests/:id/resend', protect, scopeEvent({ resolve: 'consentRequest', ownerOk: true }), resendRequest); // Public consent page router.get('/:token', consentLimiter, getConsent); router.post('/:token', consentLimiter, answerConsent); module.exports = router;