Skip to content

Commit

Permalink
fix: show regular members in dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
pbc1017 committed Mar 30, 2024
1 parent 818eafe commit 57bbafb
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 17 deletions.
67 changes: 51 additions & 16 deletions back/routes/member.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion front/src/pages/admin/MemberDashboard/MemberDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface Club {
clubType: string;
members: number;
approvedMembers: number;
approvedRegularMembers: number;
}

export const MemberDashboard = (): JSX.Element => {
Expand All @@ -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);
Expand Down Expand Up @@ -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}
/>
Expand Down

0 comments on commit 57bbafb

Please sign in to comment.