Skip to content

Commit 0115853

Browse files
committed
added curd operations to topic model
1 parent b220726 commit 0115853

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

models/topic.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,33 @@ const topicSchema = {
55
};
66
// eslint-disable-next-line no-unused-vars
77
const Topic = connector.model("topic", topicSchema);
8+
9+
//CURD operations
10+
async function create(topicData) {
11+
const{
12+
title
13+
}=topicData;
14+
const topic = new Topic({
15+
title,
16+
});
17+
const topicDoc = await topic.save();
18+
return topicDoc;
19+
}
20+
21+
async function read(filter, limit = 1) {
22+
const topicDoc = await Topic.find(filter).limit(limit);
23+
return topicDoc;
24+
}
25+
26+
async function update(filter, updateObject, options = { multi: true }) {
27+
const updateResult = await Topic.updateMany(filter, { $set: updateObject }, options);
28+
return updateResult.acknowledged;
29+
}
30+
31+
async function remove(filter) {
32+
const deleteResult = await Topic.deleteMany(filter);
33+
return deleteResult.acknowledged;
34+
}
35+
export default {
36+
create, remove, update, read,
37+
};

0 commit comments

Comments
 (0)