foamking/app/api/quotes/route.ts
mikl0s 3ebb63dc6c Add admin dashboard, authentication, step wizard, and quote management
Expand the calculator with a multi-step wizard flow, admin dashboard with
quote tracking, login/auth system, distance API integration, and history
page. Add new UI components (dialog, progress, select, slider, switch),
update pricing logic, and improve the overall design with new assets.

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

48 lines
1.5 KiB
TypeScript

import { NextRequest, NextResponse } from "next/server"
import { getAllQuotes, updateQuoteStatus, type QuoteStatus } from "@/lib/db"
import { getCurrentUser } from "@/lib/auth"
export async function GET() {
try {
const user = await getCurrentUser()
if (!user) {
return NextResponse.json({ error: "Ikke autoriseret" }, { status: 401 })
}
const quotes = getAllQuotes()
return NextResponse.json({ quotes })
} catch (error) {
console.error("Get quotes error:", error)
return NextResponse.json({ error: "Der opstod en fejl" }, { status: 500 })
}
}
export async function PATCH(request: NextRequest) {
try {
const user = await getCurrentUser()
if (!user) {
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 (error) {
console.error("Update quote error:", error)
return NextResponse.json({ error: "Der opstod en fejl" }, { status: 500 })
}
}