-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export const ATTENDED = 'attended'; | ||
export const MEETING = '정기사서회의'; | ||
export const SHIFT = '사서근무'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { SHIFT } from '../constants/events.js'; | ||
import { TOGETHER_RANGE } from '../constants/sheet.js'; | ||
import { confirmMessage } from '../messages/confirmMessage.js'; | ||
import { | ||
httpClientForSheet, | ||
httpClientForTogether, | ||
} from '../utils/httpClient.js'; | ||
import { sendBlocks } from '../utils/slackChat.js'; | ||
|
||
export const sendShiftConfirmation = async () => { | ||
const today = new Date().toISOString().slice(0, 10); | ||
const message = confirmMessage(SHIFT, today.slice(5, 10)); | ||
|
||
const todayLibrarians = await getTodayLibrariansFromTogether(today); | ||
const todayLibrariansId = await getLibrariansIdFromSheet(todayLibrarians); | ||
|
||
await Promise.all(todayLibrariansId.map((id) => sendBlocks(id, message))); | ||
}; | ||
|
||
const getTodayLibrariansFromTogether = async (today) => { | ||
const ratations = await httpClientForTogether | ||
.get('/', { params: { month: new Date().getMonth() + 1 } }) | ||
.then((response) => response.data); | ||
|
||
return ratations | ||
.filter((ratation) => ratation.date.includes(today)) | ||
.map((ratation) => ratation.intraId); | ||
}; | ||
|
||
const getLibrariansIdFromSheet = async (targets) => { | ||
const librarians = await httpClientForSheet | ||
.get(`/${TOGETHER_RANGE}`) | ||
.then((response) => response.data.values); // [[NAME, SLACK_ID], [NAME, SLACK_ID], ...] 형식으로 반환됨 | ||
|
||
return librarians | ||
.filter((item) => targets.includes(item[0])) | ||
.map((item) => item[1]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters