Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

주간 식사 운영 서버에 배포합니다! #212

Merged
merged 3 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/deploy-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ jobs:
backend:
container_name: backend
image: ${{ secrets.KYU_DOCKER_IMAGE }}
restart: always
volumes:
- ./logs:/logs
ports:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deploy-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ jobs:
backend:
container_name: backend_test
image: ${{ secrets.DOCKER_IMAGE }}
restart: always
volumes:
- ./logs:/logs
ports:
Expand Down
16 changes: 8 additions & 8 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import rateLimit from "./middleware/rate-limiter.js";
import expressBasicAuth from "express-basic-auth";
import cron from "node-cron";
import {
createWeeklyMeetingEvent,
matchWeeklyMeetingEvent,
createWeeklyDinnerEvent,
matchWeeklyDinnerEvent,
} from "./controller/together.controller.js";
import {
initParticipants,
Expand Down Expand Up @@ -104,14 +104,14 @@ cron.schedule("0 12 * * *", function () {
});
});

// 주간 회의 자동 생성
cron.schedule("0 03 * * 4", function () {
createWeeklyMeetingEvent();
// 주간 회의 후 저녁 식사 친바 자동 생성
cron.schedule("42 16 * * 3", createWeeklyDinnerEvent, {
timezone: "Asia/Seoul",
});

// 주간 회의 자동 매칭
cron.schedule("0 01 * * 3", function () {
matchWeeklyMeetingEvent();
// 주간 회의 후 저녁 식사 친바 자동 매칭
cron.schedule("0 18 * * 3", matchWeeklyDinnerEvent, {
timezone: "Asia/Seoul",
});

// 매일 오전 10시 사서에게 알림
Expand Down
30 changes: 16 additions & 14 deletions src/controller/together.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,10 @@ export async function createEvent(req, res) {
}

// 주간회의 이벤트 자동 생성
export async function createWeeklyMeetingEvent() {
const meetingDate = new Date();
meetingDate.setDate(meetingDate.getDate() + 6);
export async function createWeeklyDinnerEvent() {
const adminUserIntraId = "tkim";
const title = `[주간회의] ${
meetingDate.getMonth() + 1
}월 ${meetingDate.getDate()}일`;
const description = `매 주 생성되는 정기 회의입니다. 해당 날짜에 회의가 없다면 ${adminUserIntraId}님이 삭제해주세요!`;
const title = "[주간 식사] 오늘 주간 회의 끝나고 같이 저녁 드실 분~";
const description = "같이 회의도 하고 식사도 하면서 친해집시다!";
const categoryId = 1;
const adminUser = await userRepository.findByintraId(adminUserIntraId);
console.log(adminUser);
Expand All @@ -39,8 +35,8 @@ export async function createWeeklyMeetingEvent() {
createdId,
categoryId,
});
let str = `:fire: 친바 공지 !! :fire:\n\n${title} 이벤트가 생성되었습니다. \nhttps://together.42jip.net/\n서둘러 참석해주세요`;
await publishMessage(config.slack.jip, str);
const message = `:fire: 친바 공지 !! :fire:\n\n${title}\n이벤트가 생성되었습니다.\n금일 오후 6시에 자동 마감되오니 서둘러 참석해 주세요!\nhttps://together.42jip.net`;
await publishMessage(config.slack.jip, message);
}

//이벤트 삭제
Expand Down Expand Up @@ -173,7 +169,7 @@ export async function matching(req, res) {
res.status(201).json({ eventId, teamList });
}

export async function matchWeeklyMeetingEvent() {
export async function matchWeeklyDinnerEvent() {
const event = await togetherRepository.getNotMatchedEventByCategory(1);
if (event === undefined) return;
const check = await togetherRepository.findAttendByEventId(event.id);
Expand All @@ -184,13 +180,19 @@ export async function matchWeeklyMeetingEvent() {
}
// 이미 매칭된 경우
if (check[0].teamId !== null) return;
shuffle(check); //팀 셔플완료 이제 팀개수대로 팀 나눠야함
// 매칭 되지 않은 경우, 매칭 상태로 변경 isMatching=1
await togetherRepository.changeEvent(event.id);
const teamNum = check.length >= 3 ? 3 : 1;
for (let i = 0; i < check.length; i++) {
let teamId = (i % teamNum) + 1;
await togetherRepository.createTeam(teamId, check[i].id);
// 팀은 무조건 하나로만 자동 매칭
await togetherRepository.createTeam(1, check[i].id);
}
let message = `:fire: 친바 공지 !! :fire:\n\n오늘 저녁 식사 모집 마감되었습니다.\n`;
const attendees = await userRepository.findUsersByIdList(
check.map((e) => e.userId),
);
message += attendees.map((e) => "`" + e.intraId + "`").join(", ");
message += " 님 맛있게 드세요!";
await publishMessage(config.slack.jip, message);
}

//팀 셔플
Expand Down
11 changes: 10 additions & 1 deletion src/data/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,13 @@ export async function updatePassword(userInfo) {
return db
.execute("UPDATE users SET password=? WHERE id=?", [password, id])
.then(() => findById(id));
}
}

export async function findUsersByIdList(idList) {
const placeholder = idList.map(() => "?");
return db
.execute(`select intraId from users where id in (${placeholder})`, [
...idList,
])
.then((result) => result[0]);
}
Loading