Fix missing membership profile when create new org
Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
@@ -410,6 +410,14 @@ func (s *OrganizationService) CreateOrganization(
|
|||||||
CreatedAt: now,
|
CreatedAt: now,
|
||||||
UpdatedAt: now,
|
UpdatedAt: now,
|
||||||
}
|
}
|
||||||
|
membership = &coredata.Membership{
|
||||||
|
ID: gid.New(tenantID, coredata.MembershipEntityType),
|
||||||
|
IdentityID: identityID,
|
||||||
|
OrganizationID: organizationID,
|
||||||
|
Role: coredata.MembershipRoleOwner,
|
||||||
|
CreatedAt: now,
|
||||||
|
UpdatedAt: now,
|
||||||
|
}
|
||||||
logoFile *coredata.File
|
logoFile *coredata.File
|
||||||
horizontalLogoFile *coredata.File
|
horizontalLogoFile *coredata.File
|
||||||
scope = coredata.NewScope(tenantID)
|
scope = coredata.NewScope(tenantID)
|
||||||
@@ -492,8 +500,13 @@ func (s *OrganizationService) CreateOrganization(
|
|||||||
err := s.pg.WithTx(
|
err := s.pg.WithTx(
|
||||||
ctx,
|
ctx,
|
||||||
func(tx pg.Conn) error {
|
func(tx pg.Conn) error {
|
||||||
|
identity := &coredata.Identity{}
|
||||||
|
err := identity.LoadByID(ctx, tx, identityID)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("cannot load identity: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
err := organization.Insert(ctx, tx)
|
err = organization.Insert(ctx, tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot insert organization: %w", err)
|
return fmt.Errorf("cannot insert organization: %w", err)
|
||||||
}
|
}
|
||||||
@@ -512,19 +525,24 @@ func (s *OrganizationService) CreateOrganization(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
membership := &coredata.Membership{
|
|
||||||
ID: gid.New(tenantID, coredata.MembershipEntityType),
|
|
||||||
IdentityID: identityID,
|
|
||||||
OrganizationID: organizationID,
|
|
||||||
Role: coredata.MembershipRoleOwner,
|
|
||||||
CreatedAt: now,
|
|
||||||
UpdatedAt: now,
|
|
||||||
}
|
|
||||||
err = membership.Insert(ctx, tx, scope)
|
err = membership.Insert(ctx, tx, scope)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot create membership: %w", err)
|
return fmt.Errorf("cannot create membership: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
profile := &coredata.MembershipProfile{
|
||||||
|
ID: gid.New(tenantID, coredata.MembershipProfileEntityType),
|
||||||
|
MembershipID: membership.ID,
|
||||||
|
FullName: identity.FullName,
|
||||||
|
CreatedAt: now,
|
||||||
|
UpdatedAt: now,
|
||||||
|
}
|
||||||
|
|
||||||
|
err = profile.Insert(ctx, tx)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("cannot insert profile: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user