diff --git a/back/routes/member.js b/back/routes/member.js index fcd69a4..1c99cb9 100644 --- a/back/routes/member.js +++ b/back/routes/member.js @@ -54,7 +54,24 @@ router.get("/clubs", async (req, res) => { model: RegistrationMember, as: "RegistrationMembers", attributes: ["approved_type"], - required: false, // This ensures we also get clubs with zero registrations + include: [ + { + model: Member, + as: "student", + include: [ + { + model: MemberStatus, + as: "MemberStatuses", + where: { + semester_id: currentSemester.id, + is_regular_member: 1, + }, + required: false, + }, + ], + }, + ], + required: false, }, { model: SemesterClubType, @@ -64,21 +81,39 @@ router.get("/clubs", async (req, res) => { ], }); - const formattedData = clubsData.map((club) => { - const clubInfo = club.toJSON(); // Convert Sequelize instance to JSON - const totalMembers = clubInfo.RegistrationMembers.length; - const totalApproved = clubInfo.RegistrationMembers.filter( - (member) => member.approved_type === 2 - ).length; - - return { - club_id: clubInfo.club_id, - name: clubInfo.club.name, - type: clubInfo.type.type, - count: totalMembers, - countApproved: totalApproved, - }; - }); + console.log(clubsData[0].RegistrationMembers[0].student.MemberStatuses); + const formattedData = clubsData + .map((club) => { + const clubInfo = club.toJSON(); + const totalMembers = clubInfo.RegistrationMembers.length; + const totalApproved = clubInfo.RegistrationMembers.filter( + (member) => member.approved_type === 2 + ).length; + const totalApprovedRegular = clubInfo.RegistrationMembers.filter( + (member) => + member.approved_type === 2 && + member.student.MemberStatuses.some( + (status) => status.is_regular_member === true + ) + ).length; + + return { + club_id: clubInfo.club_id, + name: clubInfo.club.name, + type: clubInfo.type.type, + count: totalMembers, + countApproved: totalApproved, + countApprovedRegular: totalApprovedRegular, + }; + }) + .sort((a, b) => { + // First sort by type + if (a.type < b.type) return 1; + if (a.type > b.type) return -1; + + // If types are the same, sort by countApprovedRegular + return a.countApprovedRegular - b.countApprovedRegular; + }); res.json({ success: true, data: formattedData }); } catch (error) { diff --git a/front/src/pages/admin/MemberDashboard/MemberDashboard.tsx b/front/src/pages/admin/MemberDashboard/MemberDashboard.tsx index fe1cc8b..fcd380c 100644 --- a/front/src/pages/admin/MemberDashboard/MemberDashboard.tsx +++ b/front/src/pages/admin/MemberDashboard/MemberDashboard.tsx @@ -15,6 +15,7 @@ interface Club { clubType: string; members: number; approvedMembers: number; + approvedRegularMembers: number; } export const MemberDashboard = (): JSX.Element => { @@ -33,6 +34,7 @@ export const MemberDashboard = (): JSX.Element => { clubType: clubInfo.type, // 가정: clubInfo.type이 객체이고 그 안에 type 문자열이 있다고 가정합니다. members: clubInfo.count, // 가정: 받아온 데이터에 count와 totalApproved가 직접 포함되어 있다고 가정합니다. approvedMembers: clubInfo.countApproved, + approvedRegularMembers: clubInfo.countApprovedRegular, })); setClubs(clubsData); @@ -75,7 +77,7 @@ export const MemberDashboard = (): JSX.Element => { index={index + 1} name={club.name} type={club.clubType} - start_date={`${club.approvedMembers}명 / ${club.members}명`} + start_date={`${club.approvedRegularMembers}명 /${club.approvedMembers}명 / ${club.members}명`} activityStateProperty1={1} id={club.id} />