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

khu-khlug / sight-backend / 14247600948

03 Apr 2025 04:05PM UTC coverage: 50.988% (-1.0%) from 51.939%
14247600948

push

github

web-flow
feat: 디스코드 메신저 구현 (#118)

823 of 2618 branches covered (31.44%)

Branch coverage included in aggregate %.

29 of 64 new or added lines in 13 files covered. (45.31%)

45 existing lines in 10 files now uncovered.

2272 of 3452 relevant lines covered (65.82%)

12.83 hits per line

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

0.0
/src/app/application/group/eventHandler/GroupStateChangedHandler.ts
1
import { Inject } from '@nestjs/common';
2
import { EventsHandler, IEventHandler } from '@nestjs/cqrs';
×
3

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

6
import {
7
  IMessenger,
8
  MessengerToken,
9
} from '@khlug/app/domain/adapter/IMessenger';
UNCOV
10
import { GroupStateChanged } from '@khlug/app/domain/group/event/GroupStateChanged';
×
11
import {
UNCOV
12
  GroupMemberRepository,
×
13
  IGroupMemberRepository,
14
} from '@khlug/app/domain/group/IGroupMemberRepository';
15
import {
×
UNCOV
16
  GroupRepository,
×
UNCOV
17
  IGroupRepository,
×
18
} from '@khlug/app/domain/group/IGroupRepository';
×
19
import { GroupState } from '@khlug/app/domain/group/model/constant';
20
import { PointGrantService } from '@khlug/app/domain/user/service/PointGrantService';
21

×
22
import { Point } from '@khlug/constant/point';
23

UNCOV
24
// TODO[lery]: 그룹 상태 핸들러가 분리되면 그때 제거하기
×
UNCOV
25
@EventsHandler(GroupStateChanged)
×
26
export class GroupStateChangedHandler
27
  implements IEventHandler<GroupStateChanged>
28
{
29
  constructor(
30
    private readonly pointGrantService: PointGrantService,
31
    @Inject(GroupRepository)
32
    private readonly groupRepository: IGroupRepository,
33
    @Inject(GroupMemberRepository)
34
    private readonly groupMemberRepository: IGroupMemberRepository,
35
    @Inject(MessengerToken)
36
    private readonly slackSender: IMessenger,
37
  ) {}
38

39
  @Transactional()
UNCOV
40
  async handle(event: GroupStateChanged): Promise<void> {
×
UNCOV
41
    const { groupId, prevState, nextState } = event;
×
UNCOV
42

×
43
    if (nextState === GroupState.PENDING) {
44
      return;
×
45
    }
×
UNCOV
46

×
47
    const group = await this.groupRepository.findById(groupId);
48
    if (!group) {
×
49
      return;
×
50
    }
51

52
    const members = await this.groupMemberRepository.findByGroupId(groupId);
UNCOV
53
    members.forEach((member) =>
×
UNCOV
54
      this.slackSender.send({
×
55
        targetUserId: member.userId,
56
        message: `<a href="/group/${groupId}><u>${
57
          group.title
58
        }</u></a> ${this.buildMessage(nextState)}`,
59
      }),
60
    );
UNCOV
61

×
62
    const userIds = members.map((m) => m.userId);
UNCOV
63
    this.pointGrantService.grant({
×
64
      targetUserIds: userIds,
UNCOV
65
      amount: this.buildPoint(prevState, nextState),
×
66
      reason: `<u>${group.title}</u> ${this.buildMessage(nextState)}`,
UNCOV
67
    });
×
68
  }
UNCOV
69

×
70
  private buildMessage(nextState: GroupState): string {
UNCOV
71
    switch (nextState) {
×
72
      case 'PROGRESS':
73
        return '그룹이 다시 진행 중입니다.';
74
      case 'END_SUCCESS':
UNCOV
75
        return '그룹이 종료(성공)되었습니다.';
×
UNCOV
76
      case 'END_FAIL':
×
UNCOV
77
        return '그룹이 종료(실패)되었습니다.';
×
78
      case 'SUSPEND':
×
79
        return '그룹이 중단 처리되었습니다.';
×
80
      default:
81
        return 'not reachable';
×
82
    }
×
UNCOV
83
  }
×
84

×
85
  private buildPoint(prevState: GroupState, nextState: GroupState): number {
×
86
    if (nextState === GroupState.PROGRESS) {
×
87
      if (prevState == GroupState.END_SUCCESS) {
×
88
        return -Point.GROUP_ENDED_WITH_SUCCESS;
×
89
      } else if (prevState == GroupState.END_FAIL) {
×
90
        return -Point.GROUP_ENDED_WITH_FAIL;
91
      }
92
    } else if (nextState === GroupState.END_SUCCESS) {
×
93
      return Point.GROUP_ENDED_WITH_SUCCESS;
94
    } else if (nextState === GroupState.END_FAIL) {
95
      return Point.GROUP_ENDED_WITH_FAIL;
×
UNCOV
96
    } else if (nextState === GroupState.SUSPEND) {
×
UNCOV
97
      if (prevState == GroupState.END_SUCCESS) {
×
98
        return -Point.GROUP_ENDED_WITH_SUCCESS;
×
99
      } else if (prevState == GroupState.END_FAIL) {
×
100
        return -Point.GROUP_ENDED_WITH_FAIL;
×
101
      }
×
102
    }
×
103

104
    return 0;
105
  }
×
106
}
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