Files
nlcc-itinerary/server/api/settings/retention-policy.get.ts
Joshua Ryder 66172e0baa Add sermon retention policy feature
Implemented a configurable retention policy system for sermons with automatic cleanup:
- Added settings table to store retention policy configuration
- Created API endpoints for getting/setting retention policy
- Added Database Settings section to admin page with retention options (forever, 1-10 years)
- Implemented manual cleanup endpoint for on-demand deletion
- Added automated daily cleanup task via Nitro plugin
- Sermons are deleted based on their date field according to the retention policy

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-04 14:07:14 -05:00

30 lines
810 B
TypeScript

import { getSessionUsername } from '~/server/utils/auth'
import { getUserByUsername, getSetting } from '~/server/utils/database'
export default defineEventHandler(async (event) => {
// Check if user is authenticated and is admin
const username = await getSessionUsername(event)
if (!username) {
throw createError({
statusCode: 401,
message: 'Unauthorized'
})
}
const user = getUserByUsername(username)
if (!user || user.is_admin !== 1) {
throw createError({
statusCode: 403,
message: 'Forbidden - Admin access required'
})
}
// Get the retention policy setting, default to 'forever' if not set
const setting = getSetting('sermon_retention_policy')
const retentionPolicy = setting ? setting.value : 'forever'
return {
retentionPolicy
}
})