• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hicommonwealth / commonwealth / 13788382186

11 Mar 2025 12:47PM UTC coverage: 44.952% (-0.8%) from 45.755%
13788382186

Pull #11259

github

web-flow
Merge 3caab1019 into 21da2f698
Pull Request #11259: Added in async count cache

1333 of 3320 branches covered (40.15%)

Branch coverage included in aggregate %.

4 of 13 new or added lines in 4 files covered. (30.77%)

172 existing lines in 18 files now uncovered.

2554 of 5327 relevant lines covered (47.94%)

37.99 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/libs/model/src/user/SearchUserProfiles.query.ts
1
import { type Query } from '@hicommonwealth/core';
2
import * as schemas from '@hicommonwealth/schemas';
3
import { ALL_COMMUNITIES } from '@hicommonwealth/shared';
4
import { QueryTypes } from 'sequelize';
5
import { z } from 'zod';
6
import { models } from '../database';
7

8
export function SearchUserProfiles(): Query<typeof schemas.SearchUserProfiles> {
9
  return {
×
10
    ...schemas.SearchUserProfiles,
11
    auth: [],
12
    secure: true,
13
    body: async ({ payload }) => {
14
      const {
15
        community_id,
16
        search,
17
        limit,
18
        cursor,
19
        order_by,
20
        order_direction,
21
        exact_match,
UNCOV
22
      } = payload;
×
23

24
      const communityFilter =
25
        community_id && community_id !== ALL_COMMUNITIES
×
26
          ? `A.community_id = :community_id`
27
          : '';
28
      const nameFilter =
UNCOV
29
        search.length > 0
×
30
          ? exact_match
×
31
            ? `U.profile->>'name' = :searchTerm`
32
            : `U.profile->>'name' ILIKE :searchTerm`
33
          : '';
34

35
      // pagination configuration
UNCOV
36
      const direction = order_direction || 'DESC';
×
37
      const order_col =
UNCOV
38
        order_by === 'created_at'
×
39
          ? 'U.created_at'
40
          : order_by === 'profile_name'
×
41
            ? `U.profile->>'name'`
42
            : 'last_active';
UNCOV
43
      const offset = limit! * (cursor! - 1);
×
44

UNCOV
45
      const sql = `
×
46
          SELECT U.id                         AS user_id,
47
                 U.profile ->> 'name'         AS profile_name,
48
                 U.profile ->> 'avatar_url'   AS avatar_url,
49
                 U.created_at,
50
                 MAX(A.last_active)           as last_active,
51
                 array_agg(
52
                         json_build_object(
53
                                 'id', A.id,
54
                                 'community_id', A.community_id,
55
                                 'address', A.address,
56
                                 'role', A.role
57
                         )
58
                 )                            as addresses,
59
                 COUNT(U.id) OVER ()::integer as total
60
          FROM "Users" U
61
                   JOIN "Addresses" A ON U.id = A.user_id
62
              ${communityFilter || nameFilter ? 'WHERE' : ''} 
×
63
              ${communityFilter} ${communityFilter && nameFilter ? ' AND ' : ''}
×
64
              ${nameFilter}
65
          GROUP BY U.id
66
          ORDER BY ${order_col} ${direction}
67
          LIMIT :limit OFFSET :offset
68
      `;
69

UNCOV
70
      const profiles = await models.sequelize.query<
×
71
        z.infer<typeof schemas.SearchUserProfilesView> & { total: number }
72
      >(sql, {
73
        replacements: {
74
          searchTerm: exact_match ? search : `${search}%`,
×
75
          community_id,
76
          limit,
77
          offset,
78
        },
79
        type: QueryTypes.SELECT,
80
      });
81

UNCOV
82
      return schemas.buildPaginatedResponse(
×
83
        profiles,
84
        profiles.at(0)?.total ?? 0,
×
85
        { limit, offset },
86
      );
87
    },
88
  };
89
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc