39 lines
1.3 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server'
import {
createNotificationCenterProject,
listNotificationCenterProjects,
} from '@/lib/notification-center-admin'
import {
requireNotificationCenterSuperAdmin,
toNotificationCenterAdminErrorResponse,
} from '../_shared'
export const runtime = 'nodejs'
export const dynamic = 'force-dynamic'
export async function GET(request: NextRequest) {
try {
const auth = await requireNotificationCenterSuperAdmin()
if ('response' in auth) return auth.response
const result = await listNotificationCenterProjects(auth.actor, new URL(request.url).searchParams)
return NextResponse.json({ success: true, data: result.data }, { status: result.status })
} catch (error) {
return toNotificationCenterAdminErrorResponse(error)
}
}
export async function POST(request: NextRequest) {
try {
const auth = await requireNotificationCenterSuperAdmin()
if ('response' in auth) return auth.response
const body = await request.json().catch(() => ({}))
const result = await createNotificationCenterProject(auth.actor, body)
return NextResponse.json({ success: true, data: result.data }, { status: result.status })
} catch (error) {
return toNotificationCenterAdminErrorResponse(error)
}
}