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

Backend Release to Main [1.52] #790

Merged
merged 29 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
377e5e9
added adminLinks field to getTasksForTeamsByUser controller
Shuhua-L Feb 10, 2024
7cd87e2
Merge branch 'development' into Shuhua-Add_Google_Doc_Icon
Shuhua-L Feb 16, 2024
697d3aa
Merge branch 'development' into Shuhua-Add_Google_Doc_Icon
Shuhua-L Feb 18, 2024
8f608c1
Merge branch 'development' into Shuhua-Add_Google_Doc_Icon
Shuhua-L Feb 22, 2024
af28630
removed reason model,controller and router, updated blue square email
abdel-lall Feb 25, 2024
e87e562
added email notification to time off scheduler
abdel-lall Feb 26, 2024
d97f19a
merge to dev
abdel-lall Feb 26, 2024
7d19fed
Merge remote-tracking branch 'origin' into Abdel_update_bleu_square_s…
abdel-lall Feb 29, 2024
6d98d7b
make isVisible default value to be true in userprofile model
wang9hu Feb 29, 2024
6066f1e
creates function to add weekly summary report recipients
sucheta90 Feb 29, 2024
c5dbe78
fixed time off notification email body
abdel-lall Mar 2, 2024
ae7c01b
Merge remote-tracking branch 'origin' into Abdel_update_bleu_square_s…
abdel-lall Mar 2, 2024
d33cb36
updated old request auto delete
abdel-lall Mar 2, 2024
836f525
Merge pull request #779 from OneCommunityGlobal/Abdel_update_bleu_squ…
one-community Mar 3, 2024
baf3ded
Merge pull request #762 from OneCommunityGlobal/Shuhua-Add_Google_Doc…
one-community Mar 3, 2024
95456d0
Revert "Abdel update bleu square scheduler"
one-community Mar 4, 2024
bb5ebc2
Merge pull request #785 from OneCommunityGlobal/revert-779-Abdel_upda…
one-community Mar 4, 2024
bce16aa
Revert "Revert "Abdel update bleu square scheduler""
one-community Mar 5, 2024
4f0c524
Merge pull request #787 from OneCommunityGlobal/revert-785-revert-779…
one-community Mar 5, 2024
b611045
Revert "Revert "Revert "Abdel update bleu square scheduler"""
one-community Mar 5, 2024
c21cf53
Merge pull request #788 from OneCommunityGlobal/revert-787-revert-785…
one-community Mar 5, 2024
083c736
Merge branch 'development' of github.com:OneCommunityGlobal/HGNRest i…
sucheta90 Mar 7, 2024
5198439
changed the user email to [email protected] on userProfile…
sucheta90 Mar 7, 2024
beb696d
changed the user email to [email protected] on userProfile…
sucheta90 Mar 7, 2024
313bd24
Merge pull request #774 from OneCommunityGlobal/xiaow_make_isvisible_…
one-community Mar 7, 2024
b36c798
replaced user email with the correct one
sucheta90 Mar 7, 2024
ed54870
replaced user email with owner's email for authorized user
sucheta90 Mar 7, 2024
c9dd61d
resolved conflict in src/models/userProfile.js
sucheta90 Mar 7, 2024
3f7b27f
Merge pull request #775 from OneCommunityGlobal/Sucheta-create-summar…
one-community Mar 8, 2024
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
116 changes: 58 additions & 58 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/controllers/bmdashboard/bmIssueController.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const bmIssueController = function (BuildingIssue) {
BuildingIssue
.find()
.populate()
.then(result => res.status(200).send(result))
.catch(error => res.status(500).send(error));
.then((result) => res.status(200).send(result))
.catch((error) => res.status(500).send(error));
} catch (err) {
res.json(err);
}
Expand All @@ -16,8 +16,8 @@ const bmIssueController = function (BuildingIssue) {
const bmPostIssue = async (req, res) => {
try {
const newIssue = BuildingIssue.create(req.body)
.then(result => res.status(201).send(result))
.catch(error => res.status(500).send(error));
.then((result) => res.status(201).send(result))
.catch((error) => res.status(500).send(error));
} catch (err) {
res.json(err);
}
Expand Down
105 changes: 104 additions & 1 deletion src/controllers/reportsController.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
const mongoose = require('mongoose');
const reporthelper = require('../helpers/reporthelper')();
const { hasPermission } = require('../utilities/permissions');
const UserProfile = require('../models/userProfile');
const userhelper = require('../helpers/userHelper')();

const reportsController = function () {
const getWeeklySummaries = async function (req, res) {
if (!await hasPermission(req.body.requestor, 'getWeeklySummaries')) {
if (!(await hasPermission(req.body.requestor, 'getWeeklySummaries'))) {
res.status(403).send('You are not authorized to view all users');
return;
}
Expand All @@ -17,8 +20,108 @@ const reportsController = function () {
.catch((error) => res.status(404).send(error));
};

/**
* Gets the Recipients added by the owner to receive the Weekly Summary Reports
* @param {*} req
* @param {*} res
*/

const getReportRecipients = function (req, res) {
try {
UserProfile.find(
{ getWeeklyReport: true },
{
email: 1,
firstName: 1,
lastName: 1,
createdDate: 1,
getWeeklyReport: 1,
},
)
.then((results) => {
res.status(200).send(results);
})
.catch((error) => {
console.log('error:', error); // need to delete later *
res.status(404).send({ error });
});
} catch (err) {
console.log('error:', err); // need to delete later *
res.status(404).send(err);
}
};

/**
* Function deletes slected Recipients from the list
* @param {*} req
* @param {*} res
* @returns
*/
const deleteReportsRecepients = (req, res) => {
const { userid } = req.params;
const id = userid;
try {
if (!mongoose.Types.ObjectId.isValid(id)) {
return res.status(404).json({
msg: `No task with id :${id}`,
});
}

UserProfile.updateOne({ _id: id }, { $set: { getWeeklyReport: false } })
.then((record) => {
if (!record) {
console.log("'No valid records found'");
res.status(404).send('No valid records found');
return;
}
res.status(200).send({
message: 'updated user record with getWeeklyReport false',
});
})
.catch((err) => {
console.log('error in catch block last:', err);
res.status(404).send(err);
});
} catch (error) {
res.status(404).send(error);
}
};

const saveReportsRecepients = (req, res) => {
const { userid } = req.params;
const id = userid;
try {
if (!mongoose.Types.ObjectId.isValid(id)) {
return res.status(404).json({
msg: `No task with id :${id}`,
});
}

UserProfile.updateOne({ _id: id }, { $set: { getWeeklyReport: true } })
.then((record) => {
if (!record) {
console.log("'No valid records found'");
res.status(404).send('No valid records found');
return;
}
res
.status(200)
.send({ message: 'updated user record with getWeeklyReport true' });
})
.catch((err) => {
console.log('error in catch block last:', err);
res.status(404).send(err);
});
} catch (error) {
res.status(404).send(error);
}
};

return {
getWeeklySummaries,
getReportRecipients,
deleteReportsRecepients,
saveReportsRecepients,
};
};

Expand Down
43 changes: 38 additions & 5 deletions src/controllers/userProfileController.js
Original file line number Diff line number Diff line change
Expand Up @@ -668,9 +668,9 @@ const userProfileController = function (UserProfile) {
cache.removeCache(`user-${userId}`);
if (!key || value === undefined) {
return res.status(400).send({ error: 'Missing property or value' });
}
}

return UserProfile.findById(userId)
return UserProfile.findById(userId)
.then((user) => {
user.set({
[key]: value,
Expand Down Expand Up @@ -954,7 +954,7 @@ const userProfileController = function (UserProfile) {

// Search for user by first name
const getUserBySingleName = (req, res) => {
const pattern = new RegExp(`^${ req.params.singleName}`, 'i');
const pattern = new RegExp(`^${req.params.singleName}`, 'i');

// Searches for first or last name
UserProfile.find({
Expand Down Expand Up @@ -984,8 +984,8 @@ const userProfileController = function (UserProfile) {
.split(' ')
.filter((name) => name !== '');
// Creates a partial match regex for both first and last name
const firstNameRegex = new RegExp(`^${ escapeRegExp(fullName[0])}`, 'i');
const lastNameRegex = new RegExp(`^${ escapeRegExp(fullName[1])}`, 'i');
const firstNameRegex = new RegExp(`^${escapeRegExp(fullName[0])}`, 'i');
const lastNameRegex = new RegExp(`^${escapeRegExp(fullName[1])}`, 'i');

// Verfies both the first and last name are present
if (fullName.length < 2) {
Expand All @@ -1010,6 +1010,38 @@ const userProfileController = function (UserProfile) {
.catch((error) => res.status(500).send(error));
};

/**
* Authorizes user to be able to add Weekly Report Recipients
*/
const authorizeUser = async (req, res) => {
try {
await UserProfile.findOne({
email: {
$regex: escapeRegex('[email protected]'), // PLEASE CHANGE THIS EMAIL TO MATCH THE USER PROFILE WHILE TESTING THE PR
$options: 'i',
},
}).then(async (user) => {
await bcrypt
.compare(req.body.currentPassword, user.password)
.then((passwordMatch) => {
if (!passwordMatch) {
return res.status(400).send({
error: 'Incorrect current password',
});
}
return res
.status(200)
.send({ message: 'Correct Password, Password matches!' });
})
.catch((error) => {
res.status(500).send(error);
});
});
} catch (err) {
res.status(500).send(err);
}
};

return {
postUserProfile,
getUserProfiles,
Expand All @@ -1029,6 +1061,7 @@ const userProfileController = function (UserProfile) {
refreshToken,
getUserBySingleName,
getUserByFullName,
authorizeUser,
};
};

Expand Down
1 change: 1 addition & 0 deletions src/cronjobs/userProfileJobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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;
if (moment().tz('America/Los_Angeles').day() === SUNDAY) {
Expand Down
Loading
Loading