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

khu-khlug / sight-backend / 13740126841

08 Mar 2025 06:04PM UTC coverage: 50.989% (-0.2%) from 51.155%
13740126841

push

github

web-flow
feat: 디스코드 연동 시 역할 및 이름 반영 (#110)

765 of 2433 branches covered (31.44%)

Branch coverage included in aggregate %.

71 of 142 new or added lines in 14 files covered. (50.0%)

37 existing lines in 6 files now uncovered.

2123 of 3231 relevant lines covered (65.71%)

12.88 hits per line

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

73.17
/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
  DiscordOAuth2AdapterToken,
7
  IDiscordOAuth2Adapter,
8
} from '@khlug/app/application/adapter/IDiscordOAuth2Adapter';
8✔
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
import { DiscordMemberService } from '@khlug/app/application/user/service/DiscordMemberService';
1✔
15

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

22
import { Message } from '@khlug/constant/message';
16!
23

×
24
@CommandHandler(CreateDiscordIntegrationCommand)
25
export class CreateDiscordIntegrationCommandHandler
26
  implements ICommandHandler<CreateDiscordIntegrationCommand>
27
{
28
  constructor(
29
    private readonly discordMemberService: DiscordMemberService,
30
    @Inject(DiscordStateGeneratorToken)
16✔
31
    private readonly discordStateGenerator: IDiscordStateGenerator,
32
    @Inject(DiscordOAuth2AdapterToken)
16✔
33
    private readonly discordAdapter: IDiscordOAuth2Adapter,
34
    @Inject(DiscordIntegrationRepositoryToken)
35
    readonly discordIntegrationRepository: IDiscordIntegrationRepository,
1!
36
  ) {}
1!
UNCOV
37

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

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

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

4✔
53
    const accessToken = await this.discordAdapter.getAccessToken(code);
1✔
54
    const discordUserId =
55
      await this.discordAdapter.getCurrentUserId(accessToken);
3✔
56

3✔
57
    const newDiscordIntegration = new DiscordIntegration({
58
      id: ulid(),
1✔
59
      userId,
60
      discordUserId,
2✔
61
      createdAt: new Date(),
2✔
62
    });
2✔
63
    await this.discordIntegrationRepository.insert(newDiscordIntegration);
64

65
    await this.discordMemberService.reflectUserInfoToDiscordUser(userId);
66
  }
67
}
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