Files
cat-sitting-planner/app/api/plan/route.ts

28 lines
867 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 { startDate, endDate, password, instructions } = body;
if (!startDate || !endDate || !password) {
return NextResponse.json({ error: 'Missing required fields' }, { status: 400 });
}
const plan = await prisma.plan.create({
data: {
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 });
}
}