fix: add migration (#361)

* fix: add migration

* fix: add migration

* fix: delete primary domain

* Update en.yaml

Co-authored-by: Livio Amstutz <livio.a@gmail.com>
This commit is contained in:
Fabi
2020-07-07 14:23:09 +02:00
committed by GitHub
parent eaef079852
commit fb2091edc9
5 changed files with 14 additions and 6 deletions

View File

@@ -49,13 +49,13 @@ func (o *Org) IsValid() bool {
return o.Name != ""
}
func (o *Org) ContainsDomain(domain *OrgDomain) bool {
for _, d := range o.Domains {
func (o *Org) GetDomain(domain *OrgDomain) (int, *OrgDomain) {
for i, d := range o.Domains {
if d.Domain == domain.Domain {
return true
return i, d
}
}
return false
return -1, nil
}
func (o *Org) GetPrimaryDomain() *OrgDomain {

View File

@@ -179,9 +179,13 @@ func (es *OrgEventstore) RemoveOrgDomain(ctx context.Context, domain *org_model.
if err != nil {
return err
}
if !existing.ContainsDomain(domain) {
_, d := existing.GetDomain(domain)
if d == nil {
return errors.ThrowPreconditionFailed(nil, "EVENT-Sjdi3", "Errors.Org.DomainNotOnOrg")
}
if d.Primary {
return errors.ThrowPreconditionFailed(nil, "EVENT-Sjdi3", "Errors.Org.PrimaryDomainNotDeletable")
}
repoOrg := model.OrgFromModel(existing)
repoDomain := model.OrgDomainFromModel(domain)
orgAggregates, err := OrgDomainRemovedAggregate(ctx, es.Eventstore.AggregateCreator(), repoOrg, repoDomain)