Add unarchive functionality and show archived status in admin dropdown
This commit is contained in:
@@ -3,8 +3,9 @@ import { getAllSermons } from '~/server/utils/database'
|
||||
export default defineEventHandler(async (event) => {
|
||||
const query = getQuery(event)
|
||||
const limit = query.limit ? parseInt(query.limit as string) : undefined
|
||||
const includeArchived = query.includeArchived === 'true'
|
||||
|
||||
const sermons = getAllSermons(limit)
|
||||
const sermons = getAllSermons(limit, includeArchived)
|
||||
|
||||
return sermons
|
||||
})
|
||||
|
||||
43
server/api/sermons/unarchive/[id].post.ts
Normal file
43
server/api/sermons/unarchive/[id].post.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { isAuthenticated } from '~/server/utils/auth'
|
||||
import { getDatabase } 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 db = getDatabase()
|
||||
const result = db.prepare('UPDATE sermons SET archived = 0 WHERE id = ?').run(parseInt(id))
|
||||
|
||||
if (result.changes === 0) {
|
||||
throw createError({
|
||||
statusCode: 404,
|
||||
message: 'Sermon not found'
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: 'Sermon unarchived successfully'
|
||||
}
|
||||
} catch (error: any) {
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
message: error.message || 'Failed to unarchive sermon'
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user