Add archive functionality: database schema, API endpoint, and helper functions

This commit is contained in:
2025-10-01 23:49:44 -04:00
parent 160d898d94
commit 4b47f56b30
2 changed files with 70 additions and 15 deletions

View File

@@ -0,0 +1,42 @@
import { isAuthenticated } from '~/server/utils/auth'
import { archiveSermon } from '~/server/utils/database'
export default defineEventHandler(async (event) => {
// Check authentication
if (!isAuthenticated(event)) {
throw createError({
statusCode: 401,
message: 'Unauthorized'
})
}
const id = getRouterParam(event, 'id')
if (!id) {
throw createError({
statusCode: 400,
message: 'Sermon ID is required'
})
}
try {
const result = archiveSermon(parseInt(id))
if (result.changes === 0) {
throw createError({
statusCode: 404,
message: 'Sermon not found'
})
}
return {
success: true,
message: 'Sermon archived successfully'
}
} catch (error: any) {
throw createError({
statusCode: 500,
message: error.message || 'Failed to archive sermon'
})
}
})