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

hicommonwealth / commonwealth / 14975069059

12 May 2025 02:35PM UTC coverage: 42.469% (-0.2%) from 42.635%
14975069059

push

github

web-flow
Merge pull request #12091 from hicommonwealth/rotorsoft/12080-refactor-topics-controller

Refactors topics controller

1683 of 4372 branches covered (38.49%)

Branch coverage included in aggregate %.

0 of 30 new or added lines in 2 files covered. (0.0%)

3054 of 6782 relevant lines covered (45.03%)

37.11 hits per line

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

0.0
/libs/model/src/aggregates/community/UpdateTopicsOrder.command.ts
1
import { InvalidInput, type Command } from '@hicommonwealth/core';
2
import * as schemas from '@hicommonwealth/schemas';
3
import { models } from '../../database';
4
import { authRoles } from '../../middleware';
5

6
export function UpdateTopicsOrder(): Command<typeof schemas.UpdateTopicsOrder> {
NEW
7
  return {
×
8
    ...schemas.UpdateTopicsOrder,
9
    auth: [authRoles('admin', 'moderator')],
10
    body: async ({ payload }) => {
NEW
11
      const { ordered_ids } = payload;
×
NEW
12
      if (!ordered_ids?.length) return [];
×
13

NEW
14
      const found = await models.Topic.findAll({
×
15
        where: {
16
          id: ordered_ids,
17
          featured_in_sidebar: true,
18
        },
19
        attributes: ['id'],
20
      });
NEW
21
      if (found.length !== ordered_ids.length)
×
NEW
22
        throw new InvalidInput('Not all topics found');
×
23

NEW
24
      const ids = ordered_ids.join(', ');
×
NEW
25
      const whens = ordered_ids
×
NEW
26
        .map((id, idx) => `WHEN ${id} THEN ${idx + 1}\n`)
×
27
        .join(' ');
NEW
28
      await models.sequelize.query(
×
29
        `UPDATE "Topics" SET "order" = CASE id
30
        ${whens}
31
        END WHERE id IN (${ids})`,
32
      );
33

NEW
34
      const topics = await models.Topic.findAll({
×
35
        where: {
36
          id: ordered_ids,
37
          featured_in_sidebar: true,
38
        },
39
        order: [['order', 'ASC']],
40
      });
NEW
41
      return topics.map((t) => t.toJSON());
×
42
    },
43
  };
44
}
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