-
Notifications
You must be signed in to change notification settings - Fork 30
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 #728 from OneCommunityGlobal/development
Backend Release to Main [1.39]
- Loading branch information
Showing
20 changed files
with
529 additions
and
257 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -114,9 +114,5 @@ | |
{ | ||
"unit": "Sand", | ||
"category": "Material" | ||
}, | ||
{ | ||
"unit": "FakeUnitForTesting", | ||
"category": "Material" | ||
} | ||
] |
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 |
---|---|---|
@@ -1,30 +1,28 @@ | ||
const UserProfile = require('../models/userProfile'); | ||
|
||
const permissionChangeLogController = function (PermissionChangeLog) { | ||
|
||
const getPermissionChangeLogs = async function (req, res) { | ||
|
||
try { | ||
const userProfile = await UserProfile.findOne({ _id: req.params.userId }).exec() | ||
const userProfile = await UserProfile.findOne({ _id: req.params.userId }).exec(); | ||
|
||
if (userProfile) { | ||
if (userProfile.role !== 'Owner') { | ||
res.status(204).send([]) | ||
res.status(204).send([]); | ||
} else { | ||
const changeLogs = await PermissionChangeLog.find({}) | ||
res.status(200).send(changeLogs) | ||
const changeLogs = await PermissionChangeLog.find({}); | ||
res.status(200).send(changeLogs); | ||
} | ||
} else { | ||
res.status(403).send(`User (${req.params.userId}) not found.`) | ||
res.status(403).send(`User (${req.params.userId}) not found.`); | ||
} | ||
} catch (err) { | ||
console.error(err) | ||
console.error(err); | ||
} | ||
} | ||
}; | ||
|
||
return { | ||
getPermissionChangeLogs | ||
} | ||
} | ||
getPermissionChangeLogs, | ||
}; | ||
}; | ||
|
||
module.exports = permissionChangeLogController | ||
module.exports = permissionChangeLogController; |
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
const mongoose = require("mongoose"); | ||
const { v4: uuidv4 } = require("uuid"); | ||
const moment = require("moment-timezone"); | ||
const jwt = require("jsonwebtoken"); | ||
const emailSender = require("../utilities/emailSender"); | ||
const config = require("../config"); | ||
const cache = require("../utilities/nodeCache")(); | ||
const mongoose = require('mongoose'); | ||
const { v4: uuidv4 } = require('uuid'); | ||
const moment = require('moment-timezone'); | ||
const jwt = require('jsonwebtoken'); | ||
const emailSender = require('../utilities/emailSender'); | ||
const config = require('../config'); | ||
const cache = require('../utilities/nodeCache')(); | ||
|
||
// returns the email body that includes the setup link for the recipient. | ||
function sendLinkMessage(Link) { | ||
|
@@ -121,13 +121,13 @@ const profileInitialSetupController = function ( | |
let { email, baseUrl, weeklyCommittedHours } = req.body; | ||
email = email.toLowerCase(); | ||
const token = uuidv4(); | ||
const expiration = moment().tz("America/Los_Angeles").add(1, "week"); | ||
const expiration = moment().tz('America/Los_Angeles').add(1, 'week'); | ||
try { | ||
const existingEmail = await userProfile.findOne({ | ||
email, | ||
}); | ||
if (existingEmail) { | ||
res.status(400).send("email already in use"); | ||
res.status(400).send('email already in use'); | ||
} else { | ||
await ProfileInitialSetupToken.findOneAndDelete({ email }); | ||
|
||
|
@@ -161,7 +161,7 @@ const profileInitialSetupController = function ( | |
*/ | ||
const validateSetupToken = async (req, res) => { | ||
const { token } = req.body; | ||
const currentMoment = moment.tz("America/Los_Angeles"); | ||
const currentMoment = moment.tz('America/Los_Angeles'); | ||
try { | ||
const foundToken = await ProfileInitialSetupToken.findOne({ token }); | ||
|
||
|
@@ -171,10 +171,10 @@ const profileInitialSetupController = function ( | |
if (expirationMoment.isAfter(currentMoment)) { | ||
res.status(200).send(foundToken); | ||
} else { | ||
res.status(400).send("Invalid token"); | ||
res.status(400).send('Invalid token'); | ||
} | ||
} else { | ||
res.status(404).send("Token not found"); | ||
res.status(404).send('Token not found'); | ||
} | ||
} catch (error) { | ||
res.status(500).send(`Error finding token: ${error}`); | ||
|
@@ -192,30 +192,30 @@ const profileInitialSetupController = function ( | |
*/ | ||
const setUpNewUser = async (req, res) => { | ||
const { token } = req.body; | ||
const currentMoment = moment.tz("America/Los_Angeles"); | ||
const currentMoment = moment.tz('America/Los_Angeles'); | ||
try { | ||
const foundToken = await ProfileInitialSetupToken.findOne({ token }); | ||
const existingEmail = await userProfile.findOne({ | ||
email: foundToken.email, | ||
}); | ||
if (existingEmail) { | ||
res.status(400).send("email already in use"); | ||
res.status(400).send('email already in use'); | ||
} else if (foundToken) { | ||
const expirationMoment = moment(foundToken.expiration); | ||
|
||
if (expirationMoment.isAfter(currentMoment)) { | ||
const defaultProject = await Project.findOne({ | ||
projectName: "Orientation and Initial Setup", | ||
projectName: 'Orientation and Initial Setup', | ||
}); | ||
|
||
const newUser = new userProfile(); | ||
newUser.password = req.body.password; | ||
newUser.role = "Volunteer"; | ||
newUser.role = 'Volunteer'; | ||
newUser.firstName = req.body.firstName; | ||
newUser.lastName = req.body.lastName; | ||
newUser.jobTitle = req.body.jobTitle; | ||
newUser.phoneNumber = req.body.phoneNumber; | ||
newUser.bio = ""; | ||
newUser.bio = ''; | ||
newUser.weeklycommittedHours = foundToken.weeklyCommittedHours; | ||
newUser.weeklycommittedHoursHistory = [ | ||
{ | ||
|
@@ -229,33 +229,32 @@ const profileInitialSetupController = function ( | |
newUser.projects = Array.from(new Set([defaultProject])); | ||
newUser.createdDate = Date.now(); | ||
newUser.email = req.body.email; | ||
newUser.weeklySummaries = [{ summary: "" }]; | ||
newUser.weeklySummaries = [{ summary: '' }]; | ||
newUser.weeklySummariesCount = 0; | ||
newUser.weeklySummaryOption = "Required"; | ||
newUser.mediaUrl = ""; | ||
newUser.weeklySummaryOption = 'Required'; | ||
newUser.mediaUrl = ''; | ||
newUser.collaborationPreference = req.body.collaborationPreference; | ||
newUser.timeZone = req.body.timeZone || "America/Los_Angeles"; | ||
newUser.timeZone = req.body.timeZone || 'America/Los_Angeles'; | ||
newUser.location = req.body.location; | ||
newUser.profilePic = req.body.profilePicture; | ||
newUser.permissions = { | ||
frontPermissions: [], | ||
backPermissions: [], | ||
}; | ||
newUser.bioPosted = "default"; | ||
newUser.bioPosted = 'default'; | ||
newUser.privacySettings.email = req.body.privacySettings.email; | ||
newUser.privacySettings.phoneNumber = | ||
req.body.privacySettings.phoneNumber; | ||
newUser.teamCode = ""; | ||
newUser.privacySettings.phoneNumber = req.body.privacySettings.phoneNumber; | ||
newUser.teamCode = ''; | ||
newUser.isFirstTimelog = true; | ||
|
||
const savedUser = await newUser.save(); | ||
|
||
emailSender( | ||
process.env.MANAGER_EMAIL || "[email protected]", // "[email protected]" | ||
process.env.MANAGER_EMAIL || '[email protected]', // "[email protected]" | ||
`NEW USER REGISTERED: ${savedUser.firstName} ${savedUser.lastName}`, | ||
informManagerMessage(savedUser), | ||
null, | ||
null | ||
null, | ||
); | ||
await ProfileInitialSetupToken.findByIdAndDelete(foundToken._id); | ||
|
||
|
@@ -265,7 +264,7 @@ const profileInitialSetupController = function ( | |
permissions: savedUser.permissions, | ||
expiryTimestamp: moment().add( | ||
config.TOKEN.Lifetime, | ||
config.TOKEN.Units | ||
config.TOKEN.Units, | ||
), | ||
}; | ||
|
||
|
@@ -299,14 +298,14 @@ const profileInitialSetupController = function ( | |
email: savedUser.email, | ||
}; | ||
|
||
const allUserCache = JSON.parse(cache.getCache("allusers")); | ||
const allUserCache = JSON.parse(cache.getCache('allusers')); | ||
allUserCache.push(NewUserCache); | ||
cache.setCache("allusers", JSON.stringify(allUserCache)); | ||
cache.setCache('allusers', JSON.stringify(allUserCache)); | ||
} else { | ||
res.status(400).send("Token is expired"); | ||
res.status(400).send('Token is expired'); | ||
} | ||
} else { | ||
res.status(400).send("Invalid token"); | ||
res.status(400).send('Invalid token'); | ||
} | ||
} catch (error) { | ||
res.status(500).send(`Error: ${error}`); | ||
|
@@ -336,28 +335,28 @@ const profileInitialSetupController = function ( | |
const users = []; | ||
const results = await userProfile.find( | ||
{}, | ||
"location totalTangibleHrs hoursByCategory" | ||
'location totalTangibleHrs hoursByCategory', | ||
); | ||
|
||
results.forEach((item) => { | ||
if ( | ||
(item.location?.coords.lat && | ||
item.location?.coords.lng && | ||
item.totalTangibleHrs >= 10) || | ||
(item.location?.coords.lat && | ||
item.location?.coords.lng && | ||
calculateTotalHours(item.hoursByCategory) >= 10) | ||
(item.location?.coords.lat | ||
&& item.location?.coords.lng | ||
&& item.totalTangibleHrs >= 10) | ||
|| (item.location?.coords.lat | ||
&& item.location?.coords.lng | ||
&& calculateTotalHours(item.hoursByCategory) >= 10) | ||
) { | ||
users.push(item); | ||
} | ||
}); | ||
const modifiedUsers = users.map((item) => ({ | ||
const modifiedUsers = users.map(item => ({ | ||
location: item.location, | ||
})); | ||
|
||
const mapUsers = await MapLocation.find({}); | ||
const combined = [...modifiedUsers, ...mapUsers]; | ||
const countries = combined.map((user) => user.location.country); | ||
const countries = combined.map(user => user.location.country); | ||
const totalUniqueCountries = [...new Set(countries)].length; | ||
res.status(200).send({ CountryCount: totalUniqueCountries }); | ||
} catch (error) { | ||
|
Oops, something went wrong.