Skip to content

Commit

Permalink
Merge pull request #1130 from SFA23SCM35V/vorugantisaivenkatesh--Impr…
Browse files Browse the repository at this point in the history
…ove-speed-and-function-of-deleting-multiple-blue-squares

 Sai Venkatesh- Backend - Improve speed and function of deleting multiple blue squares
  • Loading branch information
one-community authored Dec 17, 2024
2 parents fb1b5ab + f4e8827 commit 424ca84
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 155 deletions.
251 changes: 123 additions & 128 deletions src/controllers/actionItemController.js
Original file line number Diff line number Diff line change
@@ -1,128 +1,123 @@
/**
* 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;
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;
29 changes: 2 additions & 27 deletions src/controllers/userProfileController.js
Original file line number Diff line number Diff line change
Expand Up @@ -1493,26 +1493,7 @@ const userProfileController = function (UserProfile, Project) {
res.status(200).send({ refreshToken: currentRefreshToken });
};

// Search for user by first name
// const getUserBySingleName = (req, res) => {
// const pattern = new RegExp(`^${ req.params.singleName}`, 'i');

// // Searches for first or last name
// UserProfile.find({
// $or: [
// { firstName: { $regex: pattern } },
// { lastName: { $regex: pattern } },
// ],
// })
// .select('firstName lastName')
// .then((users) => {
// if (users.length === 0) {
// return res.status(404).send({ error: 'Users Not Found' });
// }
// res.status(200).send(users);
// })
// .catch((error) => res.status(500).send(error));
// };


const getUserBySingleName = (req, res) => {
const pattern = new RegExp(`^${req.params.singleName}`, 'i');
Expand Down Expand Up @@ -1557,13 +1538,7 @@ const userProfileController = function (UserProfile, Project) {
.catch((error) => res.status(500).send(error));
};

// function escapeRegExp(string) {
// return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
// }
/**
* Authorizes user to be able to add Weekly Report Recipients
*
*/

const authorizeUser = async (req, res) => {
try {
let authorizedUser;
Expand Down

0 comments on commit 424ca84

Please sign in to comment.