fixup! fixup! fix(org): adding unique constrants to not allow an org to be added twice with same id

This commit is contained in:
Iraq Jaber
2025-06-30 16:03:55 +02:00
parent 8d99104e3d
commit 66f1fe52e6
20 changed files with 30 additions and 33 deletions

View File

@@ -52,7 +52,6 @@ func NewRemoveOrgNameUniqueConstraint(orgName string) *eventstore.UniqueConstrai
type OrgAddedEvent struct {
eventstore.BaseEvent `json:"-"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
}
@@ -61,7 +60,7 @@ func (e *OrgAddedEvent) Payload() interface{} {
}
func (e *OrgAddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
return []*eventstore.UniqueConstraint{NewAddOrgIDUniqueConstraint(e.ID), NewAddOrgNameUniqueConstraint(e.Name)}
return []*eventstore.UniqueConstraint{NewAddOrgIDUniqueConstraint(e.Aggregate().ID), NewAddOrgNameUniqueConstraint(e.Name)}
}
func (e *OrgAddedEvent) Fields() []*eventstore.FieldOperation {
@@ -108,7 +107,6 @@ func NewOrgAddedEvent(ctx context.Context, aggregate *eventstore.Aggregate, name
aggregate,
OrgAddedEventType,
),
ID: aggregate.ID,
Name: name,
}
}
@@ -291,7 +289,6 @@ func OrgReactivatedEventMapper(event eventstore.Event) (eventstore.Event, error)
type OrgRemovedEvent struct {
eventstore.BaseEvent `json:"-"`
id string
name string
usernames []string
loginMustBeDomain bool
@@ -306,7 +303,7 @@ func (e *OrgRemovedEvent) Payload() interface{} {
func (e *OrgRemovedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
constraints := []*eventstore.UniqueConstraint{
NewRemoveOrgIDUniqueConstraint(e.id),
NewRemoveOrgIDUniqueConstraint(e.Aggregate().ID),
NewRemoveOrgNameUniqueConstraint(e.name),
}
for _, name := range e.usernames {
@@ -338,7 +335,6 @@ func NewOrgRemovedEvent(ctx context.Context, aggregate *eventstore.Aggregate, na
aggregate,
OrgRemovedEventType,
),
id: aggregate.ID,
name: name,
usernames: usernames,
domains: domains,