Skip to content

Commit

Permalink
feat: 오늘의 사서에게 사서 근무 확인메세지 전송 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
not-using committed Oct 11, 2023
1 parent dd64aa8 commit ab03b95
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
2 changes: 2 additions & 0 deletions index.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { sendMeetingConfirmation } from './src/services/meeting.js';
import { sendShiftConfirmation } from './src/services/shift.js';
import { receiveSlackInteraction } from './src/services/slackInteraction.js';

const Tasks = {
slack: (event) => receiveSlackInteraction(event),
meetings: () => sendMeetingConfirmation(),
shifts: () => sendShiftConfirmation(),
};

export const handler = async (event) => {
Expand Down
1 change: 1 addition & 0 deletions src/constants/events.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const ATTENDED = 'attended';
export const MEETING = '정기사서회의';
export const SHIFT = '사서근무';
4 changes: 3 additions & 1 deletion src/constants/sheet.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const SLACK_ID_RANGE = '별첨_월렛 지급 예정 현황!L5:L40';
export const SLACK_ID_RANGE = '별첨_월렛 지급 예정 현황!M5:M40';
export const TOGETHER_RANGE = '별첨_월렛 지급 예정 현황!L5:M40'; // 친바에서 파싱하기 위한 데이터

export const RAW_SHEET = '별첨_raw data';
export const ATTENDTYPE = {
정기사서회의: '회의 참석',
Expand Down
38 changes: 38 additions & 0 deletions src/services/shift.js
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]);
};
4 changes: 4 additions & 0 deletions src/utils/httpClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ export const httpClientForSheet = axios.create({
baseURL: `https://sheets.googleapis.com/v4/spreadsheets/${spreadSheet}/values/`,
headers: headers,
});

export const httpClientForTogether = axios.create({
baseURL: process.env.TOGETHER_ROTATION_URL,
});

0 comments on commit ab03b95

Please sign in to comment.