Skip to content

Commit

Permalink
fix: club members
Browse files Browse the repository at this point in the history
  • Loading branch information
pbc1017 committed Mar 19, 2024
1 parent 41ebcd3 commit 58d04a3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
34 changes: 33 additions & 1 deletion back/routes/club.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const {
ClubBuilding,
RegistrationMember,
} = require("../models");
const { checkMemberDuration } = require("../utils/duration");

router.get("/club_detail", async (req, res) => {
const clubId = req.query.club_id;
Expand Down Expand Up @@ -203,12 +204,43 @@ router.get("/club_members/:clubId", async (req, res) => {

const repStudentIds = representatives.map((rep) => rep.student_id);

let lastSemesterId = currentSemester.id;
const durationCheck = await checkMemberDuration();
if (durationCheck.status > 0) {
lastSemesterId = lastSemesterId - 1;
}

// Fetch club members excluding representatives
const lsatSemesterMembers = await MemberClub.findAll({
where: {
club_id: clubId,
semester_id: lastSemesterId,
student_id: { [Op.notIn]: repStudentIds },
},
include: [
{
model: Member,
as: "student",
attributes: ["student_id", "name"],
},
],
});

const lastSemesterStudentIds = lsatSemesterMembers.map(
(member) => member.student_id
);

// Fetch club members excluding representatives
const members = await MemberClub.findAll({
where: {
club_id: clubId,
semester_id: currentSemester.id,
student_id: { [Op.notIn]: repStudentIds },
student_id: {
[Op.and]: [
{ [Op.notIn]: repStudentIds },
{ [Op.in]: lastSemesterStudentIds },
],
},
},
include: [
{
Expand Down
2 changes: 1 addition & 1 deletion back/routes/member.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ router.get("/duration", async (req, res) => {
return res.status(404).json({ message: durationCheck.message });
}

res.json({ status: durationCheck.registrationStatus });
res.json({ status: durationCheck.status });
} catch (error) {
console.error("Error checking report duration:", error);
res.status(500).json({ message: "서버 오류가 발생했습니다." });
Expand Down
4 changes: 2 additions & 2 deletions back/utils/duration.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ async function checkMemberDuration() {
if (!currentSemester) {
return {
found: false,
registrationStatus: 0,
status: 0,
message: "현재 학기를 찾을 수 없습니다.",
};
}
Expand Down Expand Up @@ -211,7 +211,7 @@ async function checkMemberDuration() {
}
});

return { found: true, registrationStatus: responseCode };
return { found: true, status: responseCode };
}

module.exports = {
Expand Down

0 comments on commit 58d04a3

Please sign in to comment.