Files
Newbie_CRM/src/app/client-portal/api/projects/route.ts
T
2026-07-01 12:08:22 +02:00

25 lines
809 B
TypeScript

import { NextResponse } from "next/server"
import { query } from "@/lib/db"
import { getPortalSession, isPortalError } from "../portal-utils"
export async function GET() {
const session = await getPortalSession()
if (isPortalError(session)) return session
if (!session.customerId) {
return NextResponse.json({ projects: [] })
}
const result = await query(
`SELECT p.id, p.name, p.description, p.start_date, p.target_end_date as end_date,
p.budget, p.created_at, p.updated_at, s.name as status_name, s.color as status_color
FROM projects p
LEFT JOIN project_statuses s ON s.id = p.status_id
WHERE p.customer_id = $1 AND p.deleted_at IS NULL
ORDER BY p.created_at DESC`,
[session.customerId],
)
return NextResponse.json({ projects: result.rows })
}