diff --git a/pages/[slug].vue b/pages/[slug].vue
index 08d1082..32075fc 100644
--- a/pages/[slug].vue
+++ b/pages/[slug].vue
@@ -89,6 +89,11 @@
{{ sermon.title }}
{{ formatDateRange(sermon) }}
+
+
+ Created by: {{ sermon.creator_name }}
+
+
@@ -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')
diff --git a/server/api/sermons/[slug].get.ts b/server/api/sermons/[slug].get.ts
index a9b0e26..8fe374a 100644
--- a/server/api/sermons/[slug].get.ts
+++ b/server/api/sermons/[slug].get.ts
@@ -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
+ }
})
diff --git a/server/api/sermons/index.post.ts b/server/api/sermons/index.post.ts
index 8abe709..e940a14 100644
--- a/server/api/sermons/index.post.ts
+++ b/server/api/sermons/index.post.ts
@@ -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 {
diff --git a/server/utils/database.ts b/server/utils/database.ts
index 0c2b4b0..1fe6dc1 100644
--- a/server/utils/database.ts
+++ b/server/utils/database.ts
@@ -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
)
}