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); + } + } + ); + }); };