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

khu-khlug / sight-backend / 13659749000

04 Mar 2025 05:47PM UTC coverage: 53.458% (-3.7%) from 57.19%
13659749000

push

github

web-flow
feat: 디스코드 연동 (#106)

719 of 2152 branches covered (33.41%)

Branch coverage included in aggregate %.

126 of 273 new or added lines in 29 files covered. (46.15%)

3 existing lines in 2 files now uncovered.

2025 of 2981 relevant lines covered (67.93%)

13.14 hits per line

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

72.37
/src/app/application/user/command/createDiscordIntegration/CreateDiscordIntegrationCommandHandler.ts
1
import { ForbiddenException, Inject } from '@nestjs/common';
2
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
1✔
3
import { ulid } from 'ulid';
4

5
import {
1✔
6
  DiscordAdapterToken,
7
  IDiscordAdapter,
8
} from '@khlug/app/application/adapter/IDiscordAdapter';
6✔
9
import {
10
  DiscordStateGeneratorToken,
11
  IDiscordStateGenerator,
1✔
12
} from '@khlug/app/application/adapter/IDiscordStateGenerator';
1✔
13
import { CreateDiscordIntegrationCommand } from '@khlug/app/application/user/command/createDiscordIntegration/CreateDiscordIntegrationCommand';
1✔
14

1✔
15
import {
1✔
16
  DiscordIntegrationRepositoryToken,
1✔
17
  IDiscordIntegrationRepository,
1✔
18
} from '@khlug/app/domain/discord/IDiscordIntegrationRepository';
1✔
19
import { DiscordIntegration } from '@khlug/app/domain/discord/model/DiscordIntegration';
1✔
20

21
import { Message } from '@khlug/constant/message';
9!
NEW
22

×
23
@CommandHandler(CreateDiscordIntegrationCommand)
24
export class CreateDiscordIntegrationCommandHandler
25
  implements ICommandHandler<CreateDiscordIntegrationCommand>
26
{
27
  constructor(
28
    @Inject(DiscordStateGeneratorToken)
29
    private readonly discordStateGenerator: IDiscordStateGenerator,
9✔
30
    @Inject(DiscordAdapterToken)
31
    private readonly discordAdapter: IDiscordAdapter,
9✔
32
    @Inject(DiscordIntegrationRepositoryToken)
33
    readonly discordIntegrationRepository: IDiscordIntegrationRepository,
34
  ) {}
1!
35

1!
NEW
36
  async execute(command: CreateDiscordIntegrationCommand): Promise<void> {
×
37
    const { userId, code, state: givenState } = command;
1!
38

39
    const state = this.discordStateGenerator.generate(userId);
40
    if (state !== givenState) {
2!
41
      throw new ForbiddenException(Message.INVALID_DISCORD_STATE);
42
    }
43

3✔
44
    const prevDiscordIntegration =
3✔
45
      await this.discordIntegrationRepository.findByUserId(userId);
46
    if (prevDiscordIntegration) {
47
      // 이미 존재한다면 무시합니다.
48
      return;
49
    }
3✔
50

3✔
51
    const accessToken = await this.discordAdapter.getAccessToken(code);
3✔
52
    const discordUserId =
1✔
53
      await this.discordAdapter.getCurrentUserId(accessToken);
54

2✔
55
    const newDiscordIntegration = new DiscordIntegration({
2✔
56
      id: ulid(),
57
      userId,
1✔
58
      discordUserId,
59
      createdAt: new Date(),
1✔
60
    });
1✔
61
    await this.discordIntegrationRepository.insert(newDiscordIntegration);
1✔
62
  }
63
}
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