@@ -84,6 +84,7 @@ const emptyInputCheck = ({
8484 checkGet = true ,
8585 emptyBodyMsg = 'The request body is empty!' ,
8686 emptyFieldMsg = 'Some fields are missing!' ,
87+ supressFieldKey = false ,
8788} = { } ) => {
8889
8990 return ( req , res , next ) => {
@@ -102,7 +103,6 @@ const emptyInputCheck = ({
102103 }
103104 }
104105
105-
106106 //Deconstruct the request to get the body out
107107 const { body, } = req ;
108108
@@ -116,6 +116,7 @@ const emptyInputCheck = ({
116116 //Array for storing non-0 values
117117 let checkZ = [ ] ;
118118 let zArray = [ ] ;
119+ let KeyArray = [ ] ;
119120
120121 //Extract the value from the request body
121122 for ( const key in body ) {
@@ -124,6 +125,7 @@ const emptyInputCheck = ({
124125
125126 if ( element !== 0 ) {
126127 checkZ . push ( element ) ;
128+ KeyArray . push ( key ) ;
127129 }
128130
129131 if ( element === 0 ) {
@@ -140,14 +142,26 @@ const emptyInputCheck = ({
140142 //Check for falsy values in the array without 0s
141143 for ( let index = 0 ; index < checkZ . length ; index ++ ) {
142144 const nonZinput = checkZ [ index ] ;
145+ const nonZinputKey = KeyArray [ index ] ;
143146
144147 //Return false if there is any falsy value
145- if ( ! nonZinput ) {
148+ if ( ! nonZinput && supressFieldKey === false ) {
149+ res . status ( 400 ) . json ( {
150+ msg : emptyFieldMsg ,
151+ field : nonZinputKey ,
152+ } ) ;
153+ return ;
154+ }
146155
147- res . status ( 400 ) . json ( { msg : emptyFieldMsg , } ) ;
156+ //Supress field key
157+ if ( ! nonZinput ) {
158+ res . status ( 400 ) . json ( {
159+ msg : emptyFieldMsg ,
160+ } ) ;
148161 return ;
149162 }
150163
164+
151165 }
152166
153167 return next ( ) ;
0 commit comments