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

Bailey new personal max backend #619

Merged
merged 5 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/controllers/userProfileController.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ async function ValidatePassword(req, res) {
}

const userProfileController = function (UserProfile) {
console.log('Hello')
Copy link
Contributor

Choose a reason for hiding this comment

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

Should remove console.log statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ptrpengdev I went through and removed the remaining console logs that you mentioned :) Please let me know if i missed anything else

Copy link
Contributor

Choose a reason for hiding this comment

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

lgtm. Please do remember to pull the latest code from the development branch and resolve any conflicts. Thanks!

const getUserProfiles = async function (req, res) {
if (
!(await hasPermission(req.body.requestor.role, "getUserProfiles")) &&
Expand Down
35 changes: 21 additions & 14 deletions src/helpers/userHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ const userHelper = function () {
) {
hasWeeklySummary = true;
}
console.log('ended update Result');

const cutOffDate = moment().subtract(1, "year");

Expand Down Expand Up @@ -759,7 +760,6 @@ const userHelper = function () {
};

const increaseBadgeCount = async function (personId, badgeId) {
console.log("Increase Badge Count", personId, badgeId);
userProfile.updateOne(
{ _id: personId, "badgeCollection.badge": badgeId },
{
Expand All @@ -781,7 +781,9 @@ const userHelper = function () {
count = 1,
featured = false
) {
console.log('Adding Badge');
console.log('personId:', personId);
ptrpengdev marked this conversation as resolved.
Show resolved Hide resolved
console.log('badgeId:', badgeId);
console.log('count:', count);
userProfile.findByIdAndUpdate(
personId,
{
Expand All @@ -797,22 +799,25 @@ const userHelper = function () {
}
}
);
console.log('made it to the end!');
};

const removeDupBadge = async function (personId, badgeId) {
userProfile.findByIdAndUpdate(
personId,
{
$pull: {
badgeCollection: { badge: badgeId }
badgeCollection: { _id: mongoose.Types.ObjectId(badgeId) }
}
},
{ new: true },
err => {
if (err) {
throw new Error(err);
}
}
);
console.log('badgeId After!', badgeId);
};

const changeBadgeCount = async function (personId, badgeId, count) {
Expand Down Expand Up @@ -1027,29 +1032,35 @@ const userHelper = function () {
// 'Personal Max',
const checkPersonalMax = async function (personId, user, badgeCollection) {
let badgeOfType;
let duplicateBadges = [];

for (let i = 0; i < badgeCollection.length; i += 1) {
if (badgeCollection[i].badge?.type === "Personal Max") {
if (badgeOfType) {
removeDupBadge(personId, badgeOfType._id);
if (!badgeOfType) {
badgeOfType = badgeCollection[i];
} else {
duplicateBadges.push(badgeCollection[i]);
}
}
for (let badge of duplicateBadges) {
await removeDupBadge(personId, badge._id);
}
}
await badge.findOne({ type: "Personal Max" }).then(results => {
if (
user.lastWeekTangibleHrs &&
user.lastWeekTangibleHrs >= 1 &&
user.lastWeekTangibleHrs === user.personalBestMaxHrs
) {
)
{
if (badgeOfType) {
changeBadgeCount(
personId,
mongoose.Types.ObjectId(badgeOfType._id),
user.personalBestMaxHrs
);
} else {

addBadge(personId, mongoose.Types.ObjectId(results._id), user.personalBestMaxHrs);

}
}
});
Expand Down Expand Up @@ -1382,16 +1393,13 @@ const userHelper = function () {
};

const awardNewBadges = async () => {
console.log("Awarding");
try {

const users = await userProfile.find({ isActive: true }).populate('badgeCollection.badge');


for (let i = 0; i < users.length; i += 1) {
const user = users[i];
const { _id, badgeCollection } = user;
const personId = mongoose.Types.ObjectId(_id);

await checkPersonalMax(personId, user, badgeCollection);
await checkMostHrsWeek(personId, user, badgeCollection);
await checkMinHoursMultiple(personId, user, badgeCollection);
Expand All @@ -1407,11 +1415,10 @@ const userHelper = function () {

const getTangibleHoursReportedThisWeekByUserId = function (personId) {
const userId = mongoose.Types.ObjectId(personId);

const pdtstart = moment().tz('America/Los_Angeles').startOf('week').format('YYYY-MM-DD');
const pdtend = moment().tz('America/Los_Angeles').endOf('week').format('YYYY-MM-DD');


return timeEntries
.find(
{
Expand Down
Loading