From 4ec81c276d3aaa5c714c3d0ca213d1334ce05086 Mon Sep 17 00:00:00 2001 From: luisarevalo21 Date: Mon, 18 Nov 2024 20:12:34 -0800 Subject: [PATCH 1/9] feat: added route for special warnings and utilized previous posting method to post new special warnings --- src/controllers/warningsController.js | 144 ++++++++++++++++++++++---- src/models/currentWarnings.js | 2 + 2 files changed, 123 insertions(+), 23 deletions(-) diff --git a/src/controllers/warningsController.js b/src/controllers/warningsController.js index fb1aa3eef..da9e58984 100644 --- a/src/controllers/warningsController.js +++ b/src/controllers/warningsController.js @@ -24,7 +24,10 @@ const emailTemplate = { }, }; async function getWarningDescriptions() { - currentWarningDescriptions = await currentWarnings.find({}, { warningTitle: 1, _id: 0 }); + currentWarningDescriptions = await currentWarnings.find( + { activeWarning: true }, + { warningTitle: 1, _id: 0, abbreviation: 1 }, + ); } const convertObjectToArray = (obj) => { @@ -37,11 +40,10 @@ const convertObjectToArray = (obj) => { const warningsController = function (UserProfile) { const getWarningsByUserId = async function (req, res) { - currentWarningDescriptions = await currentWarnings.find({ - activeWarning: true, - }); + if (!currentWarningDescriptions) { + await getWarningDescriptions(); + } - currentWarningDescriptions = convertObjectToArray(currentWarningDescriptions); const { userId } = req.params; try { @@ -58,13 +60,104 @@ const warningsController = function (UserProfile) { } }; - const postWarningsToUserProfile = async function (req, res) { + // get all the current warnings as that helps with the sorting for the fianl process + + //get users special warnings + //get all warnings the user has + //filter and return a list of all warnings that are special + //in the same format as the other warnings + //warnings [{title: 'warning title', abbreviation: 'warning abbreviation', warnings: [{userId, iconId, color, date, description}]}] + const getSpecialWarnings = async function (req, res, next) { + // if (!currentWarningDescriptions) { + // await getWarningDescriptions(); + // } try { const { userId } = req.params; + const specialWarningsObj = await currentWarnings + .find({ + activeWarning: true, + isSpecial: true, + }) + .select({ warningTitle: 1, abbreviation: 1 }); + const specialWarningsArray = convertObjectToArray(specialWarningsObj); + + const { warnings } = await UserProfile.findById(userId); + + // look into why the filtering isnt working + //must get the filtered warnings taht are special + //i need the users' special warnings and the warnings that are special + const filteredWarnings = warnings.filter((warning) => { + if (specialWarningsArray.includes(warning.description)) { + return warning; + } + }); + + const { completedData } = filterWarnings(specialWarningsObj, filteredWarnings); + + // console.log('completedData', completedData); + return res.status(201).send({ message: 'success', warnings: completedData }); + } catch (error) { + console.log('error', error); + } + }; + //post new warning via the user profile + //assiginng a new warning to a the user + // const postNewWarningToUserProfile = async function (req, res) { + // try { + // const { userId } = req.params; + // const { iconId, color, date, description } = req.body; + + // // console.log('req.body', userId); + // // console.log('typeoff', typeof userId); + // const record = await UserProfile.findById(userId); + // // const updatedWarnings = await UserProfile.findByIdAndUpdate( + // // { + // // _id: ObjectId(userId), + // // }, + // // { $push: { warnings: { userId, iconId, color, date, description } } }, + // // { new: true, upsert: true }, + // // ); + // // console.log('currentWarningDescriptions', currentWarningDescriptions); + // // const { completedData, sendEmail, size } = filterWarnings( + // // currentWarningDescriptions, + // // updatedWarnings.warnings, + // // iconId, + // // color, + // // ); + + // // const adminEmails = await getUserRoleByEmail(record); + // // if (sendEmail !== null) { + // // sendEmailToUser( + // // sendEmail, + // // description, + // // userAssignedWarning, + // // monitorData, + // // size, + // // adminEmails, + // // ); + // // } + + // // res.status(201).send({ message: 'success', warnings: completedData }); + + // // if (!record) { + // // return res.status(400).send({ message: 'No valid records found' }); + // // } + // } catch (error) { + // console.log(error); + // } + // }; + + const postWarningsToUserProfile = async function (req, res, next) { + if (!currentWarningDescriptions) { + await getWarningDescriptions(); + } + try { + console.log('post called'); + console.log('req.body', req.body); + const { userId } = req.params; const { iconId, color, date, description } = req.body; const { monitorData } = req.body; - const record = await UserProfile.findById(userId); if (!record) { return res.status(400).send({ message: 'No valid records found' }); @@ -91,17 +184,17 @@ const warningsController = function (UserProfile) { color, ); - const adminEmails = await getUserRoleByEmail(record); - if (sendEmail !== null) { - sendEmailToUser( - sendEmail, - description, - userAssignedWarning, - monitorData, - size, - adminEmails, - ); - } + // const adminEmails = await getUserRoleByEmail(record); + // if (sendEmail !== null) { + // sendEmailToUser( + // sendEmail, + // description, + // userAssignedWarning, + // monitorData, + // size, + // adminEmails, + // ); + // } res.status(201).send({ message: 'success', warnings: completedData }); } catch (error) { @@ -109,6 +202,9 @@ const warningsController = function (UserProfile) { } }; + //new post method add to the user profile + // and return the updated special warnings + const deleteUsersWarnings = async (req, res) => { const { userId } = req.params; const { warningId } = req.body; @@ -133,6 +229,7 @@ const warningsController = function (UserProfile) { return { getWarningsByUserId, + getSpecialWarnings, postWarningsToUserProfile, deleteUsersWarnings, }; @@ -232,13 +329,13 @@ const sortByColorAndDate = (a, b) => { return colorComparison; }; -const filterWarnings = (currentWarningDescriptions, warnings, iconId = null, color = null) => { +const filterWarnings = (currentWarningDescriptions, usersWarnings, iconId = null, color = null) => { const warningsObject = {}; let sendEmail = null; let size = null; - warnings.forEach((warning) => { + usersWarnings.forEach((warning) => { if (!warningsObject[warning.description]) { warningsObject[warning.description] = []; } @@ -270,10 +367,11 @@ const filterWarnings = (currentWarningDescriptions, warnings, iconId = null, col const completedData = []; - for (const descrip of currentWarningDescriptions) { + for (const { warningTitle, abbreviation } of currentWarningDescriptions) { completedData.push({ - title: descrip, - warnings: warns[descrip] ? warns[descrip] : [], + title: warningTitle, + warnings: warns[warningTitle] ? warns[warningTitle] : [], + abbreviation: abbreviation ? abbreviation : null, }); } return { completedData, sendEmail, size }; diff --git a/src/models/currentWarnings.js b/src/models/currentWarnings.js index 18a446199..a4b386c7d 100644 --- a/src/models/currentWarnings.js +++ b/src/models/currentWarnings.js @@ -6,6 +6,8 @@ const currentWarnings = new Schema({ warningTitle: { type: String, required: true }, activeWarning: { type: Boolean, required: true }, isPermanent: { type: Boolean, required: true }, + isSpecial: { type: Boolean, required: true }, + abbreviation: { type: String }, }); module.exports = mongoose.model('currentWarning', currentWarnings, 'currentWarnings'); From 064b34c561a6448e0e72687da0dda30a44ac1193 Mon Sep 17 00:00:00 2001 From: luisarevalo21 Date: Mon, 18 Nov 2024 20:28:31 -0800 Subject: [PATCH 2/9] feat: fixed fetching bug where currentWarnings was null --- src/controllers/warningsController.js | 9 ++++++--- src/routes/warningRouter.js | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/controllers/warningsController.js b/src/controllers/warningsController.js index da9e58984..f822231e9 100644 --- a/src/controllers/warningsController.js +++ b/src/controllers/warningsController.js @@ -68,9 +68,10 @@ const warningsController = function (UserProfile) { //in the same format as the other warnings //warnings [{title: 'warning title', abbreviation: 'warning abbreviation', warnings: [{userId, iconId, color, date, description}]}] const getSpecialWarnings = async function (req, res, next) { - // if (!currentWarningDescriptions) { - // await getWarningDescriptions(); - // } + if (!currentWarningDescriptions) { + await getWarningDescriptions(); + } + try { const { userId } = req.params; const specialWarningsObj = await currentWarnings @@ -92,6 +93,7 @@ const warningsController = function (UserProfile) { return warning; } }); + console.log('fitlered warnings', specialWarningsArray); const { completedData } = filterWarnings(specialWarningsObj, filteredWarnings); @@ -353,6 +355,7 @@ const filterWarnings = (currentWarningDescriptions, usersWarnings, iconId = null size = warningsObject[warning.description].length; } }); + console.log('warningsObject', warningsObject); const warns = Object.keys(warningsObject) .sort(sortKeysAlphabetically) diff --git a/src/routes/warningRouter.js b/src/routes/warningRouter.js index 9eefb48d5..72d41a0cc 100644 --- a/src/routes/warningRouter.js +++ b/src/routes/warningRouter.js @@ -11,6 +11,8 @@ const routes = function (userProfile) { .post(controller.postWarningsToUserProfile) .delete(controller.deleteUsersWarnings); + warningRouter.route('/warnings/:userId/special').get(controller.getSpecialWarnings); + return warningRouter; }; module.exports = routes; From b464559033769e2ffa426a57b0daf903155d0017 Mon Sep 17 00:00:00 2001 From: luisarevalo21 Date: Mon, 18 Nov 2024 20:32:02 -0800 Subject: [PATCH 3/9] fix: removed logs --- src/controllers/warningsController.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/controllers/warningsController.js b/src/controllers/warningsController.js index f822231e9..af23d5c9a 100644 --- a/src/controllers/warningsController.js +++ b/src/controllers/warningsController.js @@ -93,11 +93,9 @@ const warningsController = function (UserProfile) { return warning; } }); - console.log('fitlered warnings', specialWarningsArray); const { completedData } = filterWarnings(specialWarningsObj, filteredWarnings); - // console.log('completedData', completedData); return res.status(201).send({ message: 'success', warnings: completedData }); } catch (error) { console.log('error', error); From a2176560a94a7995b53ad7974ae44d5f2b66c12d Mon Sep 17 00:00:00 2001 From: luisarevalo21 Date: Mon, 18 Nov 2024 20:33:12 -0800 Subject: [PATCH 4/9] fix: removed extra logs --- src/controllers/warningsController.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/controllers/warningsController.js b/src/controllers/warningsController.js index af23d5c9a..01a5876b9 100644 --- a/src/controllers/warningsController.js +++ b/src/controllers/warningsController.js @@ -153,8 +153,6 @@ const warningsController = function (UserProfile) { await getWarningDescriptions(); } try { - console.log('post called'); - console.log('req.body', req.body); const { userId } = req.params; const { iconId, color, date, description } = req.body; const { monitorData } = req.body; @@ -353,7 +351,6 @@ const filterWarnings = (currentWarningDescriptions, usersWarnings, iconId = null size = warningsObject[warning.description].length; } }); - console.log('warningsObject', warningsObject); const warns = Object.keys(warningsObject) .sort(sortKeysAlphabetically) From 6fbdf44f8f01c51a57df837dcd5e1b14362fcf7b Mon Sep 17 00:00:00 2001 From: luisarevalo21 Date: Tue, 26 Nov 2024 19:50:15 -0800 Subject: [PATCH 5/9] added new check for posting warning from user profile --- src/controllers/warningsController.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/controllers/warningsController.js b/src/controllers/warningsController.js index 01a5876b9..a80673b6e 100644 --- a/src/controllers/warningsController.js +++ b/src/controllers/warningsController.js @@ -167,11 +167,22 @@ const warningsController = function (UserProfile) { email: record.email, }; + //if monitorData is passed and has a userId, meaning was sent from userprofile + if (monitorData.userId) { + const monitor = await UserProfile.findById(monitorData.userId); + monitorData.firstName = monitor.firstName; + monitorData.lastName = monitor.lastName; + monitorData.email = monitor.email; + monitorData.userId = monitor._id; + } + const updatedWarnings = await UserProfile.findByIdAndUpdate( { _id: userId, }, - { $push: { warnings: { userId, iconId, color, date, description } } }, + { + $push: { warnings: { userId, iconId, color, date, description } }, + }, { new: true, upsert: true }, ); @@ -196,13 +207,11 @@ const warningsController = function (UserProfile) { res.status(201).send({ message: 'success', warnings: completedData }); } catch (error) { + console.log('error', error); res.status(400).send({ message: error.message || error }); } }; - //new post method add to the user profile - // and return the updated special warnings - const deleteUsersWarnings = async (req, res) => { const { userId } = req.params; const { warningId } = req.body; From 083de017c29a4e777d528b6ccd4e2b8c77e33c8b Mon Sep 17 00:00:00 2001 From: luisarevalo21 Date: Mon, 9 Dec 2024 20:28:11 -0800 Subject: [PATCH 6/9] removed commented code and added the new warnings to the warnings enum --- src/controllers/userProfileController.js | 28 +++++++++++++----------- src/models/userProfile.js | 2 ++ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/controllers/userProfileController.js b/src/controllers/userProfileController.js index db1dc671c..e85077056 100644 --- a/src/controllers/userProfileController.js +++ b/src/controllers/userProfileController.js @@ -1693,7 +1693,6 @@ const userProfileController = function (UserProfile, Project) { return; } const { userId, blueSquareId } = req.params; - // console.log(userId, blueSquareId); UserProfile.findById(userId, async (err, record) => { if (err || !record) { @@ -1715,7 +1714,10 @@ const userProfileController = function (UserProfile, Project) { _id: record._id, }); }) - .catch((error) => res.status(400).send(error)); + .catch((error) => { + console.log('error', error); + res.status(400).send(error); + }); }); }; @@ -1797,20 +1799,20 @@ const userProfileController = function (UserProfile, Project) { } }; - const updateUserInformation = async function (req,res){ + const updateUserInformation = async function (req, res) { try { - const data=req.body; - data.map(async (e)=> { + const data = req.body; + data.map(async (e) => { let result = await UserProfile.findById(e.user_id); - result[e.item]=e.value - let newdata=await result.save() - }) - res.status(200).send({ message: 'Update successful'}); + result[e.item] = e.value; + let newdata = await result.save(); + }); + res.status(200).send({ message: 'Update successful' }); } catch (error) { - console.log(error) - return res.status(500) + console.log(error); + return res.status(500); } - } + }; return { postUserProfile, @@ -1841,7 +1843,7 @@ const userProfileController = function (UserProfile, Project) { getAllTeamCode, getAllTeamCodeHelper, updateUserInformation, - getUserProfileBasicInfo + getUserProfileBasicInfo, }; }; diff --git a/src/models/userProfile.js b/src/models/userProfile.js index 61e8e8f91..aed4a9d98 100644 --- a/src/models/userProfile.js +++ b/src/models/userProfile.js @@ -120,6 +120,8 @@ const userProfileSchema = new Schema({ 'Log Time as You Go', 'Log Time to Action Items', 'Intangible Time Log w/o Reason', + 'Removed Blue Square for No Summary', + 'Removed Blue Square for Hours Close Enough', ], }, color: { From ba98992132cad7c06ab48b3436d812cfbaa58eb4 Mon Sep 17 00:00:00 2001 From: luisarevalo21 Date: Thu, 12 Dec 2024 21:21:56 -0800 Subject: [PATCH 7/9] removed log from dashboard; --- src/helpers/dashboardhelper.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/helpers/dashboardhelper.js b/src/helpers/dashboardhelper.js index 08e0bc907..006271440 100644 --- a/src/helpers/dashboardhelper.js +++ b/src/helpers/dashboardhelper.js @@ -175,20 +175,16 @@ const dashboardhelper = function () { { members: 1 }, ); - console.log(teamsResult); teamsResult.forEach((_myTeam) => { let isUserVisible = false; _myTeam.members.forEach((teamMember) => { if (teamMember.userId.equals(userid) && teamMember.visible) isUserVisible = true; }); - if(isUserVisible) - { + if (isUserVisible) { _myTeam.members.forEach((teamMember) => { - if (!teamMember.userId.equals(userid)) - teamMemberIds.push(teamMember.userId); - }); - } - + if (!teamMember.userId.equals(userid)) teamMemberIds.push(teamMember.userId); + }); + } }); teamMembers = await userProfile.find( @@ -204,8 +200,7 @@ const dashboardhelper = function () { timeOffTill: 1, endDate: 1, missedHours: 1, - } - + }, ); } else { // 'Core Team', 'Owner' //All users @@ -270,7 +265,7 @@ const dashboardhelper = function () { ? teamMember.weeklySummaries[0].summary !== '' : false, weeklycommittedHours: teamMember.weeklycommittedHours, - missedHours: (teamMember.missedHours ?? 0), + missedHours: teamMember.missedHours ?? 0, totaltangibletime_hrs: (timeEntryByPerson[teamMember._id.toString()]?.tangibleSeconds ?? 0) / 3600, totalintangibletime_hrs: From b7670c87c552f97920a1d2fa6bd9711cc3dcb35d Mon Sep 17 00:00:00 2001 From: luisarevalo21 Date: Mon, 30 Dec 2024 20:12:08 -0800 Subject: [PATCH 8/9] removed comments and added email function --- src/controllers/warningsController.js | 80 ++++----------------------- 1 file changed, 12 insertions(+), 68 deletions(-) diff --git a/src/controllers/warningsController.js b/src/controllers/warningsController.js index a80673b6e..427e7257a 100644 --- a/src/controllers/warningsController.js +++ b/src/controllers/warningsController.js @@ -60,13 +60,6 @@ const warningsController = function (UserProfile) { } }; - // get all the current warnings as that helps with the sorting for the fianl process - - //get users special warnings - //get all warnings the user has - //filter and return a list of all warnings that are special - //in the same format as the other warnings - //warnings [{title: 'warning title', abbreviation: 'warning abbreviation', warnings: [{userId, iconId, color, date, description}]}] const getSpecialWarnings = async function (req, res, next) { if (!currentWarningDescriptions) { await getWarningDescriptions(); @@ -84,10 +77,6 @@ const warningsController = function (UserProfile) { const { warnings } = await UserProfile.findById(userId); - // look into why the filtering isnt working - //must get the filtered warnings taht are special - //i need the users' special warnings and the warnings that are special - const filteredWarnings = warnings.filter((warning) => { if (specialWarningsArray.includes(warning.description)) { return warning; @@ -101,52 +90,6 @@ const warningsController = function (UserProfile) { console.log('error', error); } }; - //post new warning via the user profile - //assiginng a new warning to a the user - // const postNewWarningToUserProfile = async function (req, res) { - // try { - // const { userId } = req.params; - // const { iconId, color, date, description } = req.body; - - // // console.log('req.body', userId); - // // console.log('typeoff', typeof userId); - // const record = await UserProfile.findById(userId); - // // const updatedWarnings = await UserProfile.findByIdAndUpdate( - // // { - // // _id: ObjectId(userId), - // // }, - // // { $push: { warnings: { userId, iconId, color, date, description } } }, - // // { new: true, upsert: true }, - // // ); - // // console.log('currentWarningDescriptions', currentWarningDescriptions); - // // const { completedData, sendEmail, size } = filterWarnings( - // // currentWarningDescriptions, - // // updatedWarnings.warnings, - // // iconId, - // // color, - // // ); - - // // const adminEmails = await getUserRoleByEmail(record); - // // if (sendEmail !== null) { - // // sendEmailToUser( - // // sendEmail, - // // description, - // // userAssignedWarning, - // // monitorData, - // // size, - // // adminEmails, - // // ); - // // } - - // // res.status(201).send({ message: 'success', warnings: completedData }); - - // // if (!record) { - // // return res.status(400).send({ message: 'No valid records found' }); - // // } - // } catch (error) { - // console.log(error); - // } - // }; const postWarningsToUserProfile = async function (req, res, next) { if (!currentWarningDescriptions) { @@ -157,6 +100,7 @@ const warningsController = function (UserProfile) { const { iconId, color, date, description } = req.body; const { monitorData } = req.body; const record = await UserProfile.findById(userId); + if (!record) { return res.status(400).send({ message: 'No valid records found' }); } @@ -193,17 +137,17 @@ const warningsController = function (UserProfile) { color, ); - // const adminEmails = await getUserRoleByEmail(record); - // if (sendEmail !== null) { - // sendEmailToUser( - // sendEmail, - // description, - // userAssignedWarning, - // monitorData, - // size, - // adminEmails, - // ); - // } + const adminEmails = await getUserRoleByEmail(record); + if (sendEmail !== null) { + sendEmailToUser( + sendEmail, + description, + userAssignedWarning, + monitorData, + size, + adminEmails, + ); + } res.status(201).send({ message: 'success', warnings: completedData }); } catch (error) { From 7078d098da1229a7cdee246b49a6677269b881c8 Mon Sep 17 00:00:00 2001 From: luisarevalo21 Date: Fri, 17 Jan 2025 20:08:29 -0800 Subject: [PATCH 9/9] adjusted the email tempalte for issue blue square and issued a warning --- src/controllers/warningsController.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/controllers/warningsController.js b/src/controllers/warningsController.js index 427e7257a..46f383c13 100644 --- a/src/controllers/warningsController.js +++ b/src/controllers/warningsController.js @@ -217,19 +217,18 @@ const sendEmailToUser = ( adminEmails, ) => { const ordinal = getOrdinal(size); - const subjectTitle = ordinal + ' Warning'; const currentUserName = `${userAssignedWarning.firstName} ${userAssignedWarning.lastName}`; const emailTemplate = sendEmail === 'issue warning' ? `

Hello ${currentUserName},

-

This is the ${ordinal} time the Admin team has requested the same thing from you. Specifically, ${warningDescription}. Please carefully review the previous communications you’ve received to fully understand what is being requested. If anything is unclear, don’t hesitate to ask questions—the Admin team is here to assist.

-

Moving forward, please ensure this issue is resolved. Repeated requests for the same thing require unnecessary administrative attention and may result in a blue square being issued if it happens again.

+

This is the ${ordinal} time the Admin team has requested the same thing from you. Specifically, we ${warningDescription}. Please carefully review the previous communications you’ve received to fully understand what is being requested. If anything is unclear, don’t hesitate to ask questions—the Admin team is here to assist.

+

Moving forward, please ensure you don’t create situations where we need to keep doing this for you. Repeated requests for the same thing require unnecessary administrative attention and may result in a blue square being issued if it happens again.

The Admin member who issued the warning is ${monitorData.firstName} ${monitorData.lastName} and their email is ${monitorData.email}. Please comment on your Google Doc and tag them using this email if you have any questions.

With Gratitude,

One Community

` : `

Hello ${currentUserName},

-

A blue square has been issued because this is the ${ordinal} time the Admin team has requested the same thing from you. Specifically, ${warningDescription}.

+

A blue square has been issued because this is the ${ordinal} time the Admin team has requested the same thing from you. Specifically, we ${warningDescription}.

Moving forward, please ensure this is resolved. Repeated requests for the same thing require unnecessary administrative attention, will result in an additional blue square being issued, and could lead to termination.

Please carefully review the previous communications you’ve received to fully understand what is being requested. If anything is unclear, feel free to ask questions—the Admin team is here to help.

The Admin member who issued this blue square is ${monitorData.firstName} ${monitorData.lastName} and can be reached at ${monitorData.email}. If you have any questions, please comment on your Google Doc and tag them using this email.

@@ -239,7 +238,7 @@ const sendEmailToUser = ( if (sendEmail === 'issue warning') { emailSender( `${userAssignedWarning.email}`, - subjectTitle, + "IMPORTANT: Please read this email and take note so you don't get a blue square", emailTemplate, adminEmails.toString(), null, @@ -247,7 +246,7 @@ const sendEmailToUser = ( } else if (sendEmail === 'issue blue square') { emailSender( `${userAssignedWarning.email}`, - `Blue Square issued for ${warningDescription}`, + `IMPORTANT: You have been issued a blue square`, emailTemplate, adminEmails.toString(), null,