11import connector from "#models/databaseUtil" ;
22
33const 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