Skip to content

Commit

Permalink
♻️ Refactor Jira user loadOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
pemontto committed Feb 6, 2022
1 parent 115d082 commit 0d006b3
Showing 1 changed file with 15 additions and 31 deletions.
46 changes: 15 additions & 31 deletions packages/nodes-base/nodes/Jira/Jira.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,45 +304,29 @@ export class Jira implements INodeType {
// Get all the users to display them to user so that he can
// select them easily
async getUsers(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const jiraVersion = this.getCurrentNodeParameter('jiraVersion') as string;
if (jiraVersion === 'server') {
// the interface call must bring username
const users = await jiraSoftwareCloudApiRequest.call(this, '/api/2/user/search', 'GET', {},
{
username: '\'',
},
);
for (const user of users) {
const userName = user.displayName;
const userId = user.name;
const query: IDataObject = {};
let endpoint = '/api/2/users/search';

returnData.push({
name: userName,
value: userId,
});
}
} else {
const users = await jiraSoftwareCloudApiRequest.call(this, '/api/2/users/search', 'GET');
if (jiraVersion === 'server') {
endpoint = '/api/2/user/search';
query.username = '\'';
}

for (const user of users) {
const userName = user.displayName;
const userId = user.accountId;
const users = await jiraSoftwareCloudApiRequest.call(this, endpoint, 'GET', {}, query);

returnData.push({
name: userName,
value: userId,
return users.reduce((activeUsers: INodePropertyOptions[], user: IDataObject) => {
if (user.active) {
activeUsers.push({
name: user.displayName as string,
value: (user.accountId || user.name) as string,
});
}
}

returnData.sort((a, b) => {
if (a.name < b.name) { return -1; }
if (a.name > b.name) { return 1; }
return 0;
return activeUsers;
}, []).sort((a: INodePropertyOptions, b: INodePropertyOptions) => {
return a.name.toLowerCase() > b.name.toLowerCase() ? 1 : -1;
});

return returnData;
},

// Get all the groups to display them to user so that he can
Expand Down

0 comments on commit 0d006b3

Please sign in to comment.