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

hicommonwealth / commonwealth / 14525314737

17 Apr 2025 09:40PM UTC coverage: 46.066% (-0.04%) from 46.108%
14525314737

push

github

web-flow
Merge pull request #11891 from hicommonwealth/tim/discord-updates-3

1622 of 3883 branches covered (41.77%)

Branch coverage included in aggregate %.

0 of 5 new or added lines in 1 file covered. (0.0%)

1 existing line in 1 file now uncovered.

2980 of 6107 relevant lines covered (48.8%)

39.34 hits per line

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

4.55
/libs/model/src/aggregates/discordBot/createDiscordBotConfig.command.ts
1
import { type Command, InvalidState } from '@hicommonwealth/core';
2
import * as schemas from '@hicommonwealth/schemas';
3
import { canIntegrateDiscord, CommunityTierMap } from '@hicommonwealth/shared';
4
import { models } from '../../database';
5
import { authRoles } from '../../middleware';
6

7
const TOKEN_EXPIRATION_MINUTES = 5;
32✔
8

9
export function CreateDiscordBotConfig(): Command<
10
  typeof schemas.CreateDiscordBotConfig
11
> {
12
  return {
×
13
    ...schemas.CreateDiscordBotConfig,
14
    auth: [authRoles('admin')],
15
    secure: true,
16
    body: async ({ payload }) => {
17
      const { community_id, verification_token } = payload;
×
18
      const token_expiration = new Date(
×
19
        +new Date() + TOKEN_EXPIRATION_MINUTES * 60 * 1000,
20
      );
21

NEW
22
      const community = await models.Community.findOne({
×
23
        attributes: ['tier'],
24
        where: {
25
          id: community_id,
26
        },
27
      });
NEW
28
      if (!community) {
×
NEW
29
        throw new InvalidState('Community not found');
×
30
      }
31

NEW
32
      if (!canIntegrateDiscord(community)) {
×
NEW
33
        throw new InvalidState(
×
34
          `Community tier must be at least ${CommunityTierMap.ManuallyVerified}`,
35
        );
36
      }
37

UNCOV
38
      const existing = await models.DiscordBotConfig.findOne({
×
39
        where: {
40
          community_id,
41
        },
42
      });
43

44
      if (existing) {
×
45
        const existingConfig = await existing.update(
×
46
          {
47
            verification_token,
48
            token_expiration,
49
          },
50
          {
51
            where: {
52
              community_id,
53
            },
54
          },
55
        );
56

57
        await models.Community.update(
×
58
          { discord_config_id: existingConfig.id },
59
          { where: { id: community_id } },
60
        );
61

62
        return { message: 'Updated an existing discord bot config' };
×
63
      }
64

65
      await models.DiscordBotConfig.create({
×
66
        community_id,
67
        verification_token,
68
        token_expiration,
69
      });
70

71
      return { message: 'Created a new discord bot config' };
×
72
    },
73
  };
74
}
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