-
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 #589 from OneCommunityGlobal/development
Backend Release to Main [1.14]
- Loading branch information
Showing
2 changed files
with
64 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -3,6 +3,8 @@ const wbs = require('../models/wbs'); | |
const timeEntryHelper = require('../helpers/timeEntryHelper')(); | ||
const taskHelper = require('../helpers/taskHelper')(); | ||
const { hasPermission } = require('../utilities/permissions'); | ||
const emailSender = require('../utilities/emailSender'); | ||
const userProfile = require('../models/userProfile'); | ||
|
||
const taskController = function (Task) { | ||
const getTasks = (req, res) => { | ||
|
@@ -774,7 +776,6 @@ const taskController = function (Task) { | |
}); | ||
|
||
res.status(200).send(task); | ||
|
||
} catch (error) { | ||
// Generic error message, you can adjust as needed | ||
res.status(500).send({ error: 'Internal Server Error', details: error.message }); | ||
|
@@ -848,6 +849,60 @@ const taskController = function (Task) { | |
} | ||
}; | ||
|
||
const updateTaskStatus = async (req, res) => { | ||
const { taskId } = req.params; | ||
|
||
Task.findOneAndUpdate( | ||
{ _id: mongoose.Types.ObjectId(taskId) }, | ||
{ ...req.body, modifiedDatetime: Date.now() }, | ||
) | ||
.then(() => res.status(201).send()) | ||
.catch(error => res.status(404).send(error)); | ||
}; | ||
|
||
const getReviewReqEmailBody = function (name, taskName) { | ||
const text = `New Task Review Request From <b>${name}</b>: | ||
<p>The following task is available to review:</p> | ||
<p><b>${taskName}</b></p> | ||
<p>Thank you,</p> | ||
<p>One Community</p>`; | ||
|
||
return text; | ||
}; | ||
|
||
const getRecipients = async function (myUserId) { | ||
const recipients = []; | ||
const user = await userProfile.findById(myUserId); | ||
const membership = await userProfile.find({ role: { $in: ['Administrator', 'Manager', 'Mentor'] } }); | ||
membership.forEach((member) => { | ||
if (member.teams.some(team => user.teams.includes(team))) { | ||
recipients.push(member.email); | ||
} | ||
}); | ||
return recipients; | ||
}; | ||
|
||
const sendReviewReq = async function (req, res) { | ||
const { | ||
myUserId, name, taskName, | ||
} = req.body; | ||
const emailBody = getReviewReqEmailBody(name, taskName); | ||
const recipients = await getRecipients(myUserId); | ||
|
||
try { | ||
emailSender( | ||
recipients, | ||
`Review Request from ${name}`, | ||
emailBody, | ||
'[email protected]', | ||
null, | ||
); | ||
res.status(200).send('Success'); | ||
} catch (err) { | ||
res.status(500).send('Failed'); | ||
} | ||
}; | ||
|
||
return { | ||
postTask, | ||
getTasks, | ||
|
@@ -864,6 +919,8 @@ const taskController = function (Task) { | |
moveTask, | ||
getTasksByUserList, | ||
getTasksForTeamsByUser, | ||
updateTaskStatus, | ||
sendReviewReq, | ||
}; | ||
}; | ||
|
||
|
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