From 872cb94d8cdc1b8a883adf5d61a2678d8a8a0198 Mon Sep 17 00:00:00 2001 From: Nehal Udyavar Date: Tue, 23 Jul 2019 02:08:34 -0700 Subject: [PATCH] PUT request to add subjects to knowledge group --- index.js | 2 +- routes/knowledgeGroupRoutes.js | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 58a963e..a827084 100644 --- a/index.js +++ b/index.js @@ -10,7 +10,7 @@ const app = express(); mongoose.connect( keys.mongoURI, - { useNewUrlParser: true } + { useNewUrlParser: true, useFindAndModify: false } ); app.use(bodyParser.json()); diff --git a/routes/knowledgeGroupRoutes.js b/routes/knowledgeGroupRoutes.js index a9d1cde..d021534 100644 --- a/routes/knowledgeGroupRoutes.js +++ b/routes/knowledgeGroupRoutes.js @@ -46,4 +46,29 @@ module.exports = app => { } }); }); + + // PUT request to add a knowledge map subject into a knowledge group + app.put("/api/knowledge-group/:knowledgeGroupId/add-subject", (req, res) => { + const { knowledgeGroupId } = req.params; + const { knowledgeMapId } = req.body; + + KnowledgeGroup.findOneAndUpdate( + knowledgeGroupId, + { + $push: { + subjects: knowledgeMapId + } + }, + { + new: true + }, + (error, data) => { + if (error) { + res.send(error); + } else { + res.send(data); + } + } + ); + }); };