29 lines
907 B
TypeScript
29 lines
907 B
TypeScript
import { NextResponse } from 'next/server';
|
|
import prisma from '@/lib/prisma';
|
|
|
|
export async function POST(req: Request) {
|
|
try {
|
|
const body = await req.json();
|
|
const { title, startDate, endDate, password, instructions } = body;
|
|
|
|
if (!title || !startDate || !endDate || !password) {
|
|
return NextResponse.json({ error: 'Missing required fields' }, { status: 400 });
|
|
}
|
|
|
|
const plan = await prisma.plan.create({
|
|
data: {
|
|
title,
|
|
startDate: new Date(startDate),
|
|
endDate: new Date(endDate),
|
|
password,
|
|
instructions,
|
|
},
|
|
});
|
|
|
|
return NextResponse.json({ planId: plan.id });
|
|
} catch (error) {
|
|
console.error('Error creating plan:', error);
|
|
return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 });
|
|
}
|
|
}
|