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

hicommonwealth / commonwealth / 13727641600

07 Mar 2025 07:13PM UTC coverage: 45.197% (-0.6%) from 45.755%
13727641600

Pull #11259

github

web-flow
Merge 865a0bd6a into a53d0f274
Pull Request #11259: Added in async count cache

1313 of 3223 branches covered (40.74%)

Branch coverage included in aggregate %.

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

151 existing lines in 13 files now uncovered.

2517 of 5251 relevant lines covered (47.93%)

38.24 hits per line

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

0.0
/libs/model/src/thread/GetThreadsByIds.query.ts
1
import { InvalidInput, Query } from '@hicommonwealth/core';
2
import { ThreadInstance } from '@hicommonwealth/model';
3
import * as schemas from '@hicommonwealth/schemas';
4
import { Op } from 'sequelize';
5
import { z } from 'zod';
6
import { models, sequelize } from '../database';
7

8
export function GetThreadsByIds(): Query<typeof schemas.GetThreadsByIds> {
9
  return {
×
10
    ...schemas.GetThreadsByIds,
11
    auth: [],
12
    secure: false,
13
    body: async ({ payload }) => {
14
      const { community_id, thread_ids } = payload;
×
15
      if (thread_ids === '') return [];
×
16

17
      let parsedThreadIds: number[];
18

19
      try {
×
20
        parsedThreadIds = z
×
21
          .string()
22
          .transform((ids) =>
23
            ids.split(',').map((id) => parseInt(id.trim(), 10)),
×
24
          )
25
          .parse(thread_ids);
26
      } catch (e) {
27
        throw new InvalidInput('Invalid thread_ids format');
×
28
      }
29

30
      let threads: ThreadInstance[];
NEW
31
      await models.sequelize.transaction(async (transaction) => {
×
NEW
32
        threads = await models.Thread.findAll({
×
33
          where: {
34
            ...(community_id && { community_id }),
×
35
            id: { [Op.in]: parsedThreadIds },
36
          },
37

38
          include: [
39
            {
40
              model: models.Address,
41
              as: 'Address',
42
              include: [
43
                {
44
                  model: models.User,
45
                  as: 'User',
46
                  required: true,
47
                  attributes: ['id', 'profile'],
48
                },
49
              ],
50
            },
51
            {
52
              model: models.Address,
53
              as: 'collaborators',
54
              include: [
55
                {
56
                  model: models.User,
57
                  as: 'User',
58
                  required: true,
59
                  attributes: ['id', 'profile'],
60
                },
61
              ],
62
            },
63
            {
64
              model: models.Topic,
65
              as: 'topic',
66
              required: true,
67
            },
68
            {
69
              model: models.Reaction,
70
              as: 'reactions',
71
              include: [
72
                {
73
                  model: models.Address,
74
                  as: 'Address',
75
                  required: true,
76
                  include: [
77
                    {
78
                      model: models.User,
79
                      as: 'User',
80
                      required: true,
81
                      attributes: ['id', 'profile'],
82
                    },
83
                  ],
84
                },
85
              ],
86
            },
87
            {
88
              model: models.ContestAction,
89
              where: {
90
                action: 'upvoted',
91
              },
92
              required: false,
93
              attributes: ['content_id', 'thread_id'],
94
              include: [
95
                {
96
                  model: models.Contest,
97
                  on: {
98
                    contest_id: sequelize.where(
99
                      sequelize.col('"ContestActions".contest_id'),
100
                      '=',
101
                      sequelize.col('"ContestActions->Contest".contest_id'),
102
                    ),
103
                    contest_address: sequelize.where(
104
                      sequelize.col('"ContestActions".contest_address'),
105
                      '=',
106
                      sequelize.col(
107
                        '"ContestActions->Contest".contest_address',
108
                      ),
109
                    ),
110
                  },
111
                  attributes: [
112
                    'contest_id',
113
                    'contest_address',
114
                    'score',
115
                    'start_time',
116
                    'end_time',
117
                  ],
118
                  include: [
119
                    {
120
                      model: models.ContestManager,
121
                      attributes: ['name', 'cancelled', 'interval'],
122
                    },
123
                  ],
124
                },
125
              ],
126
            },
127
            {
128
              model: models.ThreadVersionHistory,
129
            },
130
          ],
131
          transaction,
132
        });
133
      });
134

NEW
135
      return threads!.map(
×
136
        (t) => t.toJSON() as z.infer<typeof schemas.ThreadView>,
×
137
      );
138
    },
139
  };
140
}
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