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

hicommonwealth / commonwealth / 14722043922

29 Apr 2025 02:27AM UTC coverage: 45.422% (-0.4%) from 45.775%
14722043922

Pull #11922

github

web-flow
Merge cd32cfc1a into 3e1b8e436
Pull Request #11922: Thread Rankings

1646 of 4010 branches covered (41.05%)

Branch coverage included in aggregate %.

17 of 83 new or added lines in 15 files covered. (20.48%)

3 existing lines in 2 files now uncovered.

3022 of 6267 relevant lines covered (48.22%)

39.67 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 }) => {
NEW
14
      const { comment, community_id } = mustBeAuthorizedComment(actor, context);
×
NEW
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();
×
NEW
21
        spamToggled = true;
×
UNCOV
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();
×
NEW
32
        spamToggled = true;
×
33
      }
34

NEW
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
      });
NEW
46
      const formattedComment = comment.get({ plain: true });
×
NEW
47
      if (address) formattedComment.Address = address.get({ plain: true });
×
48

NEW
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