Fix people not create when user already exist

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
Bryan Frimin
2025-05-13 15:05:52 -07:00
parent 5b9d529532
commit e53f278053
2 changed files with 90 additions and 0 deletions

View File

@@ -660,6 +660,34 @@ func (s Service) InviteUser(
return fmt.Errorf("cannot insert user organization: %w", err)
}
people := &coredata.People{}
scope := coredata.NewScope(organizationID.TenantID())
if err := people.LoadByEmail(ctx, tx, scope, emailAddress); err != nil {
var errPeopleNotFound *coredata.ErrPeopleNotFound
if errors.As(err, &errPeopleNotFound) {
people = &coredata.People{
ID: gid.New(organizationID.TenantID(), coredata.PeopleEntityType),
OrganizationID: organizationID,
UserID: &user.ID,
FullName: fullName,
PrimaryEmailAddress: emailAddress,
Kind: coredata.PeopleKindContractor,
AdditionalEmailAddresses: []string{},
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}
if err := people.Insert(ctx, tx, scope); err != nil {
return fmt.Errorf("cannot insert people: %w", err)
}
return nil
}
return fmt.Errorf("cannot load people by email: %w", err)
}
return nil
},
)