mirror of
https://github.com/SkalaraAI/beta.git
synced 2025-04-09 15:00:20 -04:00
54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
import { createRouteHandlerClient } from "@supabase/auth-helpers-nextjs";
|
|
import { cookies } from "next/headers";
|
|
import { NextResponse, NextRequest } from "next/server";
|
|
import { Database } from "@/types/supabase";
|
|
import { prisma } from "@/lib/prisma";
|
|
|
|
async function getSession(supabase: any) {
|
|
const {
|
|
data: { session },
|
|
} = await supabase.auth.getSession();
|
|
return session;
|
|
}
|
|
|
|
export async function POST(
|
|
req: NextRequest,
|
|
{ params: { workspaceID } }: { params: { workspaceID: string } }
|
|
) {
|
|
try {
|
|
const supabase = createRouteHandlerClient<Database>({ cookies });
|
|
const session = await getSession(supabase);
|
|
|
|
if (!session) return NextResponse.redirect("/auth");
|
|
|
|
const formData = await req.json();
|
|
const name = String(formData.name);
|
|
const description = String(formData.description);
|
|
const stack = formData.stack;
|
|
|
|
const project = await prisma.project.create({
|
|
data: {
|
|
name,
|
|
description,
|
|
stack,
|
|
workspace_id: BigInt(workspaceID),
|
|
},
|
|
});
|
|
|
|
await prisma.profile_project.create({
|
|
data: { profile_id: session.user.id, project_id: project.id },
|
|
});
|
|
|
|
const res = {
|
|
...project,
|
|
id: String(project.id),
|
|
workspace_id: String(project.workspace_id),
|
|
};
|
|
|
|
return NextResponse.json({ project: res }, { status: 200 });
|
|
} catch (err) {
|
|
console.log(err);
|
|
return NextResponse.json({ error: err }, { status: 500 });
|
|
}
|
|
}
|