@@ -5,29 +5,27 @@ const _ = require('lodash')
55module . exports = function ( ) {
66
77 return function verifyProperties ( obj , properties ) {
8- return properties
9- . every ( ( property ) => {
10-
11- let propertyPath = property . split ( "." ) . slice ( 0 , - 1 ) ;
12-
13-
14- if ( _ . isArray ( _ . get ( obj , propertyPath ) ) ) {
15-
16- const propertie = [ property . split ( "." ) . pop ( ) ]
17-
18- return _ . get ( obj , propertyPath ) . every ( ( item ) => verifyProperties ( item , propertie ) ) ;
19-
20- } else if ( _ . isArray ( _ . get ( obj , propertyPath [ 0 ] ) ) ) {
21-
22-
23- const subproperties = properties . map ( el => el . split ( '.' ) . slice ( 1 ) . join ( '.' ) )
24-
25- return _ . get ( obj , propertyPath [ 0 ] ) . every ( ( item ) => verifyProperties ( item , subproperties ) )
26-
27- } else {
28- return _ . has ( obj , property )
29- }
30- }
31- ) ;
32- }
33- }
8+ return properties . every ( ( property ) => {
9+ const propertyPath = property . split ( "." ) . filter ( Boolean ) ;
10+
11+ if ( _ . isArray ( _ . get ( obj , propertyPath . slice ( 0 , - 1 ) ) ) ) {
12+ const parentArray = _ . get ( obj , propertyPath . slice ( 0 , - 1 ) ) ;
13+ const lastProperty = propertyPath [ propertyPath . length - 1 ] ;
14+
15+ return parentArray . every ( ( item ) => verifyProperties ( item , [ lastProperty ] ) ) ;
16+
17+ } else if ( _ . isArray ( _ . get ( obj , propertyPath [ 0 ] ) ) ) {
18+ const parentArray = _ . get ( obj , propertyPath [ 0 ] ) ;
19+
20+ const subProperties = properties
21+ . filter ( ( prop ) => prop . startsWith ( propertyPath [ 0 ] ) )
22+ . map ( ( prop ) => prop . split ( '.' ) . slice ( 1 ) . join ( '.' ) )
23+ . filter ( Boolean ) ;
24+
25+ return parentArray . every ( ( item ) => verifyProperties ( item , subProperties ) ) ;
26+ }
27+
28+ return _ . has ( obj , property ) ;
29+ } ) ;
30+ } ;
31+ }
0 commit comments