@@ -14,11 +14,17 @@ import { RotationEntity } from './entity/rotation.entity';
14
14
import { RotationAttendeeEntity } from './entity/rotation-attendee.entity' ;
15
15
import { UserService } from 'src/user/user.service' ;
16
16
import { RotationRepository } from './repository/rotations.repository' ;
17
- import { getFourthWeekdaysOfMonth , getNextYearAndMonth , getTodayDate } from './utils/date' ;
17
+ import {
18
+ getFourthWeekdaysOfMonth ,
19
+ getNextYearAndMonth ,
20
+ getTodayDay ,
21
+ getTomorrowDate ,
22
+ } from './utils/date' ;
18
23
import { RotationAttendeeRepository } from './repository/rotation-attendees.repository' ;
19
24
import { DayObject , RotationAttendeeInfo } from './utils/types' ;
20
25
import { HolidayService } from 'src/holiday/holiday.service' ;
21
26
import { createRotation } from './utils/rotation' ;
27
+ import { SlackService } from 'src/slack/slack.service' ;
22
28
23
29
function getRotationCronTime ( ) {
24
30
if ( process . env . NODE_ENV === 'production' ) {
@@ -36,8 +42,41 @@ export class RotationsService {
36
42
private rotationAttendeeRepository : RotationAttendeeRepository ,
37
43
@Inject ( forwardRef ( ( ) => UserService ) ) private userService : UserService ,
38
44
private holidayService : HolidayService ,
45
+ private slackService : SlackService ,
39
46
) { }
40
47
48
+ @Cron ( '0 0 * * *' , {
49
+ name : 'checkTomorrowLibrarian' ,
50
+ timeZone : 'Asia/Seoul' ,
51
+ } )
52
+ async checkTomorrowLibrarian ( ) : Promise < void > {
53
+ const tomorrow = getTomorrowDate ( ) ;
54
+ const tomorrowYear = tomorrow . getFullYear ( ) ;
55
+ const tomorrowMonth = tomorrow . getMonth ( ) + 1 ;
56
+ const tomorrowDay = tomorrow . getDate ( ) ;
57
+
58
+ const tomorrowLibrarian = await this . rotationRepository . find ( {
59
+ where : {
60
+ year : tomorrowYear ,
61
+ month : tomorrowMonth ,
62
+ day : tomorrowDay ,
63
+ } ,
64
+ relations : [ 'user' ] ,
65
+ } ) ;
66
+
67
+ if ( tomorrowLibrarian . length === 0 ) {
68
+ return ;
69
+ }
70
+
71
+ const tomorrowLibrarianOne = tomorrowLibrarian [ 0 ] . user ;
72
+ const tomorrowLibrarianTwo = tomorrowLibrarian [ 1 ] . user ;
73
+
74
+ const message = `[알림] 내일은 ${ tomorrowLibrarianOne . nickname } 님과 ${ tomorrowLibrarianTwo . nickname } 님이 사서입니다!` ;
75
+
76
+ await this . slackService . sendDirectMessage ( tomorrowLibrarianOne . slackMemberId , message ) ;
77
+ await this . slackService . sendDirectMessage ( tomorrowLibrarianTwo . slackMemberId , message ) ;
78
+ }
79
+
41
80
/*
42
81
* 4주차 월요일에 유저를 모두 DB에 담아놓는 작업 필요
43
82
* [update 20231219] - 매 달 1일에 유저를 모두 DB에 담아놓는 작업으로 변경
@@ -80,7 +119,7 @@ export class RotationsService {
80
119
timeZone : 'Asia/Seoul' ,
81
120
} )
82
121
async setRotation ( ) : Promise < void > {
83
- if ( getFourthWeekdaysOfMonth ( ) . indexOf ( getTodayDate ( ) ) > 0 ) {
122
+ if ( getFourthWeekdaysOfMonth ( ) . indexOf ( getTodayDay ( ) ) > 0 ) {
84
123
try {
85
124
this . logger . log ( 'Setting rotation...' ) ;
86
125
@@ -279,7 +318,7 @@ export class RotationsService {
279
318
const { year, month } = getNextYearAndMonth ( ) ;
280
319
281
320
/* 4주차인지 확인 */
282
- // if (getFourthWeekdaysOfMonth().indexOf(getTodayDate ()) < 0) {
321
+ // if (getFourthWeekdaysOfMonth().indexOfDay ()) < 0) {
283
322
// throw new BadRequestException(
284
323
// 'Invalid date: Today is not a fourth weekday of the month.',
285
324
// );
0 commit comments