diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 8d8d400ad..000000000 Binary files a/.DS_Store and /dev/null differ diff --git a/src/cronjobs/userProfileJobs.js b/src/cronjobs/userProfileJobs.js index f0f69e146..8ed6f1534 100644 --- a/src/cronjobs/userProfileJobs.js +++ b/src/cronjobs/userProfileJobs.js @@ -7,7 +7,6 @@ const userProfileJobs = () => { const allUserProfileJobs = new CronJob( // '* * * * *', // Comment out for testing. Run Every minute. '1 0 * * 0', // Every Sunday, 1 minute past midnight. - async () => { const SUNDAY = 0; // will change back to 0 after fix if (moment().tz('America/Los_Angeles').day() === SUNDAY) { @@ -19,6 +18,16 @@ const userProfileJobs = () => { } await userhelper.awardNewBadges(); await userhelper.reActivateUser(); + }, + null, + false, + 'America/Los_Angeles', + ); + + // Job to run every day, 1 minute past midnight to deactivate the user + const dailyUserDeactivateJobs = new CronJob( + '1 0 * * *', // Every day, 1 minute past midnight + async () => { await userhelper.deActivateUser(); }, null, @@ -26,6 +35,22 @@ const userProfileJobs = () => { 'America/Los_Angeles', ); + const summaryNotSubmittedJobs=new CronJob( + // '* * * * *', + '0 4 * * 0', // Every Sunday at 4AM + async () => { + const SUNDAY = 0; + if (moment().tz('America/Los_Angeles').day() === SUNDAY) { + await userhelper.completeHoursAndMissedSummary(); + } + }, + null, + false, + 'America/Los_Angeles', + ) + allUserProfileJobs.start(); + summaryNotSubmittedJobs.start(); + dailyUserDeactivateJobs.start(); }; module.exports = userProfileJobs; diff --git a/src/helpers/userHelper.js b/src/helpers/userHelper.js index 5195e8a37..97cc967e1 100644 --- a/src/helpers/userHelper.js +++ b/src/helpers/userHelper.js @@ -737,6 +737,7 @@ const userHelper = function () { 'dddd M-D-YYYY', )} and ending ${pdtEndOfLastWeek.format('dddd M-D-YYYY')}.`; } + } else { description = `System auto-assigned infringement for not submitting a weekly summary for the week starting ${pdtStartOfLastWeek.format( 'dddd M-D-YYYY', @@ -809,7 +810,6 @@ const userHelper = function () { } else { emailsBCCs = null; } - emailSender( status.email, 'New Infringement Assigned', @@ -822,7 +822,6 @@ const userHelper = function () { } else if (isNewUser && !timeNotMet && !hasWeeklySummary) { usersRequiringBlueSqNotification.push(personId); } - const categories = await dashboardHelper.laborThisWeekByCategory( personId, pdtStartOfLastWeek, @@ -896,7 +895,6 @@ const userHelper = function () { const inactiveUsers = await userProfile.find({ isActive: false }, '_id'); for (let i = 0; i < inactiveUsers.length; i += 1) { const user = inactiveUsers[i]; - await processWeeklySummariesByUserId(mongoose.Types.ObjectId(user._id), false); } } catch (err) { @@ -904,6 +902,87 @@ const userHelper = function () { } }; + const missedSummaryTemplate = (firstname) => { + return ( + `

Dear ${firstname},

+ +

When you read this, please input your summary into the software. When you do, please be sure to put it in using the tab for “Last Week”.

+ +

Reply to this email once you’ve done this, so I know to review what you’ve submitted. Do this before tomorrow (Monday) at 3 PM (Pacific Time) and I’ll remove this blue square.

+ +

With Gratitude,

+ +

Jae Sabol

+

310.755.4693

+

Zoom: www.tinyurl.com/zoomoc

+

Primary Email: jae@onecommunityglobal.org

+

Google Email: onecommunityglobal@gmail.com

+

Timezone: Los Angeles, CA - Pacific Time

` + ) + } + // function to send emails to those users who have completed hours but not submitted their summary + const completeHoursAndMissedSummary= async () => { + try{ + const users = await userProfile.find( + { isActive: true }, + '_id weeklycommittedHours weeklySummaries missedHours', + ); + const pdtStartOfLastWeek = moment() + .tz('America/Los_Angeles') + .startOf('week') + .subtract(1, 'week'); + + const pdtEndOfLastWeek = moment().tz('America/Los_Angeles').endOf('week').subtract(1, 'week'); + for (let i = 0; i < users.length; i += 1) { + const user = users[i]; + const person = await userProfile.findById(user._id); + const personId = mongoose.Types.ObjectId(user._id); + let hasWeeklySummary = false; + + if (Array.isArray(user.weeklySummaries) && user.weeklySummaries.length) { + const { summary } = user.weeklySummaries[0]; + if (summary) { + hasWeeklySummary = true; + } + } + const results = await dashboardHelper.laborthisweek( + personId, + pdtStartOfLastWeek, + pdtEndOfLastWeek, + ); + + const { timeSpent_hrs: timeSpent } = results[0]; + + const weeklycommittedHours = user.weeklycommittedHours + (user.missedHours ?? 0); + const timeNotMet = timeSpent < weeklycommittedHours; + + const utcStartMoment = moment(pdtStartOfLastWeek).add(1, 'second'); + const utcEndMoment = moment(pdtEndOfLastWeek).subtract(1, 'day').subtract(1, 'second'); + + const requestsForTimeOff = await timeOffRequest.find({ + requestFor: personId, + startingDate: { $lte: utcStartMoment }, + endingDate: { $gte: utcEndMoment }, + }); + const hasTimeOffRequest = requestsForTimeOff.length > 0; + // log values of the below used conditions in if statement to know if the email is being sent is correct conditions + if(hasTimeOffRequest===false && timeNotMet===false && hasWeeklySummary===false){ + emailSender( + person.email, + 'Re: New Infringement Assigned', + missedSummaryTemplate(person.firstName), + null, + 'jae@onecommunityglobal.org', + 'jae@onecommunityglobal.org', + null, + ); + } + } + }catch(err){ + console.log(err) + } + }; + const applyMissedHourForCoreTeam = async () => { try { const currentDate = moment().tz('America/Los_Angeles').format(); @@ -2266,6 +2345,7 @@ const userHelper = function () { getTangibleHoursReportedThisWeekByUserId, deleteExpiredTokens, deleteOldTimeOffRequests, + completeHoursAndMissedSummary }; }; diff --git a/src/routes/userProfileRouter.js b/src/routes/userProfileRouter.js index 2d68d2da1..1aada29f6 100644 --- a/src/routes/userProfileRouter.js +++ b/src/routes/userProfileRouter.js @@ -24,6 +24,7 @@ const routes = function (userProfile, project) { ); userProfileRouter.route('/userProfile/update').patch(controller.updateUserInformation); + // Endpoint to retrieve basic user profile information userProfileRouter.route('/userProfile/basicInfo').get(controller.getUserProfileBasicInfo); userProfileRouter diff --git a/src/server.js b/src/server.js index e53949703..4793b10cf 100644 --- a/src/server.js +++ b/src/server.js @@ -1,9 +1,7 @@ /* eslint-disable quotes */ require('dotenv').load(); - const { app, logger } = require('./app'); const websockets = require('./websockets').default; - require('./startup/db')(); require('./cronjobs/userProfileJobs')();