mirror of
https://github.com/SkalaraAI/beta.git
synced 2025-04-09 15:00:20 -04:00
50 lines
1.3 KiB
TypeScript
50 lines
1.3 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, projectID },
|
|
}: { params: { workspaceID: string; projectID: 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 feature = await prisma.feature.create({
|
|
data: {
|
|
name,
|
|
description,
|
|
project_id: BigInt(projectID),
|
|
},
|
|
});
|
|
|
|
const res = {
|
|
...feature,
|
|
id: String(feature.id),
|
|
project_id: String(feature.project_id),
|
|
};
|
|
|
|
return NextResponse.json({ project: res }, { status: 200 });
|
|
} catch (err) {
|
|
console.log(err);
|
|
return NextResponse.json({ error: err }, { status: 500 });
|
|
}
|
|
}
|