Skip to content

Commit

Permalink
Merge pull request #795 from OneCommunityGlobal/shengwei_add_stop_blu…
Browse files Browse the repository at this point in the history
…e_sqaure_added_to_new_user

Shengwei add stop blue sqaure added to new user
  • Loading branch information
one-community authored Apr 26, 2024
2 parents f9cdcaa + d115203 commit 3eabd49
Show file tree
Hide file tree
Showing 18 changed files with 939 additions and 386 deletions.
240 changes: 147 additions & 93 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
"node-datetime": "^2.0.3",
"nodemailer": "^6.4.16",
"redis": "^4.2.0",
"sanitize-html": "^2.13.0",
"supertest": "^6.3.4",
"uuid": "^3.4.0",
"ws": "^8.8.1"
},
Expand Down
17 changes: 11 additions & 6 deletions src/constants/eventTypes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
const eventtypes = {
ActionCreated: 'Action Created',
ActionEdited: 'Action Edited',
ActionDeleted: 'Action Deleted',
};
/**
* Unused legacy code. Commented out to avoid confusion.
* Commented by: Shengwei Peng
* Date: 2024-03-22
*/
// const eventtypes = {
// ActionCreated: 'Action Created',
// ActionEdited: 'Action Edited',
// ActionDeleted: 'Action Deleted',
// };

module.exports = eventtypes;
// module.exports = eventtypes;
18 changes: 18 additions & 0 deletions src/constants/message.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export const URL_TO_BLUE_SQUARE_PAGE = 'https://www.onecommunityglobal.org/hands-off-administration-policy'

// Since the notification banner is blue background, added white color for hyperlink style.
export const NEW_USER_BLUE_SQUARE_NOTIFICATION_MESSAGE = `
<p> Welcome as one of our newest members to the One Community team and family!
Heads up we’ve removed a <a href=${URL_TO_BLUE_SQUARE_PAGE}>“blue square”</a> that
was issued due to not completing your hours and/or summary this past week. The reason we removed
this blue square is because you didn’t have the full week available to complete your volunteer
time with us. </p>
<p> If you’d like to learn more about this policy and/or blue squares, click here:
<a href=${URL_TO_BLUE_SQUARE_PAGE}> “Blue Square FAQ”</a>
</p>
<p>Welcome again, we’re glad to have you joining us! </p>
<p>With Gratitude,</br>One Community </p>
`;
254 changes: 128 additions & 126 deletions src/controllers/actionItemController.js
Original file line number Diff line number Diff line change
@@ -1,126 +1,128 @@
const mongoose = require('mongoose');
const closure = require('../helpers/notificationhelper');

const actionItemController = function (ActionItem) {
const notificationhelper = closure();

const getactionItem = async function (req, res) {
const userid = req.params.userId;

try {
const actionItems = await ActionItem.find(
{
assignedTo: userid,
},
'-createdDateTime -__v',
).populate('createdBy', 'firstName lastName');
const actionitems = [];

actionItems.forEach((element) => {
const actionitem = {};

actionitem._id = element._id;
actionitem.description = element.description;
actionitem.createdBy = `${element.createdBy.firstName} ${element.createdBy.lastName}`;
actionitem.assignedTo = element.assignedTo;

actionitems.push(actionitem);
});

res.status(200).send(actionitems);
} catch (error) {
res.status(400).send(error);
}
};
const postactionItem = async function (req, res) {
const { requestorId, assignedTo } = req.body.requestor;
const _actionItem = new ActionItem();

_actionItem.description = req.body.description;
_actionItem.assignedTo = req.body.assignedTo;
_actionItem.createdBy = req.body.requestor.requestorId;

try {
const savedItem = await _actionItem.save();
notificationhelper.notificationcreated(requestorId, assignedTo, _actionItem.description);

const actionitem = {};

actionitem.createdBy = 'You';
actionitem.description = _actionItem.description;
actionitem._id = savedItem._id;
actionitem.assignedTo = _actionItem.assignedTo;

res.status(200).send(actionitem);
} catch (err) {
res.status(400).send(err);
}
};

const deleteactionItem = async function (req, res) {
const actionItemId = mongoose.Types.ObjectId(req.params.actionItemId);

try {
const _actionItem = await ActionItem.findById(actionItemId);

if (!_actionItem) {
res.status(400).send({
message: 'No valid records found',
});
return;
}

const { requestorId, assignedTo } = req.body.requestor;

notificationhelper.notificationdeleted(requestorId, assignedTo, _actionItem.description);

await _actionItem.remove();
res.status(200).send({
message: 'removed',
});
} catch (error) {
res.status(400).send(error);
}
};

const editactionItem = async function (req, res) {
const actionItemId = mongoose.Types.ObjectId(req.params.actionItemId);

const { requestorId, assignedTo } = req.body.requestor;

try {
const _actionItem = await ActionItem.findById(actionItemId);

if (!_actionItem) {
res.status(400).send({
message: 'No valid records found',
});
return;
}

notificationhelper.notificationedited(
requestorId,
assignedTo,
_actionItem.description,
req.body.description,
);

_actionItem.description = req.body.description;
_actionItem.assignedTo = req.body.assignedTo;

await _actionItem.save();
res.status(200).send({ message: 'Saved' });
} catch (error) {
res.status(400).send(error);
}
};

return {
getactionItem,
postactionItem,
deleteactionItem,
editactionItem,
};
};

module.exports = actionItemController;
/**
* Unused legacy code. Commented out to avoid confusion. Will delete in the next cycle.
* Commented by: Shengwei Peng
* Date: 2024-03-22
*/

// const mongoose = require('mongoose');
// const notificationhelper = require('../helpers/notificationhelper')();

// const actionItemController = function (ActionItem) {
// const getactionItem = function (req, res) {
// const userid = req.params.userId;
// ActionItem.find({
// assignedTo: userid,
// }, ('-createdDateTime -__v'))
// .populate('createdBy', 'firstName lastName')
// .then((results) => {
// const actionitems = [];

// results.forEach((element) => {
// const actionitem = {};

// actionitem._id = element._id;
// actionitem.description = element.description;
// actionitem.createdBy = `${element.createdBy.firstName} ${element.createdBy.lastName}`;
// actionitem.assignedTo = element.assignedTo;

// actionitems.push(actionitem);
// });

// res.status(200).send(actionitems);
// })
// .catch((error) => {
// res.status(400).send(error);
// });
// };
// const postactionItem = function (req, res) {
// const { requestorId, assignedTo } = req.body.requestor;
// const _actionItem = new ActionItem();

// _actionItem.description = req.body.description;
// _actionItem.assignedTo = req.body.assignedTo;
// _actionItem.createdBy = req.body.requestor.requestorId;

// _actionItem.save()
// .then((result) => {
// notificationhelper.notificationcreated(requestorId, assignedTo, _actionItem.description);

// const actionitem = {};

// actionitem.createdBy = 'You';
// actionitem.description = _actionItem.description;
// actionitem._id = result._id;
// actionitem.assignedTo = _actionItem.assignedTo;

// res.status(200).send(actionitem);
// })
// .catch((error) => {
// res.status(400).send(error);
// });
// };

// const deleteactionItem = async function (req, res) {
// const actionItemId = mongoose.Types.ObjectId(req.params.actionItemId);

// const _actionItem = await ActionItem.findById(actionItemId)
// .catch((error) => {
// res.status(400).send(error);
// });

// if (!_actionItem) {
// res.status(400).send({
// message: 'No valid records found',
// });
// return;
// }

// const { requestorId, assignedTo } = req.body.requestor;

// notificationhelper.notificationdeleted(requestorId, assignedTo, _actionItem.description);

// _actionItem.remove()
// .then(() => {
// res.status(200).send({
// message: 'removed',
// });
// })
// .catch((error) => {
// res.status(400).send(error);
// });
// };

// const editactionItem = async function (req, res) {
// const actionItemId = mongoose.Types.ObjectId(req.params.actionItemId);

// const { requestorId, assignedTo } = req.body.requestor;

// const _actionItem = await ActionItem.findById(actionItemId)
// .catch((error) => {
// res.status(400).send(error);
// });

// if (!_actionItem) {
// res.status(400).send({
// message: 'No valid records found',
// });
// return;
// }
// notificationhelper.notificationedited(requestorId, assignedTo, _actionItem.description, req.body.description);

// _actionItem.description = req.body.description;
// _actionItem.assignedTo = req.body.assignedTo;

// _actionItem.save()
// .then(res.status(200).send('Saved'))
// .catch((error) => res.status(400).send(error));
// };

// return {
// getactionItem,
// postactionItem,
// deleteactionItem,
// editactionItem,

// };
// };

// module.exports = actionItemController;
Loading

0 comments on commit 3eabd49

Please sign in to comment.