created by for sermons
This commit is contained in:
@@ -89,6 +89,11 @@
|
||||
<div class="border-b pb-6 mb-8">
|
||||
<h1 class="text-4xl font-bold text-gray-900 mb-2">{{ sermon.title }}</h1>
|
||||
<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>
|
||||
|
||||
<!-- 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: authData } = await useFetch('/api/auth/verify')
|
||||
const isAuthenticated = computed(() => authData.value?.authenticated || false)
|
||||
const isAdmin = computed(() => authData.value?.isAdmin || false)
|
||||
|
||||
// Font size state
|
||||
const fontSize = ref('medium')
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getSermonBySlug } from '~/server/utils/database'
|
||||
import { getSermonBySlug, getUserByUsername } from '~/server/utils/database'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
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
|
||||
}
|
||||
})
|
||||
|
||||
@@ -34,14 +34,15 @@ export default defineEventHandler(async (event) => {
|
||||
|
||||
try {
|
||||
createSermon({
|
||||
slug,
|
||||
title,
|
||||
date,
|
||||
dates,
|
||||
bible_references,
|
||||
personal_appliance,
|
||||
pastors_challenge,
|
||||
worship_songs
|
||||
slug: body.slug,
|
||||
title: body.title,
|
||||
date: body.date,
|
||||
dates: body.dates,
|
||||
bible_references: body.bible_references,
|
||||
personal_appliance: body.personal_appliance,
|
||||
pastors_challenge: body.pastors_challenge,
|
||||
worship_songs: body.worship_songs,
|
||||
created_by: username
|
||||
})
|
||||
|
||||
return {
|
||||
|
||||
@@ -14,6 +14,7 @@ export interface Sermon {
|
||||
personal_appliance: string
|
||||
pastors_challenge: string
|
||||
worship_songs?: string
|
||||
created_by?: string
|
||||
created_at?: string
|
||||
}
|
||||
|
||||
@@ -77,10 +78,18 @@ export function getDatabase() {
|
||||
personal_appliance TEXT NOT NULL,
|
||||
pastors_challenge TEXT NOT NULL,
|
||||
worship_songs TEXT,
|
||||
created_by TEXT,
|
||||
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(`
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
@@ -184,8 +193,8 @@ export function getSermonBySlug(slug: string) {
|
||||
export function createSermon(sermon: Sermon) {
|
||||
const db = getDatabase()
|
||||
const stmt = db.prepare(`
|
||||
INSERT INTO sermons (slug, title, date, dates, bible_references, personal_appliance, pastors_challenge, worship_songs)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
INSERT INTO sermons (slug, title, date, dates, bible_references, personal_appliance, pastors_challenge, worship_songs, created_by)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`)
|
||||
return stmt.run(
|
||||
sermon.slug,
|
||||
@@ -195,7 +204,8 @@ export function createSermon(sermon: Sermon) {
|
||||
sermon.bible_references,
|
||||
sermon.personal_appliance,
|
||||
sermon.pastors_challenge,
|
||||
sermon.worship_songs || null
|
||||
sermon.worship_songs || null,
|
||||
sermon.created_by || null
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user