Update existing people in confirm invitation
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
@@ -802,8 +802,15 @@ func (s Service) ConfirmInvitation(ctx context.Context, tokenString string, pass
|
|||||||
return fmt.Errorf("cannot insert user organization: %w", err)
|
return fmt.Errorf("cannot insert user organization: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
people := &coredata.People{}
|
||||||
|
scope := coredata.NewScope(token.Data.OrganizationID.TenantID())
|
||||||
|
|
||||||
|
if err := people.LoadByEmail(ctx, tx, scope, token.Data.Email); err != nil {
|
||||||
|
var errPeopleNotFound *coredata.ErrPeopleNotFound
|
||||||
|
|
||||||
|
if errors.As(err, &errPeopleNotFound) {
|
||||||
peopleID := gid.New(token.Data.OrganizationID.TenantID(), coredata.PeopleEntityType)
|
peopleID := gid.New(token.Data.OrganizationID.TenantID(), coredata.PeopleEntityType)
|
||||||
people := coredata.People{
|
people = &coredata.People{
|
||||||
ID: peopleID,
|
ID: peopleID,
|
||||||
OrganizationID: token.Data.OrganizationID,
|
OrganizationID: token.Data.OrganizationID,
|
||||||
UserID: &user.ID,
|
UserID: &user.ID,
|
||||||
@@ -815,11 +822,21 @@ func (s Service) ConfirmInvitation(ctx context.Context, tokenString string, pass
|
|||||||
UpdatedAt: now,
|
UpdatedAt: now,
|
||||||
}
|
}
|
||||||
|
|
||||||
scope := coredata.NewScope(token.Data.OrganizationID.TenantID())
|
|
||||||
|
|
||||||
if err := people.Insert(ctx, tx, scope); err != nil {
|
if err := people.Insert(ctx, tx, scope); err != nil {
|
||||||
return fmt.Errorf("cannot insert people: %w", err)
|
return fmt.Errorf("cannot insert people: %w", err)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("cannot load people by email: %w", err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
people.UserID = &user.ID
|
||||||
|
people.FullName = token.Data.FullName
|
||||||
|
people.UpdatedAt = now
|
||||||
|
|
||||||
|
if err := people.Update(ctx, tx, scope); err != nil {
|
||||||
|
return fmt.Errorf("cannot update people: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user