diff --git a/models/topic.js b/models/topic.js index 7a479fc..6c676e6 100644 --- a/models/topic.js +++ b/models/topic.js @@ -5,3 +5,33 @@ const topicSchema = { }; // eslint-disable-next-line no-unused-vars const Topic = connector.model("topic", topicSchema); + +//CURD operations +async function create(topicData) { + const{ + title + }=topicData; + const topic = new Topic({ + title, + }); + const topicDoc = await topic.save(); + return topicDoc; +} + +async function read(filter, limit = 1) { + const topicDoc = await Topic.find(filter).limit(limit); + return topicDoc; +} + +async function update(filter, updateObject, options = { multi: true }) { + const updateResult = await Topic.updateMany(filter, { $set: updateObject }, options); + return updateResult.acknowledged; +} + +async function remove(filter) { + const deleteResult = await Topic.deleteMany(filter); + return deleteResult.acknowledged; +} +export default { + create, remove, update, read, +};