foamking/app/api/quotes/route.ts
mikl0s 3a54ba40d3 fix: update quotes route to use checkAuth, fix zod type errors
Replace getCurrentUser import with checkAuth in quotes API route.
Fix z.coerce.number() type mismatch with zodResolver in calculator
forms by using z.number() directly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 22:01:36 +00:00

46 lines
1.4 KiB
TypeScript

import { NextRequest, NextResponse } from "next/server"
import { getAllQuotes, updateQuoteStatus, type QuoteStatus } from "@/lib/db"
import { checkAuth } from "@/lib/auth"
export async function GET() {
try {
const { authenticated } = await checkAuth()
if (!authenticated) {
return NextResponse.json({ error: "Ikke autoriseret" }, { status: 401 })
}
const quotes = getAllQuotes()
return NextResponse.json({ quotes })
} catch {
return NextResponse.json({ error: "Der opstod en fejl" }, { status: 500 })
}
}
export async function PATCH(request: NextRequest) {
try {
const { authenticated } = await checkAuth()
if (!authenticated) {
return NextResponse.json({ error: "Ikke autoriseret" }, { status: 401 })
}
const { id, status } = await request.json()
if (!id || !status) {
return NextResponse.json({ error: "ID og status er påkrævet" }, { status: 400 })
}
const validStatuses: QuoteStatus[] = ["new", "contacted", "accepted", "rejected"]
if (!validStatuses.includes(status)) {
return NextResponse.json({ error: "Ugyldig status" }, { status: 400 })
}
const success = updateQuoteStatus(id, status)
if (!success) {
return NextResponse.json({ error: "Tilbud ikke fundet" }, { status: 404 })
}
return NextResponse.json({ success: true })
} catch {
return NextResponse.json({ error: "Der opstod en fejl" }, { status: 500 })
}
}