37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { NextResponse } from "next/server"
|
|
import { getServiceSupabase } from "@/lib/supabase/client"
|
|
import { getAuthenticatedUser } from "@/lib/server/auth"
|
|
|
|
export const runtime = "nodejs"
|
|
|
|
const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
|
|
|
|
export async function POST(request: Request) {
|
|
try {
|
|
const user = await getAuthenticatedUser()
|
|
if (!user) {
|
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 })
|
|
}
|
|
|
|
const { id } = (await request.json()) as { id?: string }
|
|
if (!id || !UUID_PATTERN.test(id)) {
|
|
return NextResponse.json({ error: "id must be a valid sprint UUID" }, { status: 400 })
|
|
}
|
|
|
|
const supabase = getServiceSupabase()
|
|
const { data, error } = await supabase
|
|
.from("sprints")
|
|
.update({ status: "completed" })
|
|
.eq("id", id)
|
|
.select("*")
|
|
.single()
|
|
|
|
if (error) throw error
|
|
|
|
return NextResponse.json({ success: true, sprint: data })
|
|
} catch (error) {
|
|
console.error(">>> API POST /sprints/close error:", error)
|
|
return NextResponse.json({ error: "Failed to close sprint" }, { status: 500 })
|
|
}
|
|
}
|