Challenge Overview
This is another challenge in the series for Cloud Hub, where we want to aggregate some stats for every company. These APIs are a series of endpoints built using swagger, nodeJS and mongodb. We have 3 types of stats we want to track, realtime stats, nightly stats, and monthly stats. We already have a framework in place to schedule the task, and have a job running monthly to use for the 2 new monthly stats.
Realtime stats:
- userCount. This would be the number of active users assigned to the company. Active is when a user has status = A. It would include user and admin role types only.
- appCount. This would be the number of active apps assigned to the company (company.companyApps). Active is when an app has status = A.
- userAppCount. This would be the number of active user’s apps (users.userApps). Active is when an user app has status = A.
Nightly stats:
- currentSpend. This would be the total spent for the month on active applications. You would sum the amount field for charges by company where charge has status = A. This would be a new /jobs type called "currentSpend" and the logic should live in jobService.
Monthly stats (These would be added to jobService.spendAll):
- appAvgSpend. This would be the average spent for all of the company applications during the prior month.
- userAppAvgSpend. This would be the average spent per user, currently this field is added to user.spend. Currently user.spend is a percentage. This needs to be updated to the percentage of the dollar amount of the charge that month. For example if the appId has charges totaling $75 for the previous month, and 2 users have the app, each user.spend would be $37.50.
After running seed/prokure.js you should have the following stats:
{
"userCount": 14,
"appCount": 2,
"userAppCount": 12,
"appAvgSpend": 134.18,
"userAppAvgSpend": XX,
"currentSpend": 268.35
}
* XX For stat userAppAvgSpend, this will be dynamic since there is some randomness for which app is assigned to the first 8 users. This value can be grabbed by getting the average of all of the user.spend values.
Requirements
- Create new endpoint for nightly job, you don't need to add it to cron.yaml.
- Create hooks within the services to update the realtime values when records are added or updated.
- Update spendAll job to update 2 monthly stats.
- Fix issue with user.spend where a percentage is stored instead of dollar amount. See example above.
Final Submission Guidelines
- Any additions or modifications to the code project pass on "npm run lint" and "npm run test".
- Provide your code and documentation in a single zip file.
- The bulk of your documentation should be in the Readme.md and you should assume that this will be open source so make sure you cover all the steps to set up, If you have specific information that should not be included in a public readme (like links to your video) put them in a file called submission.txt and they will be omitted from the project if it is open sourced.
- Provide a quick video of your solution in action (feel free to annotate your video if you are not comfortable with spoken English or don’t like the sound of your own voice). Video may be private on youtube or added to the submission files.
- Please provide a list of files that were modified in submission.txt, or a clean git history.