This commit is contained in:
2025-10-06 17:20:26 -04:00
parent 291b6743c5
commit 2dbd4f6ba0
4 changed files with 211 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
import { getSermonNote, getUserByUsername } from '~/server/utils/database'
import { getAuthCookie } from '~/server/utils/auth'
export default defineEventHandler(async (event) => {
const username = getAuthCookie(event)
if (!username) {
throw createError({
statusCode: 401,
message: 'Unauthorized'
})
}
const user = getUserByUsername(username)
if (!user) {
throw createError({
statusCode: 401,
message: 'User not found'
})
}
const sermonId = parseInt(event.context.params?.sermonId || '')
if (isNaN(sermonId)) {
throw createError({
statusCode: 400,
message: 'Invalid sermon ID'
})
}
const note = getSermonNote(user.id!, sermonId)
return {
notes: note?.notes || ''
}
})

View File

@@ -0,0 +1,50 @@
import { saveSermonNote, getUserByUsername } from '~/server/utils/database'
import { getAuthCookie } from '~/server/utils/auth'
export default defineEventHandler(async (event) => {
const username = getAuthCookie(event)
if (!username) {
throw createError({
statusCode: 401,
message: 'Unauthorized'
})
}
const user = getUserByUsername(username)
if (!user) {
throw createError({
statusCode: 401,
message: 'User not found'
})
}
const sermonId = parseInt(event.context.params?.sermonId || '')
const body = await readBody(event)
const { notes } = body
if (isNaN(sermonId)) {
throw createError({
statusCode: 400,
message: 'Invalid sermon ID'
})
}
if (typeof notes !== 'string') {
throw createError({
statusCode: 400,
message: 'Notes must be a string'
})
}
try {
saveSermonNote(user.id!, sermonId, notes)
return { success: true }
} catch (error) {
throw createError({
statusCode: 500,
message: 'Failed to save notes'
})
}
})