-
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 #607 from OneCommunityGlobal/development
Backend Release to Main [1.17]
- Loading branch information
Showing
10 changed files
with
172 additions
and
26 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
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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// TODO: uncomment when executing auth checks | ||
// const jwt = require('jsonwebtoken'); | ||
// const config = require('../../config'); | ||
|
||
const bmMProjectController = function (BuildingProject) { | ||
// TODO: uncomment when executing auth checks | ||
// const { JWT_SECRET } = config; | ||
|
||
const fetchAllProjects = async (req, res) => { | ||
//! Note: for easier testing this route currently returns all projects from the db | ||
// TODO: uncomment the lines below to return only projects where field buildingManager === userid | ||
// const token = req.headers.authorization; | ||
// const { userid } = jwt.verify(token, JWT_SECRET); | ||
try { | ||
const projectData = await BuildingProject | ||
// TODO: uncomment this line to filter by buildingManager field | ||
// .find({ buildingManager: userid }) | ||
.find() | ||
.populate([ | ||
{ | ||
path: 'buildingManager', | ||
select: '_id firstName lastName email', | ||
}, | ||
{ | ||
path: 'team', | ||
select: '_id firstName lastName email', | ||
}, | ||
]) | ||
.exec() | ||
.then(result => result) | ||
.catch(error => res.status(500).send(error)); | ||
res.status(200).send(projectData); | ||
} catch (err) { | ||
res.json(err); | ||
} | ||
}; | ||
|
||
// fetches single project by project id | ||
const fetchSingleProject = async (req, res) => { | ||
//! Note: for easier testing this route currently returns the project without an auth check | ||
// TODO: uncomment the lines below to check the user's ability to view the current project | ||
// const token = req.headers.authorization; | ||
// const { userid } = jwt.verify(token, JWT_SECRET); | ||
const { projectId } = req.params; | ||
try { | ||
BuildingProject | ||
.findById(projectId) | ||
.populate([ | ||
{ | ||
path: 'buildingManager', | ||
select: '_id firstName lastName email', | ||
}, | ||
{ | ||
path: 'team', | ||
select: '_id firstName lastName email', | ||
}, | ||
]) | ||
.exec() | ||
.then(project => res.status(200).send(project)) | ||
// TODO: uncomment this block to execute the auth check | ||
// authenticate request by comparing userId param with buildingManager id field | ||
// Note: _id has type object and must be converted to string | ||
// .then((project) => { | ||
// if (userid !== project.buildingManager._id.toString()) { | ||
// return res.status(403).send({ | ||
// message: 'You are not authorized to view this record.', | ||
// }); | ||
// } | ||
// return res.status(200).send(project); | ||
// }) | ||
.catch(error => res.status(500).send(error)); | ||
} catch (err) { | ||
res.json(err); | ||
} | ||
}; | ||
return { fetchAllProjects, fetchSingleProject }; | ||
}; | ||
|
||
module.exports = bmMProjectController; |
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 |
---|---|---|
|
@@ -87,18 +87,29 @@ const userHelper = function () { | |
firstName, | ||
lastName, | ||
infringement, | ||
totalInfringements | ||
totalInfringements, | ||
timeRemaining | ||
) { | ||
let final_paragraph = ''; | ||
|
||
if (timeRemaining == undefined) { | ||
final_paragraph = '<p>Life happens and we understand that. That’s why we allow 5 of them before taking action. This action usually includes removal from our team though, so please let your direct supervisor know what happened and do your best to avoid future blue squares if you are getting close to 5 and wish to avoid termination. Each blue square drops off after a year.</p>'; | ||
} else { | ||
final_paragraph = `<p>Life happens and we understand that. Please make up the missed hours this following week though to avoid getting another blue square. So you know what’s needed, the missing/incomplete hours (${timeRemaining} hours) have been added to your current week and this new weekly total can be seen at the top of your dashboard.</p> | ||
<p>Reminder also that each blue square is removed from your profile 1 year after it was issued.</p>`; | ||
} | ||
|
||
const text = `Dear <b>${firstName} ${lastName}</b>, | ||
<p>Oops, it looks like something happened and you’ve managed to get a blue square.</p> | ||
<p><b>Date Assigned:</b> ${infringement.date}</p> | ||
<p><b>Description:</b> ${infringement.description}</p> | ||
<p><b>Total Infringements:</b> This is your <b>${moment | ||
.localeData() | ||
.ordinal(totalInfringements)}</b> blue square of 5.</p> | ||
<p>Life happens and we understand that. That’s why we allow 5 of them before taking action. This action usually includes removal from our team though, so please let your direct supervisor know what happened and do your best to avoid future blue squares if you are getting close to 5 and wish to avoid termination. Each blue square drops off after a year.</p> | ||
${final_paragraph} | ||
<p>Thank you,<br /> | ||
One Community</p>`; | ||
|
||
return text; | ||
}; | ||
|
||
|
@@ -322,6 +333,8 @@ const userHelper = function () { | |
for (let i = 0; i < users.length; i += 1) { | ||
const user = users[i]; | ||
|
||
const person = await userProfile.findById(user._id); | ||
|
||
const foundReason = await Reason.findOne({ | ||
date: currentUTCDate, | ||
userId: user._id, | ||
|
@@ -356,6 +369,9 @@ const userHelper = function () { | |
const timeNotMet = timeSpent < weeklycommittedHours; | ||
let description; | ||
|
||
const timeRemaining = weeklycommittedHours - timeSpent; | ||
|
||
|
||
const updateResult = await userProfile.findByIdAndUpdate( | ||
personId, | ||
{ | ||
|
@@ -446,15 +462,28 @@ const userHelper = function () { | |
{ new: true } | ||
); | ||
|
||
emailSender( | ||
status.email, | ||
"New Infringement Assigned", | ||
getInfringementEmailBody( | ||
let emailBody = ''; | ||
if (person.role == 'Core Team' && timeRemaining > 0) { | ||
emailBody = getInfringementEmailBody( | ||
status.firstName, | ||
status.lastName, | ||
infringement, | ||
status.infringements.length | ||
), | ||
status.infringements.length, | ||
timeRemaining, | ||
); | ||
} else { | ||
emailBody = getInfringementEmailBody( | ||
status.firstName, | ||
status.lastName, | ||
infringement, | ||
status.infringements.length, | ||
); | ||
} | ||
|
||
emailSender( | ||
status.email, | ||
'New Infringement Assigned', | ||
emailBody, | ||
null, | ||
"[email protected]" | ||
); | ||
|
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const { Schema } = mongoose; | ||
|
||
const buildingProject = new Schema({ | ||
isActive: Boolean, | ||
name: String, | ||
template: String, // construction template (ie Earthbag Village) | ||
location: String, // use lat/lng instead? | ||
dateCreated: { type: Date, default: Date.now }, | ||
buildingManager: { type: mongoose.SchemaTypes.ObjectId, ref: 'userProfile' }, // BM's id | ||
team: [{ type: mongoose.SchemaTypes.ObjectId, ref: 'userProfile' }], | ||
}); | ||
|
||
module.exports = mongoose.model('buildingProject', buildingProject, 'buildingProjects'); |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const express = require('express'); | ||
|
||
const routes = function (buildingProject) { | ||
const projectRouter = express.Router(); | ||
const controller = require('../../controllers/bmdashboard/bmProjectController')(buildingProject); | ||
|
||
projectRouter.route('/projects') | ||
.get(controller.fetchAllProjects); | ||
|
||
projectRouter.route('/project/:projectId') | ||
.get(controller.fetchSingleProject); | ||
|
||
return projectRouter; | ||
}; | ||
|
||
module.exports = routes; |
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,6 +1,6 @@ | ||
|
||
const escapeRegex = function (text) { | ||
return text.replace(/[[\]{}()*+?.\\^$|]/g, '\\$&'); | ||
return `^${text.replace(/[[\]{}()*+?.\\^$|]/g, '\\$&')}&`; | ||
}; | ||
|
||
module.exports = escapeRegex; |