@@ -31,10 +31,10 @@ const workingDaySchema = new mongoose.Schema({
3131 }
3232} , { _id : false } ) ;
3333
34- workingDaySchema . pre ( 'validate' , function ( next ) {
34+ workingDaySchema . pre ( 'validate' , function ( ) {
3535
3636 if ( ! this . isAvailable && this . slots . length > 0 ) {
37- return next ( new Error ( "Slots cannot exist when doctor is unavailable" ) ) ;
37+ return new Error ( "Slots cannot exist when doctor is unavailable" ) ;
3838 }
3939
4040 const sorted = [ ...this . slots ] . sort ( ( a , b ) =>
@@ -44,15 +44,13 @@ workingDaySchema.pre('validate', function(next) {
4444 for ( let i = 0 ; i < sorted . length ; i ++ ) {
4545
4646 if ( sorted [ i ] . startTime >= sorted [ i ] . endTime ) {
47- return next ( new Error ( "Start time must be before end time" ) ) ;
47+ return new Error ( "Start time must be before end time" ) ;
4848 }
4949
5050 if ( i > 0 && sorted [ i - 1 ] . endTime > sorted [ i ] . startTime ) {
51- return next ( new Error ( "Overlapping time slots detected" ) ) ;
51+ return new Error ( "Overlapping time slots detected" ) ;
5252 }
5353 }
54-
55- next ( ) ;
5654} ) ;
5755
5856const DEFAULT_WORKING_HOURS = [
@@ -115,29 +113,24 @@ const userSchema = new mongoose.Schema({
115113} , { timestamps : true } ) ;
116114
117115
118- userSchema . pre ( 'validate' , function ( next ) {
116+ userSchema . pre ( 'validate' , function ( ) {
119117
120118 if ( this . role === 'doctor' && this . workingHours ) {
121119 const days = this . workingHours . map ( d => d . day ) ;
122120 const uniqueDays = new Set ( days ) ;
123121
124122 if ( days . length !== uniqueDays . size ) {
125- return next ( new Error ( "Duplicate days are not allowed" ) ) ;
123+ return new Error ( "Duplicate days are not allowed" ) ;
126124 }
127125 }
128-
129- next ( ) ;
130126} ) ;
131127
132- userSchema . pre ( 'save' , function ( next ) {
128+ userSchema . pre ( 'save' , function ( ) {
133129
134130 if ( this . role === 'doctor' && ( ! this . workingHours || this . workingHours . length === 0 ) ) {
135131 this . workingHours = DEFAULT_WORKING_HOURS ;
136132 }
137-
138- next ( ) ;
139133} ) ;
140134
141-
142135const User = mongoose . models . User || mongoose . model ( 'User' , userSchema ) ;
143136export default User ;
0 commit comments