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

hicommonwealth / commonwealth / 16150741569

08 Jul 2025 05:57PM UTC coverage: 40.016% (+0.008%) from 40.008%
16150741569

push

github

web-flow
Merge pull request #12599 from hicommonwealth/Rotorsoft-patch-1

Update CODEOWNERS

1857 of 5027 branches covered (36.94%)

Branch coverage included in aggregate %.

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 { getCommentSearchVector, models } from '@hicommonwealth/model';
3
import * as schemas from '@hicommonwealth/schemas';
4
import { authComment } from '../../middleware';
5
import { mustBeAuthorizedComment } from '../../middleware/guards';
6

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

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

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

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