Skip to content

Commit

Permalink
added populate on remove tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Giovanni Troisi committed Dec 6, 2024
1 parent e1a1256 commit 444b043
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions routes/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -955,15 +955,26 @@ router.delete('/:requestid/tag/:tag_id', async (req, res) => {
let tag_id = req.params.tag_id;


Request.findOneAndUpdate({ id_project: id_project, request_id: request_id }, { $pull: { tags: { _id: tag_id } } }, { new: true }).then((updatedRequest) => {

Request.findOneAndUpdate({ id_project: id_project, request_id: request_id }, { $pull: { tags: { _id: tag_id } } }, { new: true }).then( async (updatedRequest) => {

if (!updatedRequest) {
winston.warn("(Request) /removetag request not found with id: " + request_id)
return res.status(404).send({ success: false, error: "Request not found with id " + request_id})
}

winston.debug("(Request) /removetag updatedRequest: ", updatedRequest)
requestEvent.emit("request.update", updatedRequest);

const populatedRequest =
await updatedRequest
.populate('lead')
.populate('department')
.populate('participatingBots')
.populate('participatingAgents')
.populate({ path: 'requester', populate: { path: 'id_user' } })
.execPopulate();

requestEvent.emit("request.update", populatedRequest)
res.status(200).send(updatedRequest);

}).catch((err) => {
Expand Down

0 comments on commit 444b043

Please sign in to comment.