Skip to content

Commit

Permalink
Merge pull request #452 from Sid-80/api/createFile
Browse files Browse the repository at this point in the history
Api/create file
  • Loading branch information
subhadeeproy3902 authored Jul 10, 2024
2 parents 9ac749b + 09ba55b commit b250e84
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 b250e84

Please sign in to comment.