-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
7,814 additions
and
10,855 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,49 @@ | ||
import dbConnect from "../../../../lib/dbConnect"; | ||
import { teamSchema } from "../../../../model/Schema/teamSchema"; | ||
import { TeamModel } from "../../../../model/Team"; | ||
|
||
export async function POST(request) { | ||
await dbConnect(); | ||
|
||
try { | ||
const { teamname, game, role, rank, server, language, players, requests } = await request.json(); | ||
// Parse JSON body from the request | ||
const { teamname, game, role, rank, server, language, players, participantCount} = await request.json(); | ||
|
||
await TeamModel.create({ | ||
teamname, | ||
game, | ||
role, | ||
rank, | ||
server, | ||
language, | ||
players, | ||
requests | ||
}); | ||
// Zod validation | ||
const parsedData = teamSchema.parse({ | ||
teamname, | ||
game, | ||
role, | ||
rank, | ||
server, | ||
language, | ||
players, | ||
participantCount, | ||
// requests, | ||
}); | ||
|
||
// Ensure 'requests' is always an array | ||
const formattedData = { | ||
...parsedData, | ||
requests: Array.isArray(parsedData.requests) ? parsedData.requests : [parsedData.requests], | ||
}; | ||
|
||
// Create a new team document in the database | ||
const team = await TeamModel.create(formattedData); | ||
|
||
console.log("Team created successfully:", team); | ||
|
||
return Response.json({ | ||
success: true, | ||
message: 'Team created successfully.' | ||
message: "Team created successfully.", | ||
team, | ||
}, { status: 201 }); | ||
|
||
} catch (error) { | ||
console.error('Error creating team:', error); | ||
console.error("Error creating team:", error); | ||
return Response.json({ | ||
success: false, | ||
message: 'Error creating team' | ||
message: "Error creating team", | ||
error: error.message, | ||
}, { status: 500 }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.