Skip to content

Commit

Permalink
fix: register multiroles
Browse files Browse the repository at this point in the history
Merge pull request #3345 from energywebfoundation/fix/multirole-organizations
  • Loading branch information
patryk-kochanski authored Mar 29, 2022
2 parents 051544d + 57de405 commit 187536c
Showing 1 changed file with 30 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,25 @@ export class CreateConnectionHandler implements ICommandHandler<CreateConnection
tokens
);

const isIssuer = irecOrganization.roles.includes(OrganisationRole.Issuer);
const isRegistrant = irecOrganization.roles.includes(OrganisationRole.Registrant);
const isParticipant = irecOrganization.roles.includes(OrganisationRole.Participant);
const accountTypesToRegister = this.getAccountTypesForOrganizationRoles(
irecOrganization.roles
);

if (isIssuer) {
await this.createAccounts(clientId, clientSecret, tokens, organization, [
AccountType.Issue
]);
} else if (isParticipant) {
await this.createAccounts(clientId, clientSecret, tokens, organization, [
AccountType.Trade,
AccountType.Redemption
]);
} else {
if (!accountTypesToRegister.length) {
const isRegistrant = irecOrganization.roles.includes(OrganisationRole.Registrant);
if (!isRegistrant) {
throw new BadRequestException(
'IREC account organization has to have issuer or registrant or participant role'
);
}
} else {
await this.createAccounts(
clientId,
clientSecret,
tokens,
organization,
accountTypesToRegister
);
}
}

Expand Down Expand Up @@ -142,4 +142,21 @@ export class CreateConnectionHandler implements ICommandHandler<CreateConnection
}
}
}

private getAccountTypesForOrganizationRoles(roles: OrganisationRole[]): AccountType[] {
const isIssuer = roles.includes(OrganisationRole.Issuer);
const isParticipant = roles.includes(OrganisationRole.Participant);

const accountTypes: AccountType[] = [];

if (isIssuer) {
accountTypes.push(AccountType.Issue);
}
if (isParticipant) {
accountTypes.push(AccountType.Redemption);
accountTypes.push(AccountType.Trade);
}

return accountTypes;
}
}

0 comments on commit 187536c

Please sign in to comment.