Skip to content

Commit b45abd9

Browse files
committed
[Feat]Added CRUD to practical.js
1 parent b220726 commit b45abd9

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

models/practical.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,38 @@ const practicalSchema = {
1414

1515
// eslint-disable-next-line no-unused-vars
1616
const Practical = connector.model("Practical", practicalSchema);
17+
18+
//CRUD operations
19+
async function remove(filter) {
20+
const deleteResult = await Practical.deleteMany(filter);
21+
return deleteResult.acknowledged;
22+
}
23+
24+
async function create(practicalData) {
25+
const {
26+
no, type, title, hours, cognitiveLevels,
27+
} = practicalData;
28+
const practical = new Practical({
29+
no,
30+
type,
31+
title,
32+
hours,
33+
cognitiveLevels,
34+
});
35+
const practicalDoc = await practical.save();
36+
return practicalDoc;
37+
}
38+
39+
async function read(filter, limit = 1) {
40+
const practicalDoc = await Practical.find(filter).limit(limit);
41+
return practicalDoc;
42+
}
43+
44+
async function update(filter, updateObject, options = { multi: true }) {
45+
const updateResult = await Practical.updateMany(filter, { $set: updateObject }, options);
46+
return updateResult.acknowledged;
47+
}
48+
49+
export default {
50+
create, read, update, remove,
51+
};

0 commit comments

Comments
 (0)