diff --git a/src/cronjobs/userProfileJobs.js b/src/cronjobs/userProfileJobs.js index 1e4c6392a..f3903c057 100644 --- a/src/cronjobs/userProfileJobs.js +++ b/src/cronjobs/userProfileJobs.js @@ -18,12 +18,12 @@ const userProfileJobs = () => { await userhelper.awardNewBadges(); await userhelper.reActivateUser(); await userhelper.deActivateUser(); - await userhelper.oneTimeLocationUpdate(); }, null, false, 'America/Los_Angeles', ); + allUserProfileJobs.start(); }; module.exports = userProfileJobs; diff --git a/src/helpers/userHelper.js b/src/helpers/userHelper.js index 1e349245c..8bf04eb5f 100644 --- a/src/helpers/userHelper.js +++ b/src/helpers/userHelper.js @@ -105,8 +105,8 @@ const userHelper = function () {

Date Assigned: ${infringement.date}

Description: ${infringement.description}

Total Infringements: This is your ${moment - .localeData() - .ordinal(totalInfringements)} blue square of 5.

+ .localeData() + .ordinal(totalInfringements)} blue square of 5.

${final_paragraph}

Thank you,
One Community

`; @@ -197,8 +197,8 @@ const userHelper = function () {
Weekly Summary (for the week ending on ${moment(dueDate) - .tz("America/Los_Angeles") - .format("YYYY-MMM-DD")}): + .tz("America/Los_Angeles") + .format("YYYY-MMM-DD")}):
${summary} @@ -220,24 +220,24 @@ const userHelper = function () { Media URL: ${ mediaUrlLink || 'Not provided!' - } + }

${ weeklySummariesCount === 8 - ? `

Total Valid Weekly Summaries: ${weeklySummariesCount}

` - : `

Total Valid Weekly Summaries: ${ + ? `

Total Valid Weekly Summaries: ${weeklySummariesCount}

` + : `

Total Valid Weekly Summaries: ${ weeklySummariesCount || "No valid submissions yet!" - }

` + }

` } ${ hoursLogged >= weeklycommittedHours - ? `

Hours logged: ${hoursLogged.toFixed( - 2 - )} / ${weeklycommittedHours}

` - : `

Hours logged: ${hoursLogged.toFixed( - 2 - )} / ${weeklycommittedHours}

` + ? `

Hours logged: ${hoursLogged.toFixed( + 2 + )} / ${weeklycommittedHours}

` + : `

Hours logged: ${hoursLogged.toFixed( + 2 + )} / ${weeklycommittedHours}

` } ${weeklySummaryMessage}
`; @@ -298,69 +298,6 @@ const userHelper = function () { }) .catch((error) => logger.logException(error)); }; - async function wait(ms) { - return new Promise((r) => setTimeout(r, ms)); - } - const oneTimeLocationUpdate = async () => { - const users = await userProfile.find({}, '_id'); - - for (let i = 0; i < users.length; i += 1) { - const user = users[i]; - const person = await userProfile.findById(user._id); - if (!person.location.coords && !person.location.country && !person.location.city && !person.location.userProvided) { - const personLoc = person.location || ''; - let location; - if (personLoc) { - try { - const res = await fetch(`https://api.opencagedata.com/geocode/v1/json?key=d093a5e0eee34aea8043f4e6edb0e9f7&q=${encodeURIComponent(personLoc)}&pretty=1&limit=1`); - if (!res) { - throw new Error(); - } else { - const data = await res.json(); - location = { - userProvided: personLoc || '', - coords: { - lat: data.results[0].geometry.lat || '', - lng: data.results[0].geometry.lng || '', - }, - country: data.results[0].components.country || '', - city: data.results[0].components.city || '', - }; - } - } catch (err) { - console.log(err); - location = { - userProvided: personLoc, - coords: { - lat: 'err', - lng: '', - }, - country: '', - city: '', - } - } - } else { - location = { - userProvided: personLoc || '', - coords: { - lat: '', - lng: '', - }, - country: '', - city: '', - }; - } - await userProfile.findOneAndUpdate({ _id: user._id }, { - $set: { - location, - }, - }); - } - - await wait(2000); - } - }; - /** * This function is called by a cron job to do 3 things to all active users: @@ -999,7 +936,7 @@ const userHelper = function () { for (let i = 0; i < badgeCollection.length; i += 1) { if ( badgeCollection[i].badge?.type === - "X Hours for X Week Streak" && + "X Hours for X Week Streak" && badgeCollection[i].badge?.weeks === bdge.weeks && bdge.hrs === hrs && !removed @@ -1104,7 +1041,7 @@ const userHelper = function () { true ) ) >= - elem.months - 12 + elem.months - 12 ) { if (badgeOfType) { if (badgeOfType._id.toString() !== elem._id.toString()) { @@ -1155,9 +1092,9 @@ const userHelper = function () { ); return theBadge ? increaseBadgeCount( - personId, - mongoose.Types.ObjectId(theBadge._id) - ) + personId, + mongoose.Types.ObjectId(theBadge._id) + ) : addBadge(personId, mongoose.Types.ObjectId(elem._id)); } } @@ -1290,7 +1227,7 @@ const userHelper = function () { for (let i = 0; i < badgeCollection.length; i += 1) { if ( badgeCollection[i].badge?.type === - "X Hours for X Week Streak" && + "X Hours for X Week Streak" && badgeCollection[i].badge?.weeks === bdge.weeks ) { if ( @@ -1682,7 +1619,6 @@ const userHelper = function () { awardNewBadges, getTangibleHoursReportedThisWeekByUserId, deleteExpiredTokens, - oneTimeLocationUpdate, }; };