Handle membership not found

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-05-12 18:25:44 +04:00
parent d1578a46b7
commit d40e9a157b

View File

@@ -1021,11 +1021,25 @@ func (s *OrganizationService) UpdateUser(ctx context.Context, req *UpdateUserReq
}
membership := &coredata.Membership{}
var webhookPayload *webhooktypes.User
if err := membership.LoadByIdentityIDAndOrganizationID(ctx, conn, scope, profile.IdentityID, profile.OrganizationID); err != nil {
return fmt.Errorf("cannot load membership: %w", err)
if !errors.Is(err, coredata.ErrResourceNotFound) {
return fmt.Errorf("cannot load membership: %w", err)
}
webhookPayload = webhooktypes.NewUser(profile, nil)
} else {
webhookPayload = webhooktypes.NewUser(profile, membership)
}
if err := webhook.InsertData(ctx, conn, scope, profile.OrganizationID, coredata.WebhookEventTypeUserUpdated, webhooktypes.NewUser(profile, membership)); err != nil {
if err := webhook.InsertData(ctx,
conn,
scope,
profile.OrganizationID,
coredata.WebhookEventTypeUserUpdated,
webhookPayload,
); err != nil {
return fmt.Errorf("cannot insert webhook event: %w", err)
}