Skip to content

[PROD] - Copilot Portal fixes and updates #838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 118 commits into
base: master
Choose a base branch
from
Open

[PROD] - Copilot Portal fixes and updates #838

wants to merge 118 commits into from

Conversation

kkartunov
Copy link
Contributor

hentrymartin and others added 30 commits July 9, 2025 22:05
fix(PM-1468): make notes mandatory
fix(PM-1368, PM-1394): group by active and then sort by createdAt
…unity-title

PM-1498 - support for opportunity title
fix(PM-1494): Add extra info for copilot email
@@ -45,11 +49,17 @@ module.exports = [
throw err;
}

const copilotRequest = await models.CopilotRequest.findOne({

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider handling the case where copilotRequest might be null or undefined after the findOne query. This could prevent potential runtime errors if the expected data is not found.

where: { id: opportunity.copilotRequestId },
transaction: t,
});

const application = await models.CopilotApplication.findOne({

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that the application object is properly validated before proceeding with operations that depend on its properties. This will help avoid errors if the findOne query does not return the expected result.

});

req.log.debug(`All updations done`);
transaction.commit();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using await transaction.commit() to ensure the transaction is properly awaited and any potential errors are caught.

transaction,
});

req.log.debug(`Updating other applications: ${JSON.stringify(copilotRequest)}`);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The debug log message here is misleading. It mentions updating 'other applications' but logs the copilotRequest object. Consider updating the log message to accurately reflect the action being performed.

$ne: application.id,
},
}
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a transaction option to the CopilotApplication.update call to ensure it is part of the same transaction as the other updates.

req.log.debug(`Email sent`);
};

const existingMember = activeMembers.find(item => item.userId === userId);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable existingMember is used here, but it is essentially the same as existingUser from the removed code. Ensure that the logic for finding the existing member is correct and consistent with the previous implementation.

where: {
id: opportunityId,
}
}).then((opportunity) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a timeout or handling for the promise returned by models.CopilotOpportunity.findOne to prevent potential hanging if the database query takes too long.

}
}).then((opportunity) => {
if (!opportunity) {
const err = new Error('No opportunity found');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message 'No opportunity found' could be more descriptive by including the opportunityId to help with debugging.

})
.then(copilotApplications => {
req.log.debug(`CopilotApplications ${JSON.stringify(copilotApplications)}`);
return models.ProjectMember.getActiveProjectMembers(opportunity.projectId).then((members) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding error handling for the promise returned by models.ProjectMember.getActiveProjectMembers to ensure that any issues fetching project members are properly managed.

req.log.debug(`Fetched existing active members ${JSON.stringify(members)}`);
req.log.debug(`Applications ${JSON.stringify(copilotApplications)}`);
const enrichedApplications = copilotApplications.map(application => {
const m = members.find(m => m.userId === application.userId);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable m could be renamed to something more descriptive, such as member, to improve code readability.

return enriched;
});

req.log.debug(`Enriched Applications ${JSON.stringify(enrichedApplications)}`);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using res.json(enrichedApplications) instead of res.status(200).send(enrichedApplications) for consistency with the previous implementation and to automatically set the correct content-type header.

req.log.debug(`Sent email to ${member.email}`);
});
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removal of _transaction.commit() may lead to uncommitted changes in the database. Ensure that the transaction is being committed elsewhere or that this removal is intentional and safe.

projectMember = projectMember.get({ plain: true });
projectMember = _.omit(projectMember, ['deletedAt']);

if (['observer', 'customer'].includes(previousValue.role) && ['copilot', 'manager'].includes(updatedProps.role)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition has been changed from checking updatedProps.role to previousValue.role. Ensure that this change aligns with the intended logic and that previousValue.role is correctly defined and used in this context.

projectMember = projectMember.get({ plain: true });
projectMember = _.omit(projectMember, ['deletedAt']);

if (['observer', 'customer'].includes(previousValue.role) && ['copilot', 'manager'].includes(updatedProps.role)) {
await completeAllCopilotRequests(req, projectId, _transaction, projectMember);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable _member has been replaced with projectMember. Verify that projectMember is the correct variable to use in this function call and that it contains the necessary data.

@@ -149,7 +149,7 @@ workflows:
context : org-global
filters:
branches:
only: ['develop', 'migration-setup', 'pm-1378']
only: ['develop', 'migration-setup', 'PM-1314']

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The branch name 'PM-1314' should be verified to ensure it is correct and intended for production deployment. If this is a typo or incorrect branch, it may lead to unintended deployments.

@@ -21,6 +21,25 @@ module.exports = [
const pageSize = parseInt(req.query.pageSize, 10) || DEFAULT_PAGE_SIZE;
const offset = (page - 1) * pageSize;
const limit = pageSize;
const noGroupingByStatus = req.query.noGrouping === 'true';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a more descriptive variable name than noGroupingByStatus to improve code readability. For example, disableStatusGrouping might better convey the purpose of the variable.

'ASC',
]);
}
baseOrder.push([sortParams[0], sortParams[1]]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure sortParams is validated before being used in baseOrder.push([sortParams[0], sortParams[1]]); to prevent potential runtime errors if sortParams is not an array or does not contain the expected elements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants