Initial commit for wedding-planner MVP
This commit is contained in:
20
app/api/events/route.ts
Normal file
20
app/api/events/route.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { auth } from '@/lib/auth';
|
||||
import { mutations } from '@/lib/mutations';
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const session = await auth();
|
||||
if (!session?.user) return new NextResponse('Unauthorized', { status: 401 });
|
||||
|
||||
const body = await req.json();
|
||||
const { name, date, location } = body;
|
||||
|
||||
const event = await mutations.createEvent({
|
||||
name,
|
||||
date,
|
||||
location,
|
||||
creatorId: session.user.id,
|
||||
});
|
||||
|
||||
return NextResponse.json(event)
|
||||
}
|
||||
21
app/api/setup/route.ts
Normal file
21
app/api/setup/route.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { prisma } from '@/lib/prisma';
|
||||
import bcrypt from 'bcrypt';
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const { email, password, role } = await req.json();
|
||||
|
||||
const existing = await prisma.user.findUnique({ where: { email }});
|
||||
if (existing) return new NextResponse('User already exists', { status: 400 });
|
||||
|
||||
const hashed = await bcrypt.hash(password, 10);
|
||||
const user = await prisma.user.create({
|
||||
data: {
|
||||
email,
|
||||
password: hashed,
|
||||
role
|
||||
}
|
||||
});
|
||||
|
||||
return NextResponse.json(user)
|
||||
}
|
||||
Reference in New Issue
Block a user