dow-prod-tracker/src/lib/api-utils.ts
Leivur R. Djurhuus 2859a50761 Add Project CRUD: API routes, service layer, form, and list page
- Zod validation schemas for create/update project
- Service layer with listProjects, getProject, createProject,
  updateProject, deleteProject
- API routes: GET/POST /api/projects, GET/PATCH/DELETE /api/projects/:id
- TanStack Query hooks for all project operations
- Project list page with card grid, status/priority badges
- Project create dialog with form validation
- QueryProvider + API utility helpers

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-28 21:11:46 -06:00

27 lines
769 B
TypeScript

import { NextResponse } from "next/server";
import { auth } from "@/lib/auth";
export async function getAuthSession() {
const session = await auth();
if (!session?.user?.id) {
return { session: null, error: unauthorized() };
}
return { session, error: null };
}
export function unauthorized() {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
export function badRequest(message: string) {
return NextResponse.json({ error: message }, { status: 400 });
}
export function notFound(message = "Not found") {
return NextResponse.json({ error: message }, { status: 404 });
}
export function serverError(error: unknown) {
console.error(error);
return NextResponse.json({ error: "Internal server error" }, { status: 500 });
}