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

hicommonwealth / commonwealth / 14450698512

14 Apr 2025 04:24PM UTC coverage: 46.172% (-0.1%) from 46.287%
14450698512

push

github

web-flow
Merge pull request #11828 from hicommonwealth/tim/spam-indexes

1618 of 3866 branches covered (41.85%)

Branch coverage included in aggregate %.

11 of 19 new or added lines in 4 files covered. (57.89%)

27 existing lines in 6 files now uncovered.

2966 of 6062 relevant lines covered (48.93%)

39.75 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 } = mustBeAuthorizedComment(actor, context);
×
15

16
      if (payload.spam && !comment.marked_as_spam_at) {
×
17
        comment.marked_as_spam_at = new Date();
×
NEW
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
NEW
22
        let body = comment.body;
×
NEW
23
        if (comment.content_url) {
×
NEW
24
          const res = await fetch(comment.content_url);
×
NEW
25
          body = await res.text();
×
26
        }
NEW
27
        comment.search = getCommentSearchVector(body);
×
28
        comment.marked_as_spam_at = null;
×
29
        await comment.save();
×
30
      }
31

32
      comment.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
      });
43

44
      return comment;
×
45
    },
46
  };
47
}
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