Skip to content

Commit 2daf48e

Browse files
committed
Performed Crud on AccreditationModel
1 parent 90dfe45 commit 2daf48e

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

models/accreditation.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import connector from "#models/databaseUtil";
2+
import { logger } from "#util";
23

4+
connector.set("debug", true);
35
const accreditationSchema = {
46
uid :{type : String, unique: true , required: true},
57
accreditationName: {type: String, required: true},
@@ -8,6 +10,34 @@ const accreditationSchema = {
810
dateofExpiry: {type: Date, required: true}
911
};
1012

11-
const AccreditationModel = new connector.model('Accreditation', accreditationSchema);
13+
const Accreditation = new connector.model('Accreditation', accreditationSchema);
1214

13-
export default AccreditationModel;
15+
async function remove(filter) {
16+
const res = await Accreditation.findOneAndDelete(filter);
17+
return res;
18+
}
19+
20+
async function create(uid,accreditationName,agencyName,dateofAccreditation,dateofExpiry) {
21+
const accreditation = new Accreditation({
22+
accreditationName,
23+
agencyName,
24+
uid,
25+
dateofAccreditation,
26+
dateofExpiry
27+
});
28+
const accreditationDoc = await accreditation.save();
29+
return accreditationDoc;
30+
}
31+
32+
async function read(filter, limit = 1) {
33+
const accreditationData = await Accreditation.find(filter).limit(limit);
34+
return accreditationData;
35+
}
36+
37+
async function update(filter, updateObject) {
38+
const accreditation = await Accreditation.findOneAndUpdate(filter, updateObject, { new : true});
39+
return accreditation;
40+
}
41+
export default {
42+
create, read, update, remove
43+
};

0 commit comments

Comments
 (0)