Skip to content

Commit

Permalink
fix(aggregation): be more strict about missing entities. better error…
Browse files Browse the repository at this point in the history
… message
  • Loading branch information
Gerald Baulig committed Sep 25, 2024
1 parent f040de3 commit 25cb3a1
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 27 deletions.
20 changes: 10 additions & 10 deletions queries/filter_ownership.aql
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
let found = (
for o in node.meta.owners
filter o.id == "urn:restorecommerce:acs:names:ownerIndicatoryEntity"
for arg in @customArguments
filter o.value == arg.entity
for ownerInst in o.attributes
filter ownerInst.id == "urn:restorecommerce:acs:names:ownerInstance"
filter ownerInst.value in arg.instance
return true
LET found = (
FOR o IN node.meta.owners
FILTER o.id == "urn:restorecommerce:acs:names:ownerIndicatoryEntity"
FOR arg IN @customArguments
FILTER o.value == arg.entity
FOR ownerInst IN o.attributes
FILTER ownerInst.id == "urn:restorecommerce:acs:names:ownerInstance"
FILTER ownerInst.value IN arg.instance
RETURN TRUE
)
filter true in found
FILTER TRUE IN found
56 changes: 39 additions & 17 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,8 @@ export class OrderingService
},
ITEM_NOT_FOUND: {
code: 404,
message: '{entity} not found!',
},
ITEMS_MISSING: {
code: 404,
message: 'Some {entity} are missing in: {id}!',
},
message: '{entity} {id} not found!',
}
};

protected readonly emitters: any;
Expand Down Expand Up @@ -726,13 +722,24 @@ export class OrderingService
limit: product_ids.length,
}).then(
response => {
if (response.operation_status?.code === 200) {
response.items?.forEach(
item => products[item.payload?.id!] = item
if (response.operation_status?.code !== 200) {
throw response.operation_status;
}
else if (response.items?.length !== product_ids.length) {
const found = response.items?.map(item => item.payload?.id);
const missing = product_ids.filter(
id => !found.includes(id)
);
throw this.createOperationStatusCode(
this.operation_status_codes.ITEM_NOT_FOUND,
'products',
JSON.stringify(missing)
);
}
else {
throw response.operation_status;
response.items?.forEach(
item => products[item.payload?.id!] = item
);
}
}
);
Expand Down Expand Up @@ -825,10 +832,15 @@ export class OrderingService
if (response.operation_status?.code !== 200) {
throw response.operation_status;
}
else if (!response.items?.length) {
else if (response.items?.length < product_ids.length) {
const found = response.items?.map(item => item.payload?.id);
const missing = product_ids.filter(
id => !found.includes(id)
);
throw this.createOperationStatusCode(
this.operation_status_codes.ITEM_NOT_FOUND,
'products',
JSON.stringify(missing)
);
}
else {
Expand Down Expand Up @@ -870,7 +882,7 @@ export class OrderingService
];
};

const tax_ids = JSON.stringify([
const tax_ids = [
...new Set<string>(
Object.values(
products
Expand All @@ -880,7 +892,7 @@ export class OrderingService
(id) => !!id
)
).values()
]);
];

return this.tax_service.read(
{
Expand All @@ -889,11 +901,12 @@ export class OrderingService
{
field: 'id',
operation: Filter_Operation.in,
value: tax_ids,
value: JSON.stringify(tax_ids),
type: Filter_ValueType.ARRAY,
}
]
}],
limit: tax_ids.length,
subject,
},
context
Expand All @@ -902,10 +915,15 @@ export class OrderingService
if (response.operation_status?.code !== 200) {
throw response.operation_status;
}
else if (!response.items?.length) {
else if (response.items?.length < tax_ids.length) {
const found = response.items?.map(item => item.payload?.id);
const missing = tax_ids.filter(
id => !found.includes(id)
);
throw this.createOperationStatusCode(
this.operation_status_codes.ITEM_NOT_FOUND,
'taxes',
JSON.stringify(missing)
);
}
else {
Expand Down Expand Up @@ -1023,10 +1041,14 @@ export class OrderingService
throw response.operation_status;
}
else if (response.items?.length < ids.length) {
const found = response.items?.map((item: any) => item.payload?.id);
const missing = ids.filter(
id => !found.includes(id)
);
throw this.createOperationStatusCode(
this.operation_status_codes.ITEMS_MISSING,
this.operation_status_codes.ITEM_NOT_FOUND,
entity,
`[${ids.join(', ')}]`,
JSON.stringify(missing),
);
}
else {
Expand Down

0 comments on commit 25cb3a1

Please sign in to comment.