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

hicommonwealth / commonwealth / 13845955660

13 Mar 2025 10:37PM UTC coverage: 43.588% (-1.1%) from 44.638%
13845955660

Pull #11430

github

web-flow
Merge 384ed128b into 54d5b089a
Pull Request #11430: Allow delete contest

1384 of 3534 branches covered (39.16%)

Branch coverage included in aggregate %.

1 of 9 new or added lines in 1 file covered. (11.11%)

219 existing lines in 24 files now uncovered.

2606 of 5620 relevant lines covered (46.37%)

37.7 hits per line

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

66.15
/libs/model/src/aggregates/community/UpdateTopic.command.ts
1
import { InvalidState, type Command } from '@hicommonwealth/core';
2
import * as schemas from '@hicommonwealth/schemas';
3
import { models } from '../../index';
4
import { authTopic } from '../../middleware';
5
import { mustExist } from '../../middleware/guards';
6
import { decodeContent, sanitizeQuillText } from '../../utils';
7

8
const Errors = {
31✔
9
  DefaultTemplateRequired: 'Default Template required',
10
};
11

12
export function UpdateTopic(): Command<typeof schemas.UpdateTopic> {
13
  return {
5✔
14
    ...schemas.UpdateTopic,
15
    auth: [authTopic({ roles: ['admin'] })],
16
    body: async ({ actor, payload }) => {
17
      const { topic_id } = payload;
4✔
18

19
      // TODO: can use topic in auth
20
      const topic = await models.Topic.findByPk(topic_id!);
4✔
21
      mustExist('Topic', topic);
4✔
22

23
      if (topic.archived_at) {
4!
24
        throw new InvalidState('Cannot update archived topic');
×
25
      }
26

27
      const {
28
        name,
29
        description,
30
        telegram,
31
        group_ids,
32
        featured_in_sidebar,
33
        featured_in_new_post,
34
      } = payload;
35

4✔
36
      const decodedDescription = decodeContent(description ?? '');
37

4✔
38
      let default_community_template =
39
        payload.default_offchain_template?.trim();
40
      if (featured_in_new_post && !default_community_template) {
4✔
41
        throw new InvalidState(Errors.DefaultTemplateRequired);
4!
UNCOV
42
      }
×
43
      // sanitize text
44
      default_community_template = sanitizeQuillText(
45
        default_community_template!,
4✔
46
      );
47

48
      if (typeof name !== 'undefined') {
49
        topic.name = name;
4✔
50
      }
1✔
51
      if (typeof decodedDescription !== 'undefined') {
52
        topic.description = decodedDescription;
4!
53
      }
4✔
54
      if (typeof telegram !== 'undefined') {
55
        topic.telegram = telegram || '';
4!
UNCOV
56
      }
×
57
      if (Array.isArray(group_ids)) {
58
        topic.group_ids = group_ids;
4!
UNCOV
59
      }
×
60
      if (typeof featured_in_sidebar !== 'undefined') {
61
        topic.featured_in_sidebar = featured_in_sidebar || false;
4!
UNCOV
62
      }
×
63
      if (typeof featured_in_new_post !== 'undefined') {
64
        topic.featured_in_new_post = featured_in_new_post || false;
4!
UNCOV
65
      }
×
66
      if (typeof default_community_template !== 'undefined') {
67
        topic.default_offchain_template = default_community_template || '';
4!
68
      }
4✔
69
      await topic.save();
70

4✔
71
      return {
1!
72
        topic: topic.toJSON(),
73
        user_id: actor.user.id!,
4✔
74
      };
75
    },
4✔
76
  };
77
}
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