Skip to content

Commit

Permalink
fix: 친바 사서 명단 가져오는 api 수정
Browse files Browse the repository at this point in the history
/rotations => /rotations/today
환경변수는 수동으로 수정함
  • Loading branch information
not-using committed Jan 5, 2024
1 parent a3af0cc commit 7afe19a
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions src/services/shift.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export const sendShiftConfirmation = async () => {
today.slice(5, 10)
);

const todayLibrarians = await getTodayLibrariansFromTogether();
const todayLibrariansId = await getLibrariansIdFromSheet(todayLibrarians);
const [todayLibrarians, todayLibrariansId] =
await getTodayLibrariansFromTogether();

await Promise.all(todayLibrariansId.map((id) => sendBlocks(id, message)));
console.log('shift', todayLibrarians);
Expand All @@ -29,20 +29,11 @@ const getTodayLibrariansFromTogether = async () => {
.get('/')
.then((response) => response.data);

return rotations
.filter(
({ month, day }) =>
month === new Date().getMonth() + 1 && day === new Date().getDay()
)
.map((rotation) => rotation.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]);
return rotations.reduce(
([name, slack], { nickname, slackMemberId }) => [
[...name, nickname],
[...slack, slackMemberId],
],
[[], []]
);
};

0 comments on commit 7afe19a

Please sign in to comment.