sofia-cloud / src /app /api /repos /route.ts
Gmagl
Fix: Complete TypeScript strict typing for all API routes
5cff373
raw
history blame
921 Bytes
import { NextRequest, NextResponse } from "next/server";
import { db } from "@/lib/db";
export async function GET() {
try {
const repos = await db.repo.findMany({ orderBy: { createdAt: "desc" } });
return NextResponse.json({ success: true, repos });
} catch {
return NextResponse.json({ success: false, error: "Error" }, { status: 500 });
}
}
export async function POST(request: NextRequest) {
try {
const body = await request.json();
const { url, name, projectId } = body;
if (!url) {
return NextResponse.json({ success: false, error: "URL requerida" }, { status: 400 });
}
const repo = await db.repo.create({
data: { url, name: name || url.split("/").pop() || "repo", projectId: projectId || null }
});
return NextResponse.json({ success: true, repo });
} catch {
return NextResponse.json({ success: false, error: "Error" }, { status: 500 });
}
}