feat: add project creator role on register user (#222)

* feat: add project creator role on register user

* fix: better error message

* fix: tests
This commit is contained in:
Fabi
2020-06-15 14:57:19 +02:00
committed by GitHub
parent e63179514c
commit 8dd6082b17
7 changed files with 46 additions and 10 deletions

View File

@@ -62,7 +62,7 @@ func precondtion(tx *sql.Tx, aggregate *models.Aggregate) error {
}
err = aggregate.Precondition.Validation(events...)
if err != nil {
return caos_errs.ThrowPreconditionFailed(err, "SQL-s6hqU", "validation failed")
return err
}
return nil
}

View File

@@ -362,7 +362,7 @@ func Test_precondtion(t *testing.T) {
expectBegin(nil).expectFilterEventsLimit(5, 0),
},
args: args{
aggregate: aggregateWithPrecondition(&models.Aggregate{}, models.NewSearchQuery().SetLimit(5), validationFunc(errors.CreateCaosError(nil, "SQL-LBIKm", "err"))),
aggregate: aggregateWithPrecondition(&models.Aggregate{}, models.NewSearchQuery().SetLimit(5), validationFunc(errors.ThrowPreconditionFailed(nil, "SQL-LBIKm", "err"))),
},
isErr: errors.IsPreconditionFailed,
},

View File

@@ -85,7 +85,10 @@ func (a *Aggregate) Validate() error {
if a.resourceOwner == "" {
return errors.ThrowPreconditionFailed(nil, "MODEL-eBYUW", "resource owner not set")
}
if a.Precondition != nil && (a.Precondition.Query == nil || a.Precondition.Query.Validate() != nil || a.Precondition.Validation == nil) {
if a.Precondition != nil && (a.Precondition.Query == nil || a.Precondition.Validation == nil) {
if err := a.Precondition.Query.Validate(); err != nil {
return err
}
return errors.ThrowPreconditionFailed(nil, "MODEL-EEUvA", "invalid precondition")
}