File tree 2 files changed +18
-9
lines changed
2 files changed +18
-9
lines changed Original file line number Diff line number Diff line change @@ -25,12 +25,9 @@ class Model {
25
25
// * =================
26
26
27
27
// ! TESTING PURPOSES ONLY FOR NOW
28
- test = cb => {
28
+ test = ( data , cb ) => {
29
29
if ( this . validate ) {
30
- let valid = validate . valid ( this . schema , {
31
- username : 'dog' ,
32
- number : 'cow'
33
- } ) ;
30
+ let valid = validate . valid ( this . schema , data ) ;
34
31
console . log ( valid ) ;
35
32
cb ( valid ) ;
36
33
} else {
Original file line number Diff line number Diff line change @@ -8,15 +8,16 @@ function htmlEntities(str) {
8
8
. replace ( / " / g, '"' ) ;
9
9
}
10
10
11
- const stringed = data => {
11
+ function stringed ( data ) {
12
12
for ( var index in data ) {
13
13
data [ index ] = htmlEntities ( data [ index ] ) ;
14
14
}
15
- } ;
15
+ return data ;
16
+ }
16
17
17
18
const valid = ( schema , data ) => {
18
- //stringed(data);
19
19
let ret = { } ;
20
+ ret [ 'body' ] = { } ;
20
21
ret [ 'errors' ] = { state : false } ;
21
22
let errors = [ ] ;
22
23
matchHash = false ;
@@ -183,17 +184,28 @@ const valid = (schema, data) => {
183
184
flag = true ;
184
185
}
185
186
}
187
+ if ( k == 'type' ) {
188
+ if ( schema [ key ] [ k ] == 'number' ) {
189
+ if ( typeof data [ key ] != 'number' ) {
190
+ errors . push (
191
+ key + ' needs to be a numerical value'
192
+ ) ;
193
+ flag = true ;
194
+ }
195
+ }
196
+ }
186
197
}
187
198
}
188
199
if ( ! flag ) {
189
- ret [ key ] = data [ key ] ;
200
+ ret [ 'body' ] [ key ] = data [ key ] ;
190
201
}
191
202
}
192
203
}
193
204
if ( errors . length > 0 ) {
194
205
ret [ 'errors' ] = { state : true } ;
195
206
ret [ 'errors' ] [ 'messages' ] = errors ;
196
207
}
208
+ ret [ 'body' ] = stringed ( ret [ 'body' ] ) ;
197
209
return ret ;
198
210
} ;
199
211
You can’t perform that action at this time.
0 commit comments