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

khu-khlug / sight-backend / 14190117854

01 Apr 2025 07:47AM UTC coverage: 51.423%. Remained the same
14190117854

push

github

web-flow
refactor: 메시지 전송 클래스 구현을 위해 기존 클래스 및 파일 이름 변경 (#115)

796 of 2513 branches covered (31.68%)

Branch coverage included in aggregate %.

29 of 34 new or added lines in 18 files covered. (85.29%)

36 existing lines in 6 files now uncovered.

2222 of 3356 relevant lines covered (66.21%)

13.1 hits per line

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

78.64
/src/app/application/group/command/createGroup/CreateGroupCommandHandler.ts
1
import { Inject, NotFoundException } from '@nestjs/common';
2
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
1✔
3

4
import { Transactional } from '@khlug/core/persistence/transaction/Transactional';
5

1✔
6
import { CreateGroupCommand } from '@khlug/app/application/group/command/createGroup/CreateGroupCommand';
7
import { CreateGroupCommandResult } from '@khlug/app/application/group/command/createGroup/CreateGroupCommandResult';
8

8✔
9
import { INotifier, NotifierToken } from '@khlug/app/domain/adapter/INotifier';
10
import { GroupFactory } from '@khlug/app/domain/group/GroupFactory';
11
import { GroupMemberFactory } from '@khlug/app/domain/group/GroupMemberFactory';
1✔
12
import {
1✔
13
  GroupMemberRepository,
1✔
14
  IGroupMemberRepository,
1✔
15
} from '@khlug/app/domain/group/IGroupMemberRepository';
1✔
16
import {
1✔
17
  GroupRepository,
1✔
18
  IGroupRepository,
1✔
19
} from '@khlug/app/domain/group/IGroupRepository';
1✔
20
import { GroupState } from '@khlug/app/domain/group/model/constant';
1✔
21
import {
1✔
22
  IInterestRepository,
1✔
23
  InterestRepository,
1✔
24
} from '@khlug/app/domain/interest/IInterestRepository';
1✔
25
import { NotificationCategory } from '@khlug/constant/notification';
1✔
26
import { PointGrantService } from '@khlug/app/domain/user/service/PointGrantService';
1✔
27

28
import { Message } from '@khlug/constant/error';
28!
UNCOV
29
import { Point } from '@khlug/constant/point';
×
30

31
@CommandHandler(CreateGroupCommand)
32
export class CreateGroupCommandHandler
33
  implements ICommandHandler<CreateGroupCommand, CreateGroupCommandResult>
34
{
35
  constructor(
36
    private readonly groupFactory: GroupFactory,
28✔
37
    private readonly groupMemberFactory: GroupMemberFactory,
38
    private readonly pointGrantService: PointGrantService,
28✔
39
    @Inject(GroupRepository)
40
    private readonly groupRepository: IGroupRepository,
41
    @Inject(GroupMemberRepository)
2!
42
    private readonly groupMemberRepository: IGroupMemberRepository,
2!
UNCOV
43
    @Inject(InterestRepository)
×
44
    private readonly interestRepository: IInterestRepository,
2✔
45
    @Inject(NotifierToken)
46
    private readonly slackSender: INotifier,
47
  ) {}
5!
48

49
  @Transactional()
50
  async execute(
4✔
51
    command: CreateGroupCommand,
4✔
52
  ): Promise<CreateGroupCommandResult> {
53
    const {
54
      requesterUserId,
55
      title,
56
      category,
4✔
57
      grade,
4✔
58
      interestIds,
4✔
59
      purpose,
3✔
60
      technology,
61
      allowJoin,
62
      repository,
63
    } = command;
64

65
    const uniqueInterestIds = Array.from(new Set(interestIds));
66
    await this.checkInterestExists(uniqueInterestIds);
67

68
    const newGroup = this.groupFactory.create({
69
      id: this.groupRepository.nextId(),
70
      category,
71
      state: GroupState.PROGRESS,
72
      title,
73
      authorUserId: requesterUserId,
74
      adminUserId: requesterUserId,
3✔
75
      purpose,
3✔
76
      interestIds,
77
      technology,
78
      grade,
79
      lastUpdaterUserId: requesterUserId,
80
      repository,
3✔
81
      allowJoin,
3✔
82
    });
3✔
83
    await this.groupRepository.save(newGroup);
84

85
    const groupMember = this.groupMemberFactory.create({
86
      id: this.groupMemberRepository.nextId(),
87
      userId: requesterUserId,
88
      groupId: newGroup.id,
89
    });
3✔
90
    await this.groupMemberRepository.save(groupMember);
91

92
    const message = `${newGroup.title} 그룹을 만들었습니다.`;
93
    await this.pointGrantService.grant({
94
      targetUserIds: [newGroup.adminUserId],
3✔
95
      amount: Point.GROUP_CREATED,
96
      reason: message,
97
    });
4✔
98

4✔
99
    this.slackSender.send({
1✔
100
      targetUserId: newGroup.adminUserId,
101
      category: NotificationCategory.GROUP_ACTIVITY,
102
      message,
103
    });
4✔
104

4✔
105
    return new CreateGroupCommandResult(newGroup);
4✔
106
  }
4✔
107

4✔
108
  private async checkInterestExists(
4✔
109
    uniqueInterestIds: string[],
4✔
110
  ): Promise<void> {
4✔
111
    const interests =
4✔
112
      await this.interestRepository.findByIds(uniqueInterestIds);
4✔
113

4✔
114
    if (interests.length !== uniqueInterestIds.length) {
4✔
115
      throw new NotFoundException(Message.SOME_INTERESTS_NOT_FOUND);
4✔
116
    }
4✔
117
  }
118
}
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