Skip to content

Commit e148259

Browse files
authored
Merge pull request #79 from tcet-opensource/49-CURD-Accreditation_Model
Performed Crud on AccreditationModel
2 parents e62916e + a38f4b1 commit e148259

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

models/accreditation.js

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,42 @@
11
import connector from "#models/databaseUtil";
22

33
const accreditationSchema = {
4-
uid :{type : String, unique: true , required: true},
5-
accreditationName: {type: String, required: true},
6-
agencyName: {type: String, required: true},
7-
dateofAccreditation: {type: Date, required: true},
8-
dateofExpiry: {type: Date, required: true}
4+
uid: { type: String, unique: true, required: true },
5+
accreditationName: { type: String, required: true },
6+
agencyName: { type: String, required: true },
7+
dateofAccreditation: { type: Date, required: true },
8+
dateofExpiry: { type: Date, required: true },
99
};
1010

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

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

0 commit comments

Comments
 (0)