Files
nlcc-itinerary/server/api/sermons/index.post.ts
2025-10-02 08:59:05 -04:00

46 lines
1.0 KiB
TypeScript

import { createSermon } from '~/server/utils/database'
import { isAuthenticated } from '~/server/utils/auth'
export default defineEventHandler(async (event) => {
// Check authentication
if (!isAuthenticated(event)) {
throw createError({
statusCode: 401,
message: 'Unauthorized'
})
}
const body = await readBody(event)
const { slug, title, date, dates, bible_references, personal_appliance, pastors_challenge, worship_songs } = body
if (!slug || !title || !date || !bible_references || !personal_appliance || !pastors_challenge) {
throw createError({
statusCode: 400,
message: 'All fields are required'
})
}
try {
createSermon({
slug,
title,
date,
dates,
bible_references,
personal_appliance,
pastors_challenge,
worship_songs
})
return {
success: true,
message: 'Sermon created successfully'
}
} catch (error: any) {
throw createError({
statusCode: 500,
message: error.message || 'Failed to create sermon'
})
}
})