Skip to content

Commit 9793dcc

Browse files
committed
fix: get role by role name
1 parent 82dd797 commit 9793dcc

File tree

5 files changed

+32
-5
lines changed

5 files changed

+32
-5
lines changed

config/default.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"inviteEmailSubject": "You are invited to Topcoder",
5555
"inviteEmailSectionTitle": "Project Invitation",
5656
"workManagerUrl": "https://challenges.topcoder-dev.com",
57+
"copilotPortalUrl": "https://copilots.topcoder-dev.com",
5758
"accountsAppUrl": "https://accounts.topcoder-dev.com",
5859
"MAX_REVISION_NUMBER": 100,
5960
"UNIQUE_GMAIL_VALIDATION": false,

config/development.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"pubsubExchangeName": "dev.projects",
44
"attachmentsS3Bucket": "topcoder-dev-media",
55
"workManagerUrl": "https://challenges.topcoder-dev.com",
6+
"copilotPortalUrl": "https://copilots.topcoder-dev.com",
67
"fileServiceEndpoint": "https://api.topcoder-dev.com/v5/files",
78
"memberServiceEndpoint": "https://api.topcoder-dev.com/v5/members",
89
"identityServiceEndpoint": "https://api.topcoder-dev.com/v3/",

config/production.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"authDomain": "topcoder.com",
33
"workManagerUrl": "https://challenges.topcoder.com",
4+
"copilotPortalUrl": "https://copilots.topcoder.com",
45
"sfdcBillingAccountNameField": "Billing_Account_name__c",
56
"sfdcBillingAccountMarkupField": "Mark_up__c",
67
"sfdcBillingAccountActiveField": "Active__c"

src/routes/copilotRequest/approveRequest.service.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import _ from 'lodash';
2+
import config from 'config';
23

34
import models from '../../models';
4-
import { COPILOT_REQUEST_STATUS } from '../../constants';
5+
import { CONNECT_NOTIFICATION_EVENT, COPILOT_REQUEST_STATUS } from '../../constants';
56
import util from '../../util';
7+
import { createEvent } from '../../services/busApi';
68

79
const resolveTransaction = (transaction, callback) => {
810
if (transaction) {
@@ -54,11 +56,31 @@ module.exports = (req, data, existingTransaction) => {
5456
.create(data, { transaction });
5557
}))
5658
.then(async (opportunity) => {
57-
console.log(opportunity);
5859
const roles = await util.getRolesByRoleName('copilot', req.log, req.id);
59-
const roleInfo = await util.getRoleInfo(roles[0], req.log, req.id);
60-
console.log(roles, roleInfo, 'roles by copilot');
60+
const { subjects = [] } = await util.getRoleInfo(roles[0], req.log, req.id);
61+
req.log.info("getting subjects for roles", roles[0]);
62+
const emailEventType = CONNECT_NOTIFICATION_EVENT.COPILOT_OPPORTUNITY_CREATED;
63+
const copilotPortalUrl = config.get('copilotPortalUrl');
64+
req.log.info("Sending emails to all copilots about new opportunity");
65+
subjects.forEach(subject => {
66+
req.log.info("Each copilot members", subject);
67+
createEvent(emailEventType, {
68+
data: {
69+
handle: subject.handle,
70+
opportunityDetailsUrl: `${copilotPortalUrl}/opportunity/${opportunity.id}`,
71+
},
72+
recipients: [subject.email],
73+
version: 'v3',
74+
from: {
75+
name: config.get('EMAIL_INVITE_FROM_NAME'),
76+
email: config.get('EMAIL_INVITE_FROM_EMAIL'),
77+
},
78+
categories: [`${process.env.NODE_ENV}:${emailEventType}`.toLowerCase()],
79+
}, req.log);
80+
});
6181

82+
req.log.info("Finished sending emails to copilots");
83+
6284
return opportunity;
6385
})
6486
.catch((err) => {

src/util.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,9 @@ const projectServiceUtils = {
850850
},
851851
}).then((res) => {
852852
logger.debug(`Roles by ${roleName}: ${JSON.stringify(res.data.result.content)}`);
853-
return _.get(res, 'data.result.content', []).map(r => r.id);
853+
return _.get(res, 'data.result.content', [])
854+
.filter(item => item.roleName === roleName)
855+
.map(r => r.id);
854856
});
855857
} catch (err) {
856858
return Promise.reject(err);

0 commit comments

Comments
 (0)