Skip to content

Commit 935e77f

Browse files
committed
added: add rotation deadline alarm slack bot
1 parent b40cbef commit 935e77f

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

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

+32-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import { RotationAttendeeEntity } from './entity/rotation-attendee.entity';
1616
import { UserService } from 'src/user/user.service';
1717
import { RotationRepository } from './repository/rotations.repository';
1818
import {
19+
getFourthFridayOfMonth,
20+
getFourthMondayOfMonth,
1921
getFourthWeekdaysOfMonth,
2022
getNextYearAndMonth,
2123
getTodayDay,
@@ -54,8 +56,8 @@ export class RotationsService {
5456
/*
5557
* 매일 0시 0분에 내일 사서에게 메세지를 전송하는 cron job
5658
*/
57-
@Cron('* * * * * *', {
58-
name: 'checkTomorrowLibrarian',
59+
@Cron('0 0 * * *', {
60+
name: 'sendMessageTomorrowLibrarian',
5961
timeZone: 'Asia/Seoul',
6062
})
6163
async sendMessageTomorrowLibrarian(): Promise<void> {
@@ -98,6 +100,34 @@ export class RotationsService {
98100
}
99101
}
100102

103+
/*
104+
* 매일 0시 0분마다, 현재 날짜가 이번 달 4째주 월요일/금요일인지 확인하여, 집현전 슬랙 채널에 메세지를 보내는 cron job
105+
*/
106+
@Cron('0 0 * * *', {
107+
name: 'sendMessageRotationDeadline',
108+
timeZone: 'Asia/Seoul',
109+
})
110+
async sendMessageRotationDeadline(): Promise<void> {
111+
let message: string;
112+
const today = new Date().getDate();
113+
if (today === getFourthMondayOfMonth()) {
114+
message =
115+
'[알림] 로테이션 신청 기간이 시작되었습니다. 이번 주 금요일까지 신청해주세요!\n[신청하러 가기]: https://together.42jip.net/';
116+
} else if (today === getFourthFridayOfMonth()) {
117+
message =
118+
'[알림] 로테이션 신청 기간이 내일 마감됩니다. 오늘까지 신청해주세요!\n[신청하러 가기]: https://together.42jip.net/';
119+
} else {
120+
return;
121+
}
122+
123+
await this.slackService.postMessage(
124+
Message({
125+
text: message,
126+
channel: this.configService.get('slack.jiphyeonjeonChannel'),
127+
}).buildToObject(),
128+
);
129+
}
130+
101131
/*
102132
* 4주차 월요일에 유저를 모두 DB에 담아놓는 작업 필요
103133
* [update 20231219] - 매 달 1일에 유저를 모두 DB에 담아놓는 작업으로 변경

Diff for: src/rotation/utils/date.ts

+6
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ export const getFourthWeekdaysOfMonth = (date = new Date()): number[] => {
5757
return fourthWeekdays;
5858
};
5959

60+
export const getFourthMondayOfMonth = (date = new Date()): number => {
61+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
62+
const [dateOfMondayOnFourthWeek] = getFourthWeekPeriod(date);
63+
return dateOfMondayOnFourthWeek;
64+
};
65+
6066
export const getFourthFridayOfMonth = (date = new Date()): number => {
6167
// eslint-disable-next-line @typescript-eslint/no-unused-vars
6268
const [dateOfMondayOnFourthWeek, dateOfSundayOnFourthWeek] = getFourthWeekPeriod(date);

0 commit comments

Comments
 (0)