feat(db): phase 4 group 6 — server component pages to Drizzle
Converts all 18 server component page files from Supabase client queries to Drizzle ORM using asAdmin. Adds getSession() + redirect to the three pages (hse/incidents, hse/incidents/[id], hse/dashboard) that lacked it. Maps snake_case component prop shapes explicitly where required. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
import { redirect } from 'next/navigation'
|
||||
import { createClient } from '@/lib/supabase/server'
|
||||
import { asAdmin } from '@/lib/db/with-user'
|
||||
import { getSession } from '@/lib/auth/get-session'
|
||||
import { appSettings } from '@/lib/db/schema'
|
||||
import { ApiKeyForm } from '@/components/settings/api-key-form'
|
||||
|
||||
export default async function SettingsPage() {
|
||||
@@ -10,14 +11,16 @@ export default async function SettingsPage() {
|
||||
if (!session) redirect('/login')
|
||||
if (session.role !== 'admin') redirect('/hse/dashboard')
|
||||
|
||||
const supabase = await createClient()
|
||||
|
||||
const { data: settings } = await supabase
|
||||
.from('app_settings')
|
||||
.select('key, value, updated_at')
|
||||
const settingRows = await asAdmin(db =>
|
||||
db.select({
|
||||
key: appSettings.key,
|
||||
value: appSettings.value,
|
||||
updatedAt: appSettings.updatedAt,
|
||||
}).from(appSettings)
|
||||
)
|
||||
|
||||
const settingsMap = Object.fromEntries(
|
||||
(settings ?? []).map(s => [s.key, { set: Boolean(s.value), updated_at: s.updated_at }])
|
||||
settingRows.map(s => [s.key, { set: Boolean(s.value), updated_at: s.updatedAt?.toISOString() ?? null }])
|
||||
)
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user