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

hicommonwealth / commonwealth / 14999283812

13 May 2025 02:28PM UTC coverage: 42.937% (-0.08%) from 43.021%
14999283812

push

github

web-flow
Merge pull request #12110 from hicommonwealth/rotorsoft/12108-refactor-add-thread-links

Refactors add links

1700 of 4402 branches covered (38.62%)

Branch coverage included in aggregate %.

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

3151 of 6896 relevant lines covered (45.69%)

39.21 hits per line

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

0.0
/libs/model/src/aggregates/thread/AddLinks.command.ts
1
import { Command } from '@hicommonwealth/core';
2
import * as schemas from '@hicommonwealth/schemas';
3
import { models } from '../../database';
4
import { authThread, mustExist } from '../../middleware';
5

6
export function AddLinks(): Command<typeof schemas.AddLinks> {
NEW
7
  return {
×
8
    ...schemas.AddLinks,
9
    auth: [authThread({ roles: ['admin'], author: true })],
10
    secure: true,
11
    body: async ({ payload }) => {
NEW
12
      const { thread_id, links } = payload;
×
13

NEW
14
      const thread = await models.Thread.findOne({
×
15
        where: { id: thread_id },
16
      });
NEW
17
      mustExist('Thread', thread);
×
18

19
      const new_links =
NEW
20
        links.length > 0
×
21
          ? thread.links
×
22
            ? links.filter((link) => {
NEW
23
                return !thread.links!.some(
×
24
                  (l) =>
NEW
25
                    l.source === link.source &&
×
26
                    l.identifier === link.identifier,
27
                );
28
              })
29
            : links
30
          : [];
31

NEW
32
      if (new_links.length > 0) {
×
NEW
33
        thread.links = thread.links
×
34
          ? thread.links.concat(new_links)
35
          : new_links;
NEW
36
        await thread.save();
×
37
      }
38

NEW
39
      const updated = await models.Thread.findOne({
×
40
        where: { id: thread_id },
41
        include: [
42
          { model: models.Address, as: 'Address' },
43
          { model: models.Address, as: 'collaborators' },
44
          { model: models.Topic, as: 'topic' },
45
        ],
46
      });
47

NEW
48
      return {
×
49
        ...updated!.toJSON(),
50
        new_links,
51
      };
52
    },
53
  };
54
}
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