Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-1612', 'fix-project-exposing']
only: ['develop', 'migration-setup', 'PM-1612', 'PM-2321']
- deployProd:
context : org-global
filters:
Expand Down
31 changes: 22 additions & 9 deletions src/routes/copilotRequest/approveRequest.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import moment from 'moment';
import { Op } from 'sequelize';

import models from '../../models';
import { CONNECT_NOTIFICATION_EVENT, COPILOT_OPPORTUNITY_STATUS, COPILOT_REQUEST_STATUS, TEMPLATE_IDS, USER_ROLE } from '../../constants';
import {
CONNECT_NOTIFICATION_EVENT,
COPILOT_OPPORTUNITY_STATUS,
COPILOT_REQUEST_STATUS,
TEMPLATE_IDS, USER_ROLE } from '../../constants';
Copy link

Choose a reason for hiding this comment

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

Consider formatting the import statement so that each constant is on a separate line for better readability, like the other constants in this block.

import util from '../../util';
import { createEvent } from '../../services/busApi';
import { getCopilotTypeLabel } from '../../utils/copilot';
Expand Down Expand Up @@ -47,7 +51,7 @@ module.exports = (req, data, existingTransaction) => {
type: data.type,
status: {
[Op.in]: [COPILOT_OPPORTUNITY_STATUS.ACTIVE],
}
},
},
})
.then((existingCopilotOpportunityOfSameType) => {
Expand All @@ -62,11 +66,15 @@ module.exports = (req, data, existingTransaction) => {
.create(data, { transaction });
}))
.then(async (opportunity) => {
// eslint-disable-next-line no-console
console.time('getRolesByRoleName');
Copy link

Choose a reason for hiding this comment

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

Using console.time for performance measurement in production code is not recommended. Consider using a more robust logging or monitoring solution.

const roles = await util.getRolesByRoleName(USER_ROLE.TC_COPILOT, req.log, req.id);
// eslint-disable-next-line no-console
console.timeEnd('getRolesByRoleName');
Copy link

Choose a reason for hiding this comment

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

Using console.timeEnd for performance measurement in production code is not recommended. Consider using a more robust logging or monitoring solution.

const { subjects = [] } = await util.getRoleInfo(roles[0], req.log, req.id);
Copy link

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 await util.getRoleInfo(roles[0], req.log, req.id); call to manage potential promise rejections.

const emailEventType = CONNECT_NOTIFICATION_EVENT.EXTERNAL_ACTION_EMAIL;
const copilotPortalUrl = config.get('copilotPortalUrl');
req.log.info("Sending emails to all copilots about new opportunity");
req.log.info('Sending emails to all copilots about new opportunity');

const sendNotification = (userName, recipient) => createEvent(emailEventType, {
data: {
Expand All @@ -75,20 +83,25 @@ module.exports = (req, data, existingTransaction) => {
work_manager_url: config.get('workManagerUrl'),
opportunity_type: getCopilotTypeLabel(type),
opportunity_title: opportunityTitle,
start_date: moment(startDate).format("DD-MM-YYYY"),
start_date: moment(startDate).format('DD-MM-YYYY'),
},
sendgrid_template_id: TEMPLATE_IDS.CREATE_REQUEST,
recipients: [recipient],
version: 'v3',
}, req.log);

subjects.forEach(subject => sendNotification(subject.handle, subject.email));
const notificationPromises = subjects.map(subject =>
sendNotification(subject.handle, subject.email),
);

notificationPromises.push(
sendNotification('Copilots', config.copilotsSlackEmail),
);

await Promise.all(notificationPromises);

// send email to notify via slack
sendNotification('Copilots', config.copilotsSlackEmail);
req.log.info('Finished sending emails to copilots');

req.log.info("Finished sending emails to copilots");

return opportunity;
})
.catch((err) => {
Expand Down
8 changes: 4 additions & 4 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -820,10 +820,10 @@ const projectServiceUtils = {
const token = yield this.getM2MToken();
const httpClient = this.getHttpClient({ id: requestId, log: logger });
httpClient.defaults.timeout = 6000;
logger.debug(`${config.identityServiceEndpoint}roles/${roleId}`, "fetching role info");
logger.debug(`${config.identityServiceEndpoint}roles/${roleId}`, 'fetching role info');
return httpClient.get(`${config.identityServiceEndpoint}roles/${roleId}`, {
params: {
fields: `subjects`,
fields: 'subjects',
},
headers: {
'Content-Type': 'application/json',
Expand All @@ -834,7 +834,7 @@ const projectServiceUtils = {
return _.get(res, 'data.result.content', []);
});
} catch (err) {
logger.debug(err, "error on getting role info");
logger.debug(err, 'error on getting role info');
return Promise.reject(err);
}
}),
Expand All @@ -843,7 +843,7 @@ const projectServiceUtils = {
try {
const token = yield this.getM2MToken();
const httpClient = this.getHttpClient({ id: requestId, log: logger });
httpClient.defaults.timeout = 6000;
httpClient.defaults.timeout = 10000;
return httpClient.get(`${config.identityServiceEndpoint}roles`, {
params: {
filter: `roleName=${roleName}`,
Expand Down