@@ -22,42 +22,50 @@ const setup = function(fileUploadOptions) {
2222 app . use ( expressFileupload ( fileUploadOptions ) ) ;
2323
2424 app . all ( '/upload/single' , function ( req , res ) {
25- if ( ! req . files )
25+ if ( ! req . files ) {
2626 return res . status ( 400 ) . send ( 'No files were uploaded.' ) ;
27+ }
2728
2829 let testFile = req . files . testFile ;
2930 let uploadPath = path . join ( uploadDir , testFile . name ) ;
3031
3132 testFile . mv ( uploadPath , function ( err ) {
32- if ( err )
33+ if ( err ) {
3334 return res . status ( 500 ) . send ( err ) ;
35+ }
3436
3537 res . send ( 'File uploaded to ' + uploadPath ) ;
3638 } ) ;
3739 } ) ;
3840
3941 app . all ( '/upload/single/withfields' , function ( req , res ) {
40- if ( ! req . files )
42+ if ( ! req . files ) {
4143 return res . status ( 400 ) . send ( 'No files were uploaded.' ) ;
44+ }
4245
43- if ( ! req . body )
46+ if ( ! req . body ) {
4447 return res . status ( 400 ) . send ( 'No request body found' ) ;
48+ }
4549
46- if ( ! req . body . firstName || ! req . body . firstName . trim ( ) )
50+ if ( ! req . body . firstName || ! req . body . firstName . trim ( ) ) {
4751 return res . status ( 400 ) . send ( 'Invalid first name' ) ;
52+ }
4853
49- if ( ! req . body . lastName || ! req . body . lastName . trim ( ) )
54+ if ( ! req . body . lastName || ! req . body . lastName . trim ( ) ) {
5055 return res . status ( 400 ) . send ( 'Invalid last name' ) ;
56+ }
5157
52- if ( ! req . body . email || ! req . body . email . trim ( ) )
58+ if ( ! req . body . email || ! req . body . email . trim ( ) ) {
5359 return res . status ( 400 ) . send ( 'Invalid email' ) ;
60+ }
5461
5562 let testFile = req . files . testFile ;
5663 let uploadPath = path . join ( uploadDir , testFile . name ) ;
5764
5865 testFile . mv ( uploadPath , function ( err ) {
59- if ( err )
66+ if ( err ) {
6067 return res . status ( 500 ) . send ( err ) ;
68+ }
6169
6270 res . json ( {
6371 firstName : req . body . firstName ,
@@ -68,8 +76,9 @@ const setup = function(fileUploadOptions) {
6876 } ) ;
6977
7078 app . all ( '/upload/multiple' , function ( req , res ) {
71- if ( ! req . files )
79+ if ( ! req . files ) {
7280 return res . status ( 400 ) . send ( 'No files were uploaded.' ) ;
81+ }
7382
7483 let testFile1 = req . files . testFile1 ;
7584 let testFile2 = req . files . testFile2 ;
@@ -78,26 +87,32 @@ const setup = function(fileUploadOptions) {
7887 let uploadPath2 = path . join ( uploadDir , testFile2 . name ) ;
7988 let uploadPath3 = path . join ( uploadDir , testFile3 . name ) ;
8089
81- if ( ! testFile1 )
90+ if ( ! testFile1 ) {
8291 return res . status ( 400 ) . send ( 'testFile1 was not uploaded' ) ;
92+ }
8393
84- if ( ! testFile2 )
94+ if ( ! testFile2 ) {
8595 return res . status ( 400 ) . send ( 'testFile2 was not uploaded' ) ;
96+ }
8697
87- if ( ! testFile3 )
98+ if ( ! testFile3 ) {
8899 return res . status ( 400 ) . send ( 'testFile3 was not uploaded' ) ;
100+ }
89101
90102 testFile1 . mv ( uploadPath1 , function ( err ) {
91- if ( err )
103+ if ( err ) {
92104 return res . status ( 500 ) . send ( err ) ;
105+ }
93106
94107 testFile2 . mv ( uploadPath2 , function ( err ) {
95- if ( err )
108+ if ( err ) {
96109 return res . status ( 500 ) . send ( err ) ;
110+ }
97111
98112 testFile3 . mv ( uploadPath3 , function ( err ) {
99- if ( err )
113+ if ( err ) {
100114 return res . status ( 500 ) . send ( err ) ;
115+ }
101116
102117 res . send ( 'Files uploaded to ' + uploadDir ) ;
103118 } ) ;
@@ -106,46 +121,56 @@ const setup = function(fileUploadOptions) {
106121 } ) ;
107122
108123 app . all ( '/upload/array' , function ( req , res ) {
109- if ( ! req . files )
124+ if ( ! req . files ) {
110125 return res . status ( 400 ) . send ( 'No files were uploaded.' ) ;
126+ }
111127
112128 let testFiles = req . files . testFiles ;
113129
114- if ( ! testFiles )
130+ if ( ! testFiles ) {
115131 return res . status ( 400 ) . send ( 'No files were uploaded' ) ;
132+ }
116133
117- if ( ! Array . isArray ( testFiles ) )
134+ if ( ! Array . isArray ( testFiles ) ) {
118135 return res . status ( 400 ) . send ( 'Files were not uploaded as an array' ) ;
136+ }
119137
120- if ( ! testFiles . length )
138+ if ( ! testFiles . length ) {
121139 return res . status ( 400 ) . send ( 'Files array is empty' ) ;
140+ }
122141
123142 let filesUploaded = 0 ;
124143 for ( let i = 0 ; i < testFiles . length ; i ++ ) {
125144 let uploadPath = path . join ( uploadDir , testFiles [ i ] . name ) ;
126145
127146 testFiles [ i ] . mv ( uploadPath , function ( err ) {
128- if ( err )
147+ if ( err ) {
129148 return res . status ( 500 ) . send ( err ) ;
149+ }
130150
131- if ( ++ filesUploaded === testFiles . length )
151+ if ( ++ filesUploaded === testFiles . length ) {
132152 res . send ( 'File uploaded to ' + uploadPath ) ;
153+ }
133154 } ) ;
134155 }
135156 } ) ;
136157
137158 app . all ( '/fields/user' , function ( req , res ) {
138- if ( ! req . body )
159+ if ( ! req . body ) {
139160 return res . status ( 400 ) . send ( 'No request body found' ) ;
161+ }
140162
141- if ( ! req . body . firstName || ! req . body . firstName . trim ( ) )
163+ if ( ! req . body . firstName || ! req . body . firstName . trim ( ) ) {
142164 return res . status ( 400 ) . send ( 'Invalid first name' ) ;
165+ }
143166
144- if ( ! req . body . lastName || ! req . body . lastName . trim ( ) )
167+ if ( ! req . body . lastName || ! req . body . lastName . trim ( ) ) {
145168 return res . status ( 400 ) . send ( 'Invalid last name' ) ;
169+ }
146170
147- if ( ! req . body . email || ! req . body . email . trim ( ) )
171+ if ( ! req . body . email || ! req . body . email . trim ( ) ) {
148172 return res . status ( 400 ) . send ( 'Invalid email' ) ;
173+ }
149174
150175 res . json ( {
151176 firstName : req . body . firstName ,
@@ -155,14 +180,17 @@ const setup = function(fileUploadOptions) {
155180 } ) ;
156181
157182 app . all ( '/fields/array' , function ( req , res ) {
158- if ( ! req . body )
183+ if ( ! req . body ) {
159184 return res . status ( 400 ) . send ( 'No request body found' ) ;
185+ }
160186
161- if ( ! req . body . testField )
187+ if ( ! req . body . testField ) {
162188 return res . status ( 400 ) . send ( 'Invalid field' ) ;
189+ }
163190
164- if ( ! Array . isArray ( req . body . testField ) )
191+ if ( ! Array . isArray ( req . body . testField ) ) {
165192 return res . status ( 400 ) . send ( 'Field is not an array' ) ;
193+ }
166194
167195 res . json ( req . body . testField ) ;
168196 } ) ;
0 commit comments