36 lines
896 B
TypeScript
36 lines
896 B
TypeScript
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
import prisma from '../../lib/prisma';
|
|
import {getSession} from "next-auth/client";
|
|
import {create} from "domain";
|
|
|
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|
|
|
const session = await getSession({req: req});
|
|
|
|
if (!session) {
|
|
res.status(401).json({message: "Not authenticated"});
|
|
return;
|
|
}
|
|
|
|
if (req.method === "POST") {
|
|
const createTeam = await prisma.team.create({
|
|
data: {
|
|
name: req.body.name,
|
|
},
|
|
});
|
|
|
|
const createMembership = await prisma.membership.create({
|
|
data: {
|
|
teamId: createTeam.id,
|
|
userId: session.user.id,
|
|
role: 'OWNER',
|
|
accepted: true,
|
|
}
|
|
});
|
|
|
|
return res.status(201).setHeader('Location', 'https://calendso.alexvanandel.com/api/teams/1').send(null);
|
|
}
|
|
|
|
res.status(404).send(null);
|
|
}
|