Skip to content

Commit

Permalink
fix: extend acs-client for supporting multiple entitites in custom ar…
Browse files Browse the repository at this point in the history
…guments filter response
  • Loading branch information
Arun-KumarH committed Apr 22, 2024
1 parent e504a2c commit dab3aaf
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 59 deletions.
76 changes: 38 additions & 38 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@
],
"type": "module",
"dependencies": {
"@bull-board/api": "^5.15.5",
"@bull-board/express": "^5.15.5",
"@bull-board/koa": "^5.15.5",
"@restorecommerce/acs-client": "^1.5.1",
"@restorecommerce/chassis-srv": "^1.5.0",
"@bull-board/api": "^5.16.0",
"@bull-board/express": "^5.16.0",
"@bull-board/koa": "^5.16.0",
"@restorecommerce/acs-client": "^1.6.0",
"@restorecommerce/chassis-srv": "^1.6.0",
"@restorecommerce/cluster-service": "^1.0.3",
"@restorecommerce/kafka-client": "^1.2.1",
"@restorecommerce/logger": "^1.2.10",
"@restorecommerce/rc-grpc-clients": "^5.1.23",
"@restorecommerce/scs-jobs": "^0.1.23",
"@restorecommerce/service-config": "^1.0.12",
"bullmq": "^5.7.1",
"bullmq": "^5.7.4",
"cache-manager": "^5.5.1",
"cache-manager-redis": "^0.6.0",
"cron-parser": "^4.9.0",
Expand Down
37 changes: 22 additions & 15 deletions src/schedulingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ export class SchedulingService implements SchedulingServiceServiceImplementation

private filterByOwnerShip(customArgsObj, result) {
// applying filter based on custom arguments (filterByOwnerShip)
let filteredResult: Job[] = [];
let customArgs = (customArgsObj)?.custom_arguments;
if (customArgs?.value) {
let customArgsFilter;
Expand All @@ -638,28 +639,34 @@ export class SchedulingService implements SchedulingServiceServiceImplementation
message: error.message, stack: error.stack
});
}
if (!customArgsFilter) {
if (customArgsFilter?.length === 0) {
return [];
}
const ownerIndicatorEntity = customArgsFilter.entity;
const ownerValues = customArgsFilter.instance;
const ownerIndictaorEntURN = this.cfg.get('authorization:urns:ownerIndicatoryEntity');
const ownerInstanceURN = this.cfg.get('authorization:urns:ownerInstance');
result = result.filter(job => {
if (job?.data?.meta?.owners?.length > 0) {
for (let owner of job.data.meta.owners) {
if (owner?.id === ownerIndictaorEntURN && owner?.value === ownerIndicatorEntity && owner?.attributes?.length > 0) {
for (let ownerInstObj of owner.attributes) {
if (ownerInstObj?.id === ownerInstanceURN && ownerInstObj?.value && ownerValues.includes(ownerInstObj.value)) {
return job;
for (let customArgObj of customArgsFilter) {
const ownerIndicatorEntity = customArgObj?.entity;
const ownerValues = customArgObj?.instance;
const ownerIndictaorEntURN = this.cfg.get('authorization:urns:ownerIndicatoryEntity');
const ownerInstanceURN = this.cfg.get('authorization:urns:ownerInstance');
const filteredResp = result.filter(job => {
if (job?.data?.meta?.owners?.length > 0) {
for (let owner of job.data.meta.owners) {
if (owner?.id === ownerIndictaorEntURN && owner?.value === ownerIndicatorEntity && owner?.attributes?.length > 0) {
for (let ownerInstObj of owner.attributes) {
if (ownerInstObj?.id === ownerInstanceURN && ownerInstObj?.value && ownerValues.includes(ownerInstObj.value)) {
return job;
}
}
}
}
}
}
});
});
filteredResult = filteredResult.concat(filteredResp);
}
return filteredResult;
} else {
// no custom filters exist, return complete result set
return result;
}
return result;
}

async deleteRedisKey(key: string): Promise<any> {
Expand Down

0 comments on commit dab3aaf

Please sign in to comment.