forked from BasirKhan418/Project-Studio
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
1cb8d61
commit 6978b73
Showing
2 changed files
with
35 additions
and
3 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
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import connectDb from "../../../middleware/mongoose"; | ||
import Chat from "../../../../models/Chat"; | ||
|
||
const handler = async (req, res) => { | ||
if (req.method == 'POST'){ | ||
try{ | ||
const {chatName, isGroupChat, users, groupAdmin} = req.body; | ||
|
||
const chat = new Chat({ | ||
chatName, | ||
isGroupChat, | ||
users, | ||
groupAdmin, | ||
}) | ||
|
||
await chat.save(); | ||
|
||
res.status(200).json({message: "Chat created successfully", chat}); | ||
} | ||
catch (error){ | ||
console.error('Error creating chat: ', error); | ||
res.status(500).json({error: "Internal server error"}); | ||
} | ||
|
||
} | ||
else{ | ||
res.status(400).json({error: "Bad request"}); | ||
} | ||
} | ||
|
||
export default connectDb(handler); |