@@ -2,11 +2,11 @@ import connector from "#models/databaseUtil";
22
33const activityBluePrintSchema = {
44 number : { type : Number , required : true } ,
5- academicYearYear : {
5+ academicYear : {
66 type : String ,
77 required : true ,
88 validate : {
9- validator : ( value ) => / ^ 2 \d { 3 } $ / . test ( value ) ,
9+ validator : ( value ) => / ^ 2 0 \d { 2 } $ / . test ( value ) , //changed the valid year format starting from "20" !!
1010 message : ( props ) => `${ props . value } is not a valid year format starting with "2"!` ,
1111 } ,
1212 } ,
@@ -17,3 +17,37 @@ const activityBluePrintSchema = {
1717
1818// eslint-disable-next-line no-unused-vars
1919const ActivityBlueprint = connector . model ( "ActivityBlueprint" , activityBluePrintSchema ) ;
20+
21+ async function remove ( filter ) {
22+ const deleteResult = await ActivityBlueprint . deleteMany ( filter ) ;
23+ return deleteResult . acknowledged ;
24+ }
25+
26+ async function create ( activityBlueprintData ) {
27+ const {
28+ number, academicYear, type, startDate, endDate,
29+ } = activityBlueprintDataData ;
30+ const activityblueprint = new ActivityBlueprint ( {
31+ number,
32+ academicYear,
33+ type,
34+ startDate,
35+ endDate,
36+ } ) ;
37+ const activityblueprintDoc = await activityblueprint . save ( ) ;
38+ return activityblueprintDoc ;
39+ }
40+
41+ async function read ( filter , limit = 1 ) {
42+ const activityblueprintDoc = await ActivityBlueprint . find ( filter ) . limit ( limit ) ;
43+ return activityblueprintDoc ;
44+ }
45+
46+ async function update ( filter , updateObject , options = { multi : true } ) {
47+ const deleteResult = await ActivityBlueprint . updateMany ( filter , { $set : updateObject } , options ) ;
48+ return deleteResult . acknowledged ;
49+ }
50+
51+ export default {
52+ create, read, update, remove,
53+ }
0 commit comments