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

hicommonwealth / commonwealth / 14612624300

23 Apr 2025 07:40AM UTC coverage: 45.5% (-0.4%) from 45.902%
14612624300

Pull #11922

github

web-flow
Merge 37480c362 into faf8a2222
Pull Request #11922: Thread Rankings

1639 of 3988 branches covered (41.1%)

Branch coverage included in aggregate %.

11 of 74 new or added lines in 14 files covered. (14.86%)

2 existing lines in 1 file now uncovered.

3017 of 6245 relevant lines covered (48.31%)

39.81 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);
×
15

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

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

NEW
46
      return { ...formattedComment, community_id };
×
47
    },
48
  };
49
}
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