Files
config-vault/app/api/apps/[id]/route.ts
T
2026-08-26 14:21:53 +03:00

33 lines
1.2 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server'
import { getServerSession } from 'next-auth'
import { authOptions } from '@/lib/auth'
import sql from '@/lib/db'
export async function DELETE(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
const session = await getServerSession(authOptions)
if (!session) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
const { id } = await params
await sql`DELETE FROM apps WHERE id = ${id}`
return NextResponse.json({ success: true })
}
export async function PATCH(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
const session = await getServerSession(authOptions)
if (!session) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
const { id } = await params
const { name, description, icon_url } = await req.json()
const [app] = await sql`
UPDATE apps SET
name = COALESCE(${name}, name),
description = ${description !== undefined ? description : sql`description`},
icon_url = ${icon_url !== undefined ? icon_url : sql`icon_url`},
updated_at = NOW()
WHERE id = ${id}
RETURNING *
`
return NextResponse.json(app)
}