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

khu-khlug / sight-backend / 13616929463

02 Mar 2025 03:40PM UTC coverage: 57.19% (-1.0%) from 58.222%
13616929463

push

github

web-flow
chore: yarn에서 npm으로 롤백 (#105)

637 of 1702 branches covered (37.43%)

Branch coverage included in aggregate %.

1797 of 2554 relevant lines covered (70.36%)

15.16 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
  ISlackSender,
8
  SlackSender,
9
} from '@khlug/app/domain/adapter/ISlackSender';
10
import { GroupStateChanged } from '@khlug/app/domain/group/event/GroupStateChanged';
×
11
import {
12
  GroupMemberRepository,
×
13
  IGroupMemberRepository,
14
} from '@khlug/app/domain/group/IGroupMemberRepository';
15
import {
×
16
  GroupRepository,
×
17
  IGroupRepository,
×
18
} from '@khlug/app/domain/group/IGroupRepository';
×
19
import { GroupState } from '@khlug/app/domain/group/model/constant';
20
import { SlackMessageCategory } from '@khlug/app/domain/message/model/constant';
21
import { PointGrantService } from '@khlug/app/domain/user/service/PointGrantService';
×
22

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

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

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

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

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

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

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

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

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

106
    return 0;
107
  }
×
108
}
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