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

hicommonwealth / commonwealth / 13167720508

05 Feb 2025 10:25PM UTC coverage: 46.505% (-0.04%) from 46.543%
13167720508

push

github

web-flow
Merge pull request #10834 from hicommonwealth/tim/fix-getThreadsById

1366 of 3277 branches covered (41.68%)

Branch coverage included in aggregate %.

0 of 5 new or added lines in 1 file covered. (0.0%)

1 existing line in 1 file now uncovered.

2612 of 5277 relevant lines covered (49.5%)

36.77 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 * as schemas from '@hicommonwealth/schemas';
3
import { Op } from 'sequelize';
4
import { z } from 'zod';
5
import { models, sequelize } from '../database';
6

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

16
      let parsedThreadIds: number[];
17

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

UNCOV
29
      const threads = await models.Thread.findAll({
×
30
        where: {
31
          ...(community_id && { community_id }),
×
32
          id: { [Op.in]: parsedThreadIds },
33
        },
34

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

128
      return threads.map(
×
129
        (t) => t.toJSON() as z.infer<typeof schemas.ThreadView>,
×
130
      );
131
    },
132
  };
133
}
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