-
Notifications
You must be signed in to change notification settings - Fork 56
feat(PM-1173): Notify all copilots on copilot opportunity #815
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
Changes from 4 commits
79fdf6f
4b8c9f7
0c54ecf
223b7bd
82dd797
9793dcc
5b29f65
a29f1c9
deaed3a
d4ed7a9
91f23ab
fb9b8a9
31a2b66
ae5952d
c16d06e
190c04c
4c98fe7
0ad22c3
cc5a28d
b52b16e
5fbd197
49356d6
e34f785
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import _ from 'lodash'; | |
|
||
import models from '../../models'; | ||
import { COPILOT_REQUEST_STATUS } from '../../constants'; | ||
import util from '../../util'; | ||
|
||
const resolveTransaction = (transaction, callback) => { | ||
if (transaction) { | ||
|
@@ -52,6 +53,14 @@ module.exports = (data, existingTransaction) => { | |
return models.CopilotOpportunity | ||
.create(data, { transaction }); | ||
})) | ||
.then(async (opportunity) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider removing the |
||
console.log(opportunity); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid using |
||
const roles = await util.getRolesByRoleName('copilot'); | ||
const roleInfo = await util.getRoleInfo(roles[0]); | ||
console.log(roles, roleInfo, 'roles by copilot'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider removing the |
||
|
||
return opportunity; | ||
}) | ||
.catch((err) => { | ||
transaction.rollback(); | ||
return Promise.reject(err); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -815,6 +815,48 @@ const projectServiceUtils = { | |
} | ||
}, | ||
|
||
getRoleInfo: Promise.coroutine(function* (roleId, logger, requestId) { // eslint-disable-line func-names | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using async/await syntax instead of Promise.coroutine for better readability and modern JavaScript practices. |
||
try { | ||
const token = yield this.getM2MToken(); | ||
const httpClient = this.getHttpClient({ id: requestId, log: logger }); | ||
return httpClient.get(`${config.identityServiceEndpoint}roles/${roleId}`, { | ||
params: { | ||
fields: 'subjects' | ||
}, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
}).then((res) => { | ||
logger.debug(`Role info by ${roleId}: ${JSON.stringify(res.data.result.content)}`); | ||
return _.get(res, 'data.result.content', []); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of |
||
}); | ||
} catch (err) { | ||
return Promise.reject(err); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of returning |
||
} | ||
}), | ||
|
||
getRolesByRoleName: Promise.coroutine(function* (roleName, logger, requestId) { // eslint-disable-line func-names | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using async/await instead of Promise.coroutine for better readability and modern syntax. |
||
try { | ||
const token = yield this.getM2MToken(); | ||
const httpClient = this.getHttpClient({ id: requestId, log: logger }); | ||
return httpClient.get(`${config.identityServiceEndpoint}roles`, { | ||
params: { | ||
filter: `roleName=${roleName}`, | ||
}, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
}).then((res) => { | ||
logger.debug(`Roles by ${roleName}: ${JSON.stringify(res.data.result.content)}`); | ||
return _.get(res, 'data.result.content', []).map(r => r.id); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The change from |
||
}); | ||
} catch (err) { | ||
return Promise.reject(err); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of catching the error and returning a rejected promise, consider allowing the error to propagate naturally. This will make the function easier to handle with async/await syntax. |
||
} | ||
}), | ||
|
||
/** | ||
* Retrieve member details from userIds | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
console.log(opportunity);
statement has been removed, which is good for production code, but ensure that any necessary logging is still in place for debugging purposes.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason to use console here instead of the req.log?