-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #775 from OneCommunityGlobal/Sucheta-create-summar…
…y-report-recipient-button Sucheta - Create Summary Report Recipient Button
- Loading branch information
Showing
12 changed files
with
730 additions
and
565 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -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({ | ||
|
@@ -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) { | ||
|
@@ -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, | ||
|
@@ -1029,6 +1061,7 @@ const userProfileController = function (UserProfile) { | |
refreshToken, | ||
getUserBySingleName, | ||
getUserByFullName, | ||
authorizeUser, | ||
}; | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.