-
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
Showing
3 changed files
with
36 additions
and
21 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 |
---|---|---|
@@ -1,26 +1,29 @@ | ||
import ReplyModel from "../models/Reply.js"; | ||
import { handleServerError, handleSuccess } from '../utils/handlers.js'; | ||
import { handleServerError, handleSuccess } from "../utils/handlers.js"; | ||
|
||
// Reply to a message | ||
export const reply_to_message = async (req, res) => { | ||
try { | ||
const reply = await ReplyModel.create({ | ||
parent_message: req.body.message_id, | ||
content: req.body.content, | ||
}).exec(); | ||
handleSuccess(res, reply); | ||
} catch (err) { | ||
handleServerError(res, err); | ||
} | ||
try { | ||
const reply = await ReplyModel.create({ | ||
parent_message: req.body.message_id, | ||
content: req.body.content, | ||
}).exec(); | ||
handleSuccess(res, reply); | ||
} catch (err) { | ||
handleServerError(res, err); | ||
} | ||
}; | ||
|
||
// changes value of like field in ReplySchema to true. | ||
export const like_reply = async (req, res) => { | ||
try { | ||
const reply = await ReplyModel.findByIdAndUpdate(req.body._id, {likes: true}, {new: true}).exec(); | ||
handleSuccess(res, reply); | ||
} catch (err) { | ||
handleServerError(res, err); | ||
} | ||
try { | ||
const reply = await ReplyModel.findByIdAndUpdate( | ||
req.body._id, | ||
{ likes: true }, | ||
{ new: true } | ||
).exec(); | ||
handleSuccess(res, reply); | ||
} catch (err) { | ||
handleServerError(res, err); | ||
} | ||
}; | ||
|
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