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

Club revenue #1427

Open
wants to merge 15 commits into
base: dev
Choose a base branch
from
Open
35 changes: 35 additions & 0 deletions api/main_endpoints/routes/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,4 +509,39 @@ router.post('/usersSubscribedAndVerified', function(req, res) {
});
});

//For Club Revenue page
router.post('/countMembers', async (req, res) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wanna try adding a unit test for this? see

const result = await test.sendPostRequestWithToken(

if (!checkIfTokenSent(req)) {
return res.sendStatus(FORBIDDEN);
} else if (!checkIfTokenValid(req)) {
return res.sendStatus(UNAUTHORIZED);
}

const currentYear = new Date().getFullYear();

const jan1ThisYear = new Date(currentYear, 0, 1);
const june1ThisYear = new Date(currentYear, 5, 1);
const jan1NextYear = new Date(currentYear + 1, 0, 1);
const june1NextYear = new Date(currentYear + 1, 5, 1);
const dec31ThisYear = new Date(currentYear, 11, 31);

const today = new Date();

let count, newSingleSemester, newAnnualMembers, totalNewMembersThisYear, currentActiveMembers;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initialize these when you assign them, and use const


totalNewMembersThisYear = await User.countDocuments({ emailVerified: true, accessLevel: 1, joinDate: { $gte: jan1ThisYear, $lte: today } });
currentActiveMembers = await User.countDocuments({ emailVerified: true, accessLevel: 1, });
cruiserkasuga marked this conversation as resolved.
Show resolved Hide resolved

if (today < june1ThisYear) {
count = await User.countDocuments({ emailVerified: true, accessLevel: 1, joinDate: { $gte: jan1ThisYear, $lt: june1ThisYear}});
newSingleSemester = await User.countDocuments({ emailVerified: true, accessLevel: 1, joinDate: { $gte: jan1ThisYear, $lt: june1ThisYear }, membershipValidUntil: june1ThisYear });
newAnnualMembers = await User.countDocuments({ emailVerified: true, accessLevel: 1, joinDate: { $gte: jan1ThisYear, $lt: june1ThisYear }, membershipValidUntil: june1NextYear });
} else {
count = await User.countDocuments({ emailVerified: true, accessLevel: 1, joinDate: { $gte: june1ThisYear, $lte: dec31ThisYear } });
newSingleSemester = await User.countDocuments({ emailVerified: true, accessLevel: 1, joinDate: { $gte: june1ThisYear, $lte: dec31ThisYear }, membershipValidUntil: jan1NextYear });
newAnnualMembers = await User.countDocuments({ emailVerified: true, accessLevel: 1, joinDate: { $gte: june1ThisYear, $lte: dec31ThisYear }, membershipValidUntil: june1NextYear });
}
return res.json({ count, newSingleSemester, newAnnualMembers, totalNewMembersThisYear, currentActiveMembers }); //count = newSingleSemester + new AnnualMembers
});

module.exports = router;
16 changes: 16 additions & 0 deletions src/APIFunctions/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,19 @@ export async function getAllUserSubscribedAndVerified(token) {
});
return status;
}

export async function countMembers(token) {
console.log(token);
let status = new UserApiResponse();
await axios
.post(GENERAL_API_URL + '/user/countMembers', { token })
.then((res) => {
status.responseData = res.data;
})
.catch((err) => {
status.error = true;
});
return status;
}


10 changes: 10 additions & 0 deletions src/Components/Navbar/AdminNavbar.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';

export default function UserNavBar(props) {

const getLinkClassName = (path) => {
const weAreAtGivenPath = path === window.location.pathname;
let className = 'flex items-center p-2 text-gray-900 rounded-lg dark:text-white';
Expand Down Expand Up @@ -81,6 +82,15 @@ export default function UserNavBar(props) {

),
},
{
title: 'Club Revenue',
route: '/club-revenue',
icon: (
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor" className="w-6 h-6">
<path strokeLinecap="round" strokeLinejoin="round" d="M12 2v20m5-17H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6"/>
</svg>
),
},
];

const renderRoutesForNavbar = (navbarLinks) => {
Expand Down
40 changes: 40 additions & 0 deletions src/Pages/ClubRevenue/ClubRevenue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React, { useEffect, useState } from 'react';
import { countMembers } from '../../APIFunctions/User';


export default function ClubRevenue(props) {

const [newSingleSemester, setNewSingleSemester] = useState();
const [newAnnualMembers, setNewAnnualMembers] = useState();
const [totalNewMembersThisYear, setNewTotalMembers] = useState();
const [currentActiveMembers, setCurrentActiveMembers] = useState();

useEffect(() => {
async function fetchMembers() {
const status = await countMembers(props.user.token);
setNewSingleSemester(status.responseData.newSingleSemester);
setNewAnnualMembers(status.responseData.newAnnualMembers);
setNewTotalMembers(status.responseData.totalNewMembersThisYear);
setCurrentActiveMembers(status.responseData.currentActiveMembers);
}
fetchMembers();
}, []);

return (
<div className="m-10 p-6 bg-white shadow-lg rounded-lg">
<h1 className="text-3xl font-bold mb-4">Club Revenue</h1>
<div className="mb-4">
<h2 className="text-xl font-semibold">Total Earnings from New Members This Semester:</h2>
<p className="text-lg text-green-600 font-medium">${newSingleSemester * 20 + newAnnualMembers * 30}</p>
</div>
<div className="mb-4">
<h2 className="text-xl font-semibold">Total New Members This Year:</h2>
<p className="text-lg">{totalNewMembersThisYear}</p>
</div>
<div className="mb-4">
<h2 className="text-xl font-semibold">Current Active Members:</h2>
<p className="text-lg">{currentActiveMembers}</p>
</div>
</div>
);
}
10 changes: 9 additions & 1 deletion src/Routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ import URLShortenerPage from './Pages/URLShortener/URLShortener';
import EmailPreferencesPage from './Pages/EmailPreferences/EmailPreferences';

import sendUnsubscribeEmail from './Pages/Profile/admin/SendUnsubscribeEmail';

import ClubRevenue from './Pages/ClubRevenue/ClubRevenue.js';

export default function Routing({ appProps }) {

const userIsAuthenticated = appProps.authenticated;
const userIsMember =
userIsAuthenticated &&
Expand Down Expand Up @@ -117,6 +118,13 @@ export default function Routing({ appProps }) {
inAdminNavbar: true,
redirect: '/',
},
{
Component: ClubRevenue,
path: '/club-revenue',
allowedIf: userIsOfficerOrAdmin,
inAdminNavbar: true,
redirect: '/',
},
];
const signedOutRoutes = [
{ Component: Home, path: '/' },
Expand Down