Skip to content

Commit

Permalink
Merge pull request #723 from OneCommunityGlobal/development
Browse files Browse the repository at this point in the history
Backend Release to Main [1.38]
  • Loading branch information
one-community authored Jan 26, 2024
2 parents 9825974 + 6886d40 commit 1e2de28
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 74 deletions.
File renamed without changes.
12 changes: 7 additions & 5 deletions src/controllers/bmdashboard/bmInventoryTypeController.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const fs = require('fs');

const filepath = 'src/controllers/bmdashboard/BuildingUnits.json';
const path = require('path');
const filepath = 'BuildingUnits.json';
const readFile = fs.readFile;
const writeFile = fs.writeFile;

function bmInventoryTypeController(InvType, MatType, ConsType, ReusType, ToolType, EquipType) {
async function fetchMaterialTypes(req, res) {
Expand All @@ -17,7 +19,7 @@ function bmInventoryTypeController(InvType, MatType, ConsType, ReusType, ToolTyp

const fetchInvUnitsFromJson = async (req, res) => {
try {
fs.readFile(filepath, 'utf8', (err, data) => {
readFile(filepath, 'utf8', (err, data) => {
if (err) {
console.error('Error reading file:', err);
return;
Expand Down Expand Up @@ -67,7 +69,7 @@ function bmInventoryTypeController(InvType, MatType, ConsType, ReusType, ToolTyp
// Add new unit to json file : src\controllers\bmdashboard\BuildingUnits.json
const newItem = { unit: req.body.customUnit, category: 'Material' };
const newItemString = JSON.stringify(newItem, null, 2);
fs.readFile(filepath, 'utf8', (err, data) => {
readFile(filepath, 'utf8', (err, data) => {
if (err) {
console.error('Error reading file:', err);
return;
Expand All @@ -79,7 +81,7 @@ function bmInventoryTypeController(InvType, MatType, ConsType, ReusType, ToolTyp
const separator = (updatedContent !== '') ? ',\n' : '';
const updatedFileContent = `${updatedContent}${separator}${newItemString}\n]`;

fs.writeFile(filepath, updatedFileContent, 'utf8', (error) => {
writeFile(filepath, updatedFileContent, 'utf8', (error) => {
if (error) {
console.error('Error writing to file:', error);
return;
Expand Down
4 changes: 0 additions & 4 deletions src/controllers/taskController.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const mongoose = require('mongoose');
const WBS = require('../models/wbs');
const UserProfile = require('../models/userProfile');
const timeEntryHelper = require('../helpers/timeEntryHelper')();
const taskHelper = require('../helpers/taskHelper')();
const { hasPermission } = require('../utilities/permissions');
const emailSender = require('../utilities/emailSender');
Expand Down Expand Up @@ -803,9 +802,6 @@ const taskController = function (Task) {
return res.status(400).send({ error: 'This is not a valid task' });
}

const hoursLogged = await timeEntryHelper.getAllHoursLoggedForSpecifiedTask(taskId);
task.set('hoursLogged', hoursLogged, { strict: false });

// Fetch the resource names for all resources
const resourceNamesPromises = task.resources.map(resource => taskHelper.getUserProfileFirstAndLastName(resource.userID));
const resourceNames = await Promise.all(resourceNamesPromises);
Expand Down
75 changes: 37 additions & 38 deletions src/helpers/taskHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,50 +60,54 @@ const taskHelper = function () {
);
break;
}
case !isRequestorOwnerLike && !isUserOwnerLike: {
const sharedTeamsResult = await team.find({ $or: [{ 'members.userId': { $all: [userid, requestorId] } }, { 'members.userId': userid }] }, { members: 1 });
case isRequestorOwnerLike && !isUserOwnerLike: {
const teamsResult = await team.find(
{ 'members.userId': { $in: [userid] } },
{ members: 1 },
);

sharedTeamsResult.forEach((_myTeam) => {
teamsResult.forEach((_myTeam) => {
_myTeam.members.forEach((teamMember) => {
if (!teamMember.userId.equals(userid)) teamMemberIds.push(teamMember.userId);
});
});

teamMembers = await userProfile
.find(
{ _id: { $in: teamMemberIds }, isActive: true },
{
role: 1,
firstName: 1,
lastName: 1,
weeklycommittedHours: 1,
timeOffFrom: 1,
timeOffTill: 1,
},
);
break;
teamMembers = await userProfile.find(
{ _id: { $in: teamMemberIds }, isActive: true },
{
role: 1,
firstName: 1,
lastName: 1,
weeklycommittedHours: 1,
timeOffFrom: 1,
timeOffTill: 1,
},
);
break;
}
default: {
const teamsResult = await team.find({ 'members.userId': { $in: [userid] } }, { members: 1 });
const sharedTeamsResult = await team.find(
{ 'members.userId': { $all: [userid, requestorId] } },
{ members: 1 },
);

teamsResult.forEach((_myTeam) => {
sharedTeamsResult.forEach((_myTeam) => {
_myTeam.members.forEach((teamMember) => {
if (!teamMember.userId.equals(userid)) teamMemberIds.push(teamMember.userId);
});
});

teamMembers = await userProfile
.find(
{ _id: { $in: teamMemberIds }, isActive: true },
{
role: 1,
firstName: 1,
lastName: 1,
weeklycommittedHours: 1,
timeOffFrom: 1,
timeOffTill: 1,
},
);
teamMembers = await userProfile.find(
{ _id: { $in: teamMemberIds }, isActive: true },
{
role: 1,
firstName: 1,
lastName: 1,
weeklycommittedHours: 1,
timeOffFrom: 1,
timeOffTill: 1,
},
);
}
}

Expand Down Expand Up @@ -133,12 +137,8 @@ const taskHelper = function () {
timeEntryByPerson[personIdStr].totalSeconds += timeEntry.totalSeconds;
});
const teamMemberTasks = await Task.find(
{
'resources.userID': { $in: teamMemberIds },
},
{
'resources.profilePic': 0,
},
{ 'resources.userID': { $in: teamMemberIds } },
{ 'resources.profilePic': 0 },
).populate({
path: 'wbsId',
select: 'projectId',
Expand All @@ -163,8 +163,7 @@ const taskHelper = function () {
}
});

const taskByPerson = [];

const taskByPerson = {};
teamMemberTasks.forEach((teamMemberTask) => {
const projId = teamMemberTask.wbsId?.projectId;
const _teamMemberTask = { ...teamMemberTask._doc };
Expand Down
27 changes: 0 additions & 27 deletions src/helpers/timeEntryHelper.js

This file was deleted.

0 comments on commit 1e2de28

Please sign in to comment.