Skip to content

Commit

Permalink
feat: api for creating new team
Browse files Browse the repository at this point in the history
  • Loading branch information
Sid-80 committed Jul 10, 2024
1 parent f7142ae commit 09ba55b
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/app/api/teams/create/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { mongoDB } from "@/lib/MongoDB";
import { AuthMiddleware } from "@/Middleware/AuthMiddleware";
import TeamModel from "@/models/team";
import { ApiUser } from "@/types/types";
import { NextResponse } from "next/server";

export const POST = async (req: Request) => {

const result = await AuthMiddleware(req);

if (result instanceof NextResponse) {

try {
const { teamName } = await req.json();

await mongoDB();

const user: ApiUser = JSON.parse(req.headers.get("user") || "{}");

const team = await TeamModel.create({
teamName,
createdBy:user._id,
teamMembers:[user._id]
});

return NextResponse.json({ status: 200 });
} catch (err) {
return NextResponse.json(`Err : ${err}`, {status:500});
}
} else {
return result;
}
};

0 comments on commit 09ba55b

Please sign in to comment.