Fix profiles list + implement resolver methods

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-02-09 13:13:58 +04:00
parent f24c5e7590
commit f884c6bb05
3 changed files with 79 additions and 3 deletions

View File

@@ -498,6 +498,41 @@ INNER JOIN signatories ON p.id = signatories.signed_by_profile_id
return nil
}
func (p *MembershipProfiles) CountByOrganizationID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
organizationID gid.GID,
) (int, error) {
q := `
SELECT
COUNT(*)
FROM
iam_membership_profiles
WHERE
%s
AND organization_id = @organization_id
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{"organization_id": organizationID}
maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args)
if err != nil {
return 0, fmt.Errorf("cannot query iam_membership_profiles: %w", err)
}
var count int
err = rows.Scan(&count)
if err != nil {
return 0, fmt.Errorf("cannot collect count: %w", err)
}
return count, nil
}
func (p *MembershipProfile) Insert(
ctx context.Context,
conn pg.Conn,

View File

@@ -1069,6 +1069,31 @@ func (s *OrganizationService) ListProfiles(
return page.NewPage(profiles, cursor), nil
}
func (s OrganizationService) CountProfiles(
ctx context.Context,
organizationID gid.GID,
) (int, error) {
var (
scope = coredata.NewScopeFromObjectID(organizationID)
count int
)
err := s.pg.WithConn(
ctx,
func(conn pg.Conn) (err error) {
profiles := coredata.MembershipProfiles{}
count, err = profiles.CountByOrganizationID(ctx, conn, scope, organizationID)
if err != nil {
return fmt.Errorf("cannot count profiles: %w", err)
}
return nil
},
)
return count, err
}
func (s *OrganizationService) GetOrganizationForMembership(ctx context.Context, membershipID gid.GID) (*coredata.Organization, error) {
var (
scope = coredata.NewScopeFromObjectID(membershipID)

View File

@@ -5520,7 +5520,10 @@ func (r *organizationResolver) Profiles(ctx context.Context, obj *types.Organiza
}, nil
}
filters := coredata.NewMembershipProfileFilter(filter.ExcludeContractEnded)
filters := coredata.NewMembershipProfileFilter(nil)
if filter != nil {
filters = coredata.NewMembershipProfileFilter(filter.ExcludeContractEnded)
}
pageOrderBy := page.OrderBy[coredata.MembershipProfileOrderField]{
Field: coredata.MembershipProfileOrderFieldCreatedAt,
@@ -6456,12 +6459,25 @@ func (r *processingActivityConnectionResolver) TotalCount(ctx context.Context, o
// Permission is the resolver for the permission field.
func (r *profileResolver) Permission(ctx context.Context, obj *types.Profile, action string) (bool, error) {
panic(fmt.Errorf("not implemented: Permission - permission"))
return r.Resolver.Permission(ctx, obj, action)
}
// TotalCount is the resolver for the totalCount field.
func (r *profileConnectionResolver) TotalCount(ctx context.Context, obj *types.ProfileConnection) (int, error) {
panic(fmt.Errorf("not implemented: TotalCount - totalCount"))
if err := r.authorize(ctx, obj.ParentID, iam.ActionMembershipProfileList); err != nil {
return 0, err
}
switch obj.Resolver.(type) {
case *stateOfApplicabilityResolver:
count, err := r.iam.OrganizationService.CountProfiles(ctx, obj.ParentID)
if err != nil {
panic(fmt.Errorf("cannot count profiles: %w", err))
}
return count, nil
}
panic(fmt.Errorf("not implemented: TotalCount for parent type %T", obj.Resolver))
}
// Node is the resolver for the node field.