Skip to content

Commit fac3a68

Browse files
committed
modify: change user defined slack module to slack library
1 parent 69c694f commit fac3a68

File tree

6 files changed

+25
-65
lines changed

6 files changed

+25
-65
lines changed

Diff for: src/auth/auth.module.ts

-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { RotationAttendeeRepository } from 'src/rotation/repository/rotation-att
1818
import { HolidayModule } from 'src/holiday/holiday.module';
1919
import { UserService } from 'src/user/user.service';
2020
import { UserRepository } from 'src/user/repository/user.repository';
21-
import { SlackModule } from 'src/slack/slack.module';
2221

2322
@Module({
2423
imports: [
@@ -39,7 +38,6 @@ import { SlackModule } from 'src/slack/slack.module';
3938
}),
4039
}),
4140
HolidayModule,
42-
SlackModule,
4341
TypeOrmModule.forFeature([RotationEntity, RotationAttendeeEntity, UserEntity]),
4442
],
4543
controllers: [AuthController],

Diff for: src/rotation/rotations.module.ts

-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@ import { RotationAttendeeRepository } from './repository/rotation-attendees.repo
1111
import { RotationEntity } from './entity/rotation.entity';
1212
import { RotationAttendeeEntity } from './entity/rotation-attendee.entity';
1313
import { UserEntity } from 'src/user/entity/user.entity';
14-
import { SlackModule } from 'src/slack/slack.module';
1514

1615
@Module({
1716
imports: [
1817
TypeOrmModule.forFeature([RotationEntity, RotationAttendeeEntity, UserEntity]),
1918
ScheduleModule.forRoot(),
2019
HolidayModule,
21-
SlackModule,
2220
],
2321
controllers: [RotationsController],
2422
providers: [

Diff for: src/rotation/rotations.service.ts

+25-14
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
forwardRef,
88
} from '@nestjs/common';
99
import { Cron } from '@nestjs/schedule';
10+
import { ConfigService } from '@nestjs/config';
1011
import { CreateRegistrationDto } from './dto/create-registration.dto';
1112
import { CreateRotationDto } from './dto/create-rotation.dto';
1213
import { UpdateRotationDto } from './dto/update-rotation.dto';
@@ -24,7 +25,8 @@ import { RotationAttendeeRepository } from './repository/rotation-attendees.repo
2425
import { DayObject, RotationAttendeeInfo } from './utils/types';
2526
import { HolidayService } from 'src/holiday/holiday.service';
2627
import { createRotation } from './utils/rotation';
27-
import { SlackService } from 'src/slack/slack.service';
28+
import { SlackService } from 'nestjs-slack';
29+
import { Message } from 'slack-block-builder';
2830
import { FindTodayRotationDto } from './dto/find-today-rotation.dto';
2931
import { FindRegistrationDto } from './dto/find-registration.dto';
3032
import { FindAllRotationDto } from './dto/find-all-rotation.dto';
@@ -46,9 +48,13 @@ export class RotationsService {
4648
@Inject(forwardRef(() => UserService)) private userService: UserService,
4749
private holidayService: HolidayService,
4850
private slackService: SlackService,
51+
private configService: ConfigService,
4952
) {}
5053

51-
@Cron('0 0 * * *', {
54+
/*
55+
* 매일 0시 0분에 내일 사서에게 메세지를 전송하는 cron job
56+
*/
57+
@Cron('* * * * * *', {
5258
name: 'checkTomorrowLibrarian',
5359
timeZone: 'Asia/Seoul',
5460
})
@@ -69,21 +75,26 @@ export class RotationsService {
6975

7076
if (tomorrowLibrarian.length === 0) {
7177
return;
72-
} else if (tomorrowLibrarian.length === 1) {
73-
const tomorrowLibrarianOne = tomorrowLibrarian[0].user;
74-
75-
const message = `[알림] 내일은 ${tomorrowLibrarianOne.nickname}님이 사서입니다!`;
78+
}
7679

77-
await this.slackService.sendDirectMessage(tomorrowLibrarianOne.slackMemberId, message);
78-
return;
79-
} else {
80-
const tomorrowLibrarianOne = tomorrowLibrarian[0].user;
81-
const tomorrowLibrarianTwo = tomorrowLibrarian[1].user;
80+
for (const item of tomorrowLibrarian) {
81+
if (!item.user) {
82+
this.logger.warn('Failed to get tomorrow librarian information. User not found.');
83+
return;
84+
}
8285

83-
const message = `[알림] 내일은 ${tomorrowLibrarianOne.nickname}님과 ${tomorrowLibrarianTwo.nickname}님이 사서입니다!`;
86+
const message = `[알림] 안녕하세요 ${item.user.nickname}님! 내일 사서 업무가 있습니다.`;
8487

85-
await this.slackService.sendDirectMessage(tomorrowLibrarianOne.slackMemberId, message);
86-
await this.slackService.sendDirectMessage(tomorrowLibrarianTwo.slackMemberId, message);
88+
try {
89+
await this.slackService.postMessage(
90+
Message({
91+
text: message,
92+
channel: item.user.slackMemberId,
93+
}).buildToObject(),
94+
);
95+
} catch (error) {
96+
this.logger.error(`Error sending message to ${item.user.nickname}: ` + error);
97+
}
8798
}
8899
}
89100

Diff for: src/slack/slack.module.ts

-8
This file was deleted.

Diff for: src/slack/slack.service.ts

-37
This file was deleted.

Diff for: src/user/user.module.ts

-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ import { RotationAttendeeEntity } from 'src/rotation/entity/rotation-attendee.en
1010
import { RotationRepository } from 'src/rotation/repository/rotations.repository';
1111
import { RotationAttendeeRepository } from 'src/rotation/repository/rotation-attendees.repository';
1212
import { HolidayModule } from 'src/holiday/holiday.module';
13-
import { SlackModule } from 'src/slack/slack.module';
1413

1514
@Module({
1615
imports: [
1716
TypeOrmModule.forFeature([UserEntity, RotationEntity, RotationAttendeeEntity]),
1817
HolidayModule,
19-
SlackModule,
2018
],
2119
controllers: [UserController],
2220
providers: [

0 commit comments

Comments
 (0)