Skip to content

Commit 90f5852

Browse files
committed
#71 CRUD operation for attendance model
1 parent b9407ff commit 90f5852

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

models/attendance.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
11
import connector from "./databaseUtil";
22
import Infrastructure from "./infrastructure";
3+
34
connector.set("debug", true);
45

56
const attendanceSchema = {
67
date: { type: Date, required: true },
78
time: { type: String, required: true },
9+
absentees: { type: Array },
810
class: Infrastructure,
911
};
1012

1113
const Attendance = connector.model("Attendance", attendanceSchema);
1214

15+
async function create(date, time, absentees) {
16+
const attendance = new Attendance({
17+
date,
18+
time,
19+
absentees,
20+
});
21+
const newAttendence = await attendance.save();
22+
return newAttendence;
23+
}
24+
25+
async function remove(filter) {
26+
const res = await Attendance.findOneAndDelete(filter);
27+
return res;
28+
}
29+
30+
async function grantAttendance(roll, date) {
31+
const res = await Attendance.findOneAndUpdate(date, {$pull: { absentees: roll } }, { new: true });
32+
return res;
33+
}
34+
1335
export default {
14-
Attendance,
15-
};
36+
create, remove, grantAttendance,
37+
};

0 commit comments

Comments
 (0)