Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions app/api/applications/team/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
export const runtime = "nodejs";

import { NextResponse } from "next/server";
import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

export async function POST(request: Request) {
try {
const body = await request.json();
const { teamName, projectTitle, budget, description } = body;

// Server-side validation
if (!teamName || !projectTitle || !budget || !description) {
return NextResponse.json(
{ error: "Missing required fields" },
{ status: 400 },
);
}

// Parse budget to number
const parsedBudget = Number(String(budget).replace(/[^0-9.-]+/g, ""));
if (isNaN(parsedBudget)) {
return NextResponse.json(
{ error: "Budget must be a valid number" },
{ status: 400 },
);
}

// Create application in DB
const application = await prisma.application.create({
data: {
type: "TEAM",
status: "PENDING",
submitterName: teamName,
submitterEmail: "N/A", // placeholder, can be updated later
payload: {
teamName,
projectTitle,
budget: parsedBudget,
description,
},
},
});

return NextResponse.json(
{
success: true,
id: application.id,
},
{ status: 201 },
);
} catch (error) {
console.error(error);
return NextResponse.json(
{ error: "Failed to create application" },
{ status: 500 },
);
}
}