Skip to content

Commit

Permalink
Merge pull request #829 from OneCommunityGlobal/Ivy-Blue-Email-BE
Browse files Browse the repository at this point in the history
Ivy-blue-email-add-administrative-details
  • Loading branch information
one-community authored May 1, 2024
2 parents 170562c + fcfbc08 commit c452af7
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 53 deletions.
4 changes: 1 addition & 3 deletions src/controllers/timeEntryController.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ const checkIsUserFirstTimeEntry = async (personId) => {

const canEdit = isSameDayAuthUserEdit || isRequestorAdminLikeRole || hasEditTimeEntryPermission;


if (!canEdit) {
const error = 'Unauthorized request';
return res.status(403).send({ error });
Expand Down Expand Up @@ -623,7 +624,6 @@ const checkIsUserFirstTimeEntry = async (personId) => {
const tangibilityChanged = initialIsTangible !== newIsTangible;
const timeChanged = initialTotalSeconds !== newTotalSeconds;
const dateOfWorkChanged = initialDateOfWork !== newDateOfWork;

timeEntry.notes = newNotes;
timeEntry.totalSeconds = newTotalSeconds;
timeEntry.isTangible = newIsTangible;
Expand All @@ -641,7 +641,6 @@ const checkIsUserFirstTimeEntry = async (personId) => {
// tangiblity change usually only happens by itself via tangibility checkbox,
// and it can't be changed by user directly (except for owner-like roles)
// but here the other changes are also considered here for completeness

// change from tangible to intangible
if (initialIsTangible) {
// subtract initial logged hours from old task (if not null)
Expand Down Expand Up @@ -792,7 +791,6 @@ const checkIsUserFirstTimeEntry = async (personId) => {
res.status(400).send({ message: 'No valid record found' });
return;
}

const { personId, totalSeconds, dateOfWork, projectId, taskId, isTangible } = timeEntry;

const isForAuthUser = personId.toString() === req.body.requestor.requestorId;
Expand Down
38 changes: 18 additions & 20 deletions src/controllers/userProfileController.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const userProfileController = function (UserProfile) {
cache.setCache('allusers', JSON.stringify(results));
res.status(200).send(results);
})
.catch(error => res.status(404).send(error));
.catch((error) => res.status(404).send(error));
};

const getProjectMembers = async function (req, res) {
Expand Down Expand Up @@ -329,7 +329,6 @@ const userProfileController = function (UserProfile) {
};

const putUserProfile = async function (req, res) {

const userid = req.params.userId;
const isRequestorAuthorized = !!(
canRequestorUpdateUser(req.body.requestor.requestorId, userid) &&
Expand Down Expand Up @@ -422,7 +421,7 @@ const userProfileController = function (UserProfile) {
let userIdx;
if (isUserInCache) {
allUserData = JSON.parse(cache.getCache('allusers'));
userIdx = allUserData.findIndex(users => users._id === userid);
userIdx = allUserData.findIndex((users) => users._id === userid);
userData = allUserData[userIdx];
}
if (await hasPermission(req.body.requestor, 'putUserProfileImportantInfo')) {
Expand Down Expand Up @@ -499,10 +498,7 @@ const userProfileController = function (UserProfile) {
record.weeklycommittedHoursHistory.push(newEntry);
}

if (
req.body.startDate !== undefined
&& record.startDate !== req.body.startDate
) {
if (req.body.startDate !== undefined && record.startDate !== req.body.startDate) {
record.startDate = moment(req.body.startDate).toDate();
// Make sure weeklycommittedHoursHistory isn't empty
if (record.weeklycommittedHoursHistory.length === 0) {
Expand Down Expand Up @@ -558,6 +554,8 @@ const userProfileController = function (UserProfile) {
results.firstName,
results.lastName,
results.email,
results.role,
results.startDate,
);
res.status(200).json({
_id: record._id,
Expand All @@ -569,7 +567,7 @@ const userProfileController = function (UserProfile) {
cache.setCache('allusers', JSON.stringify(allUserData));
}
})
.catch(error => res.status(400).send(error));
.catch((error) => res.status(400).send(error));
});
};

Expand Down Expand Up @@ -710,7 +708,7 @@ const userProfileController = function (UserProfile) {
res.status(200).send(results);
});
})
.catch(error => res.status(404).send(error));
.catch((error) => res.status(404).send(error));
};

const getUserByName = (req, res) => {
Expand All @@ -723,7 +721,7 @@ const userProfileController = function (UserProfile) {
.then((results) => {
res.status(200).send(results);
})
.catch(error => res.status(404).send(error));
.catch((error) => res.status(404).send(error));
};

const updateOneProperty = function (req, res) {
Expand Down Expand Up @@ -759,9 +757,9 @@ const userProfileController = function (UserProfile) {
.then(() => {
res.status(200).send({ message: 'updated property' });
})
.catch(error => res.status(500).send(error));
.catch((error) => res.status(500).send(error));
})
.catch(error => res.status(500).send(error));
.catch((error) => res.status(500).send(error));
};

const updatepassword = async function (req, res) {
Expand Down Expand Up @@ -821,11 +819,11 @@ const userProfileController = function (UserProfile) {
return user
.save()
.then(() => res.status(200).send({ message: 'updated password' }))
.catch(error => res.status(500).send(error));
.catch((error) => res.status(500).send(error));
})
.catch(error => res.status(500).send(error));
.catch((error) => res.status(500).send(error));
})
.catch(error => res.status(500).send(error));
.catch((error) => res.status(500).send(error));
};

const getreportees = async function (req, res) {
Expand Down Expand Up @@ -857,7 +855,7 @@ const userProfileController = function (UserProfile) {
});
res.status(200).send(teammembers);
})
.catch(error => res.status(400).send(error));
.catch((error) => res.status(400).send(error));
};

const getTeamMembersofUser = function (req, res) {
Expand All @@ -874,7 +872,7 @@ const userProfileController = function (UserProfile) {
.then((results) => {
res.status(200).send(results);
})
.catch(error => res.status(400).send(error));
.catch((error) => res.status(400).send(error));
};

const getUserName = function (req, res) {
Expand Down Expand Up @@ -1126,7 +1124,7 @@ const userProfileController = function (UserProfile) {
}
res.status(200).send(users);
})
.catch(error => res.status(500).send(error));
.catch((error) => res.status(500).send(error));
};

function escapeRegExp(string) {
Expand Down Expand Up @@ -1158,7 +1156,7 @@ const userProfileController = function (UserProfile) {
}
res.status(200).send(users);
})
.catch(error => res.status(500).send(error));
.catch((error) => res.status(500).send(error));
};

/**
Expand Down Expand Up @@ -1225,4 +1223,4 @@ const userProfileController = function (UserProfile) {
};
};

module.exports = userProfileController;
module.exports = userProfileController;
Loading

0 comments on commit c452af7

Please sign in to comment.