Skip to content
Merged
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ workflows:
context : org-global
filters:
branches:
only: ['develop', 'migration-setup', 'pm-1169']
only: ['develop', 'migration-setup', 'pm-1169_1']
Copy link

Choose a reason for hiding this comment

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

The branch name has been changed from 'pm-1169' to 'pm-1169_1'. Ensure that this change is intentional and that all relevant documentation and references to the branch name are updated accordingly.

- deployProd:
context : org-global
filters:
Expand Down
63 changes: 63 additions & 0 deletions src/routes/projectMemberInvites/update.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import validate from 'express-validation';
import _ from 'lodash';
import Joi from 'joi';
import { Op } from 'sequelize';
import { middleware as tcMiddleware } from 'tc-core-library-js';
import models from '../../models';
import util from '../../util';
import { INVITE_STATUS, EVENT, RESOURCES, COPILOT_APPLICATION_STATUS, COPILOT_OPPORTUNITY_STATUS, COPILOT_REQUEST_STATUS, INVITE_SOURCE } from '../../constants';
import { PERMISSION } from '../../permissions/constants';


/**
* API to update invite member to project.
*
Expand Down Expand Up @@ -170,6 +172,67 @@ module.exports = [
}, {
transaction: t,
});
} else if (source === INVITE_SOURCE.WORK_MANAGER) {
req.log.info("cancelling all existing requests", source);
Copy link

Choose a reason for hiding this comment

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

Consider providing more context in the log message to make it clear what specific action is being taken. For example, include the project ID or other relevant identifiers to help with debugging.

const allCopilotRequestsByProjectId = await models.CopilotRequest.findAll({
where: {
projectId: invite.projectId,
},
transaction: t,
});

const requestIds = allCopilotRequestsByProjectId.map(item => item.id);
req.log.info("requestIds", requestIds);
Copy link

Choose a reason for hiding this comment

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

Consider removing or adjusting the log statement before merging. Logging sensitive information or excessive data can lead to performance issues or security concerns. If logging is necessary, ensure it is appropriately handled and does not expose sensitive information.


await models.CopilotRequest.update({
status: COPILOT_REQUEST_STATUS.CANCELED,
}, {
where: {
id: {
[Op.in]: requestIds,
}
},
transaction: t,
});

req.log.info("updated copilot request");

const allCopilotOpportunityByRequestIds = await models.CopilotOpportunity.findAll({
where: {
copilotRequestId: {
[Op.in]: requestIds,
},
},
transaction: t,
});

req.log.info("allCopilotOpportunityByRequestIds", allCopilotOpportunityByRequestIds.length);
Copy link

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 log message to provide context about the operation being logged. For example, include information about what the length represents or the significance of this log entry.


await models.CopilotOpportunity.update({
status: COPILOT_OPPORTUNITY_STATUS.CANCELED,
}, {
where: {
id: {
[Op.in]: allCopilotOpportunityByRequestIds.map(item => item.id),
Copy link

Choose a reason for hiding this comment

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

The change from copilotRequestId to id suggests that allCopilotOpportunityByRequestIds is now an array of objects rather than an array of IDs. Ensure that allCopilotOpportunityByRequestIds is correctly populated with objects containing an id property before this line is executed.

},
},
transaction: t,
});

req.log.info("updated copilot opportunity");

await models.CopilotApplication.update({
status: COPILOT_APPLICATION_STATUS.CANCELED,
}, {
where: {
opportunityId: {
[Op.in]: allCopilotOpportunityByRequestIds.map(item => item.id),
},
},
transaction: t,
});

req.log.info("updated CopilotApplication");
Copy link

Choose a reason for hiding this comment

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

Consider providing more context in the log message to make it clear what specific changes were made to the CopilotApplication. This can help in debugging and understanding the flow of the application.

}

await t.commit();
Expand Down