Skip to content

Commit

Permalink
fix contract definition page failing for all operators but IN
Browse files Browse the repository at this point in the history
  • Loading branch information
richardtreier committed May 2, 2023
1 parent cb0d494 commit c1a2c3c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
24 changes: 24 additions & 0 deletions fake-backend/json/contractDefinitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,29 @@
}
],
"id": "Charging Station - Walkthrough"
},
{
"id": "example-using-asset-prop-id-eq",
"accessPolicyId": "end-of-the-year",
"contractPolicyId": "end-of-the-year",
"criteria": [
{
"operandLeft": "asset:prop:id",
"operator": "eq",
"operandRight": "urn:artifact:db-rail-network-2023-jan"
}
]
},
{
"id": "example-using-asset-prop-usecase-eq",
"accessPolicyId": "end-of-the-year",
"contractPolicyId": "end-of-the-year",
"criteria": [
{
"operandLeft": "asset:prop:usecase",
"operator": "eq",
"operandRight": "urn:usecase:my-example-usecase"
}
]
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class ContractDefinitionCardBuilder {
contractDefinition.accessPolicyId,
policyDefinitionById,
),

criteria: contractDefinition.criteria.map((criterion) => ({
label: this.extractCriterionOperation(criterion),
values: this.extractCriterionValues(criterion, assetById),
Expand Down Expand Up @@ -93,10 +94,8 @@ export class ContractDefinitionCardBuilder {
let {operandRight, operandLeft} = criterion;

let values: (object | string)[] = [];
if (Array.isArray(values)) {
if (Array.isArray(operandRight)) {
values = operandRight as string[];
} else if (typeof operandRight === 'string') {
values = [operandRight];
} else {
values = [operandRight];
}
Expand All @@ -109,7 +108,7 @@ export class ContractDefinitionCardBuilder {
searchTargets: [it],
};

// Try find asset
// Try to find asset
if (operandLeft === AssetProperties.id) {
let asset = assetsById.get(it);
if (asset) {
Expand Down

0 comments on commit c1a2c3c

Please sign in to comment.