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

hicommonwealth / commonwealth / 16150748756

08 Jul 2025 05:57PM UTC coverage: 40.016%. Remained the same
16150748756

push

github

web-flow
Merge pull request #12586 from hicommonwealth/rotorsoft/refactor-libs-models-exports

Rotorsoft/refactor libs models exports

1857 of 5027 branches covered (36.94%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

104 existing lines in 10 files now uncovered.

3293 of 7843 relevant lines covered (41.99%)

36.82 hits per line

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

0.0
/libs/model/src/aggregates/comment/ToggleCommentSpam.command.ts
1
import { type Command } from '@hicommonwealth/core';
2
import * as schemas from '@hicommonwealth/schemas';
3
import { models } from '../../database';
4
import { authComment } from '../../middleware';
5
import { mustBeAuthorizedComment } from '../../middleware/guards';
6
import { getCommentSearchVector } from '../../models';
7

8
export function ToggleCommentSpam(): Command<typeof schemas.ToggleCommentSpam> {
UNCOV
9
  return {
×
10
    ...schemas.ToggleCommentSpam,
11
    auth: [
12
      authComment({ author: true, roles: ['admin', 'moderator', 'member'] }),
13
    ],
14
    body: async ({ actor, payload, context }) => {
UNCOV
15
      const { comment, community_id } = mustBeAuthorizedComment(actor, context);
×
16
      let spamToggled = false;
×
17

UNCOV
18
      if (payload.spam && !comment.marked_as_spam_at) {
×
19
        comment.marked_as_spam_at = new Date();
×
20
        comment.search = null;
×
21
        await comment.save();
×
22
        spamToggled = true;
×
23
      } else if (!payload.spam && comment.marked_as_spam_at) {
×
24
        // Update search index when unmarking as spam
UNCOV
25
        let body = comment.body;
×
26
        if (comment.content_url) {
×
27
          const res = await fetch(comment.content_url);
×
28
          body = await res.text();
×
29
        }
UNCOV
30
        comment.search = getCommentSearchVector(body);
×
31
        comment.marked_as_spam_at = null;
×
32
        await comment.save();
×
33
        spamToggled = true;
×
34
      }
35

UNCOV
36
      const address = await models.Address.findOne({
×
37
        where: {
38
          id: comment.address_id,
39
        },
40
        include: [
41
          {
42
            model: models.User,
43
            required: true,
44
          },
45
        ],
46
      });
UNCOV
47
      const formattedComment = comment.get({ plain: true });
×
48
      if (address) formattedComment.Address = address.get({ plain: true });
×
49

UNCOV
50
      return { ...formattedComment, community_id, spam_toggled: spamToggled };
×
51
    },
52
  };
53
}
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