Skip to content

Commit 46241a6

Browse files
committed
[Added]added CURD to coursework
1 parent da0c5e1 commit 46241a6

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

models/coursework.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,39 @@ const courseworkSchema = {
1212

1313
// eslint-disable-next-line no-unused-vars
1414
const Coursework = connector.model("Coursework", courseworkSchema);
15+
16+
async function remove(filter) {
17+
const deleteResult = await Coursework.deleteMany(filter);
18+
return deleteResult.acknowledged;
19+
}
20+
21+
async function create(courseworkData) {
22+
const {
23+
student,type,course,task,objectID,activity,marks
24+
} = courseworkData;
25+
const coursework = new Coursework({
26+
student,
27+
type,
28+
course,
29+
task,
30+
objectID,
31+
activity,
32+
marks
33+
});
34+
const courseworkDoc = await coursework.save();
35+
return courseworkDoc;
36+
}
37+
38+
async function read(filter, limit = 1) {
39+
const courseworkDoc = await Coursework.find(filter).limit(limit);
40+
return courseworkDoc;
41+
}
42+
43+
async function update(filter, updateObject, options = { multi: true }) {
44+
const updateResult = await Coursework.updateMany(filter, { $set: updateObject }, options);
45+
return updateResult.acknowledged;
46+
}
47+
48+
export default {
49+
create, read, update, remove,
50+
};

0 commit comments

Comments
 (0)