diff --git a/.circleci/config.yml b/.circleci/config.yml index e2ac728e..5465d0c2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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: diff --git a/config/development.json b/config/development.json index 878bc669..5b8eb136 100644 --- a/config/development.json +++ b/config/development.json @@ -6,7 +6,7 @@ "copilotPortalUrl": "https://copilots.topcoder-dev.com", "fileServiceEndpoint": "https://api.topcoder-dev.com/v5/files", "memberServiceEndpoint": "https://api.topcoder-dev.com/v5/members", - "identityServiceEndpoint": "https://api.topcoder-dev.com/v3/", + "identityServiceEndpoint": "https://api.topcoder-dev.com/v6/", "taasJobApiUrl": "https://api.topcoder-dev.com/v5/jobs", "sfdcBillingAccountNameField": "Billing_Account_name__c", "sfdcBillingAccountMarkupField": "Mark_Up__c", diff --git a/src/routes/copilotRequest/approveRequest.service.js b/src/routes/copilotRequest/approveRequest.service.js index 5ef4d2c1..773b01ca 100644 --- a/src/routes/copilotRequest/approveRequest.service.js +++ b/src/routes/copilotRequest/approveRequest.service.js @@ -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'; import util from '../../util'; import { createEvent } from '../../services/busApi'; import { getCopilotTypeLabel } from '../../utils/copilot'; @@ -47,7 +51,7 @@ module.exports = (req, data, existingTransaction) => { type: data.type, status: { [Op.in]: [COPILOT_OPPORTUNITY_STATUS.ACTIVE], - } + }, }, }) .then((existingCopilotOpportunityOfSameType) => { @@ -62,11 +66,15 @@ module.exports = (req, data, existingTransaction) => { .create(data, { transaction }); })) .then(async (opportunity) => { + // eslint-disable-next-line no-console + console.time('getRolesByRoleName'); const roles = await util.getRolesByRoleName(USER_ROLE.TC_COPILOT, req.log, req.id); + // eslint-disable-next-line no-console + console.timeEnd('getRolesByRoleName'); const { subjects = [] } = await util.getRoleInfo(roles[0], req.log, req.id); 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: { @@ -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) => { diff --git a/src/util.js b/src/util.js index 60c71d57..da98ce7d 100644 --- a/src/util.js +++ b/src/util.js @@ -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', @@ -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); } }),