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

hicommonwealth / commonwealth / 14475476648

15 Apr 2025 05:18PM UTC coverage: 46.141% (-0.1%) from 46.287%
14475476648

Pull #11664

github

web-flow
Merge faa64a68e into 84ecac07e
Pull Request #11664: Added `XpChainEventCreated` support

1622 of 3876 branches covered (41.85%)

Branch coverage included in aggregate %.

0 of 25 new or added lines in 2 files covered. (0.0%)

58 existing lines in 14 files now uncovered.

2976 of 6089 relevant lines covered (48.88%)

39.44 hits per line

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

0.0
/libs/model/src/aggregates/thread/SearchThreads.query.ts
1
import { Query } from '@hicommonwealth/core';
2
import * as schemas from '@hicommonwealth/schemas';
3
import {
4
  PaginationSqlOptions,
5
  buildPaginatedResponse,
6
  buildPaginationSql,
7
} from '@hicommonwealth/schemas';
8
import { ALL_COMMUNITIES } from '@hicommonwealth/shared';
9
import { QueryTypes } from 'sequelize';
10
import { z } from 'zod';
11
import { models } from '../../database';
12

13
export function SearchThreads(): Query<typeof schemas.SearchThreads> {
14
  return {
×
15
    ...schemas.SearchThreads,
16
    auth: [],
17
    secure: false,
18
    body: async ({ payload }) => {
19
      const {
20
        communityId,
21
        searchTerm,
22
        threadTitleOnly,
23
        limit,
24
        page,
25
        orderBy,
26
        orderDirection,
27
        includeCount,
28
      } = payload;
×
29

30
      // sort by rank by default
31
      let sortOptions: PaginationSqlOptions = {
×
32
        limit: limit || 10,
×
33
        page: page || 1,
×
34
        orderDirection,
35
      };
36
      switch (orderBy) {
×
37
        case 'created_at':
38
          sortOptions = {
×
39
            ...sortOptions,
40
            orderBy: `"Threads".${orderBy}`,
41
          };
42
          break;
×
43
        default:
44
          sortOptions = {
×
45
            ...sortOptions,
46
            orderBy: `rank`,
47
            orderBySecondary: `"Threads".created_at`,
48
            orderDirectionSecondary: 'DESC',
49
          };
50
      }
51

52
      const { sql: paginationSort, bind: paginationBind } =
53
        buildPaginationSql(sortOptions);
×
54

55
      const bind = {
×
56
        community:
57
          communityId && communityId !== ALL_COMMUNITIES
×
58
            ? communityId
59
            : undefined,
60
        searchTerm: searchTerm,
61
        ...paginationBind,
62
      };
63

64
      const sql = `
×
65
SELECT 
66
  "Threads".id,
67
  "Threads".title,
68
  ${threadTitleOnly ? '' : `"Threads".body,`}
×
69
  'thread' as type,
70
  "Addresses".id as address_id,
71
  "Addresses".user_id as address_user_id,
72
  "Addresses".address,
73
  "Addresses".community_id as address_community_id,
74
  "Threads".created_at,
75
  "Threads".community_id as community_id,
76
  COUNT(*) OVER() AS total_count, 
77
  ts_rank_cd("Threads".search, tsquery) as rank
78
FROM 
79
  "Threads"
80
  JOIN "Addresses" ON "Threads".address_id = "Addresses".id,
81
  websearch_to_tsquery('english', $searchTerm) as tsquery
82
WHERE
83
  "Threads".deleted_at IS NULL AND
84
  "Threads".marked_as_spam_at IS NULL
85
  ${bind.community ? 'AND "Threads".community_id = $community' : ''} 
×
86
  AND ("Threads".title ILIKE '%' || $searchTerm || '%' 
87
  ${!threadTitleOnly ? 'OR tsquery @@ "Threads".search' : ''})
×
88
${paginationSort}`;
89

UNCOV
90
      const results = await models.sequelize.query<
×
91
        z.infer<typeof schemas.ThreadView> & { total_count: number }
92
      >(sql, {
93
        bind,
94
        type: QueryTypes.SELECT,
95
        raw: true,
96
      });
97

UNCOV
98
      const totalResults = includeCount
×
99
        ? results.length > 0
×
100
          ? results[0].total_count
101
          : 0
102
        : results.length;
103

UNCOV
104
      return buildPaginatedResponse(results, totalResults, bind);
×
105
    },
106
  };
107
}
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