-
Notifications
You must be signed in to change notification settings - Fork 13
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
cruiserkasuga
wants to merge
15
commits into
dev
Choose a base branch
from
club_revenue
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Club revenue #1427
Changes from 5 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8951a0f
created club revenue api endpoint
cruiserkasuga e0ed3dd
connected back end to front end
cruiserkasuga 74c5e10
Added tokens for countMembers api request
cruiserkasuga 1078352
cleanup
cruiserkasuga 37bd64a
corrected formatting for date objects
cruiserkasuga 6cfbaa4
adjusted access level integer paremeters to fit conventions
cruiserkasuga 2ce8ecd
initialized all variables
cruiserkasuga 27ed98b
initialized dates conditionally
cruiserkasuga cb02862
initialized date variables beforehand
cruiserkasuga 1e72c00
created test for tokens
cruiserkasuga badc45b
initialized tests with mock users
cruiserkasuga 09a46ff
(incomplete) added successful test
cruiserkasuga f880fbd
Separated count tests from token test
cruiserkasuga b34ad06
used mock dates for testing
cruiserkasuga fa40194
test
cruiserkasuga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -509,4 +509,39 @@ router.post('/usersSubscribedAndVerified', function(req, res) { | |
}); | ||
}); | ||
|
||
//For Club Revenue page | ||
router.post('/countMembers', async (req, res) => { | ||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
Clark/test/api/User.js
Line 135 in 1ab954d