created by for sermons

This commit is contained in:
2025-10-12 01:01:01 -04:00
parent e313def354
commit a505edcae7
4 changed files with 43 additions and 14 deletions

View File

@@ -89,6 +89,11 @@
<div class="border-b pb-6 mb-8"> <div class="border-b pb-6 mb-8">
<h1 class="text-4xl font-bold text-gray-900 mb-2">{{ sermon.title }}</h1> <h1 class="text-4xl font-bold text-gray-900 mb-2">{{ sermon.title }}</h1>
<p class="text-lg text-gray-600">{{ formatDateRange(sermon) }}</p> <p class="text-lg text-gray-600">{{ formatDateRange(sermon) }}</p>
<ClientOnly>
<p v-if="isAdmin && sermon.creator_name" class="text-sm text-gray-500 mt-2">
Created by: {{ sermon.creator_name }}
</p>
</ClientOnly>
</div> </div>
<!-- Section 1: Bible References --> <!-- Section 1: Bible References -->
@@ -254,6 +259,7 @@ const slug = route.params.slug as string
const { data: sermon } = await useFetch(`/api/sermons/${slug}`) const { data: sermon } = await useFetch(`/api/sermons/${slug}`)
const { data: authData } = await useFetch('/api/auth/verify') const { data: authData } = await useFetch('/api/auth/verify')
const isAuthenticated = computed(() => authData.value?.authenticated || false) const isAuthenticated = computed(() => authData.value?.authenticated || false)
const isAdmin = computed(() => authData.value?.isAdmin || false)
// Font size state // Font size state
const fontSize = ref('medium') const fontSize = ref('medium')

View File

@@ -1,4 +1,4 @@
import { getSermonBySlug } from '~/server/utils/database' import { getSermonBySlug, getUserByUsername } from '~/server/utils/database'
export default defineEventHandler(async (event) => { export default defineEventHandler(async (event) => {
const slug = getRouterParam(event, 'slug') const slug = getRouterParam(event, 'slug')
@@ -19,5 +19,17 @@ export default defineEventHandler(async (event) => {
}) })
} }
return sermon // If sermon has a creator, get their name
let creatorName = null
if (sermon.created_by) {
const creator = getUserByUsername(sermon.created_by)
if (creator && creator.first_name && creator.last_name) {
creatorName = `${creator.first_name} ${creator.last_name}`
}
}
return {
...sermon,
creator_name: creatorName
}
}) })

View File

@@ -34,14 +34,15 @@ export default defineEventHandler(async (event) => {
try { try {
createSermon({ createSermon({
slug, slug: body.slug,
title, title: body.title,
date, date: body.date,
dates, dates: body.dates,
bible_references, bible_references: body.bible_references,
personal_appliance, personal_appliance: body.personal_appliance,
pastors_challenge, pastors_challenge: body.pastors_challenge,
worship_songs worship_songs: body.worship_songs,
created_by: username
}) })
return { return {

View File

@@ -14,6 +14,7 @@ export interface Sermon {
personal_appliance: string personal_appliance: string
pastors_challenge: string pastors_challenge: string
worship_songs?: string worship_songs?: string
created_by?: string
created_at?: string created_at?: string
} }
@@ -77,10 +78,18 @@ export function getDatabase() {
personal_appliance TEXT NOT NULL, personal_appliance TEXT NOT NULL,
pastors_challenge TEXT NOT NULL, pastors_challenge TEXT NOT NULL,
worship_songs TEXT, worship_songs TEXT,
created_by TEXT,
archived INTEGER DEFAULT 0, archived INTEGER DEFAULT 0,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP created_at DATETIME DEFAULT CURRENT TIMESTAMP
) )
`) `)
// Add created_by column if it doesn't exist (migration)
try {
db.exec(`ALTER TABLE sermons ADD COLUMN created_by TEXT`)
} catch (e) {
// Column already exists, ignore error
}
db.exec(` db.exec(`
CREATE TABLE IF NOT EXISTS users ( CREATE TABLE IF NOT EXISTS users (
@@ -184,8 +193,8 @@ export function getSermonBySlug(slug: string) {
export function createSermon(sermon: Sermon) { export function createSermon(sermon: Sermon) {
const db = getDatabase() const db = getDatabase()
const stmt = db.prepare(` const stmt = db.prepare(`
INSERT INTO sermons (slug, title, date, dates, bible_references, personal_appliance, pastors_challenge, worship_songs) INSERT INTO sermons (slug, title, date, dates, bible_references, personal_appliance, pastors_challenge, worship_songs, created_by)
VALUES (?, ?, ?, ?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
`) `)
return stmt.run( return stmt.run(
sermon.slug, sermon.slug,
@@ -195,7 +204,8 @@ export function createSermon(sermon: Sermon) {
sermon.bible_references, sermon.bible_references,
sermon.personal_appliance, sermon.personal_appliance,
sermon.pastors_challenge, sermon.pastors_challenge,
sermon.worship_songs || null sermon.worship_songs || null,
sermon.created_by || null
) )
} }