@@ -8,7 +8,7 @@ const transform = require('lodash/transform');
88const utils = require ( '../utils' ) ;
99
1010const { AttributeError, ConsumableError, DomainError, FkError, UniquenessError } = errors ;
11- const { findIndexViolations, findViolationsDuplicates, validateAssociation } = utils ;
11+ const { findIndexViolations, findViolationsDuplicates, validateBelongsTo , validateConsumables } = utils ;
1212
1313class SyncModuleValidator {
1414 constructor ( syncModule ) {
@@ -24,7 +24,6 @@ class SyncModuleValidator {
2424 }
2525
2626 get associations ( ) {
27- // TODO: add check for consumability
2827 const types = [ 'BelongsTo' , 'BelongsToMany' , 'HasMany' ] ;
2928 const addJunction = it => this . Model . associations [ it . as ] ||
3029 this . Model . hasMany ( it . target , it ) ;
@@ -36,12 +35,12 @@ class SyncModuleValidator {
3635
3736 async run ( entries ) {
3837 try {
38+ await this . syncModule . errors . flush ( ) ;
3939 await this . validateAttributes ( ) ;
4040 await this . validateUniqueness ( ) ;
41- this . validateFks ( ) ;
41+ await this . validateFks ( ) ;
4242 await this . validateDependencies ( ) ;
43- this . validateConsumables ( ) ;
44- this . validateDomain ( ) ;
43+ await this . validateConsumables ( ) ;
4544 return this . syncModule . errors . invalidate ( { model : this . Model } ) ;
4645 } catch ( err ) {
4746 // TODO: throw real error here
@@ -86,7 +85,7 @@ class SyncModuleValidator {
8685 const associationType = 'BelongsTo' ;
8786 const associations = filter ( this . associations , { associationType } ) ;
8887 const validateFk = ( instance , association ) => {
89- if ( validateAssociation ( instance , association ) ) return ;
88+ if ( validateBelongsTo ( instance , association ) ) return ;
9089 return this . pushError ( FkError , instance , association ) ;
9190 } ;
9291 return this . overAssociations ( associations , validateFk ) ;
@@ -103,11 +102,12 @@ class SyncModuleValidator {
103102 }
104103
105104 validateConsumables ( ) {
105+ const associations = filter ( this . associations , 'options.consumable' ) ;
106106 const validateConsumable = ( instance , association ) => {
107- if ( validateAssociation ( instance , association ) ) return ;
107+ if ( validateConsumables ( instance , association ) ) return ;
108108 return this . pushError ( ConsumableError , instance , association ) ;
109109 } ;
110- return this . overAssociations ( this . associations , validateConsumable ) ;
110+ return this . overAssociations ( associations , validateConsumable ) ;
111111 }
112112
113113 async validateDomain ( ) {
0 commit comments