X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/0c46a74e6c0397fa153c345857977f8654ec4471..bcc074c282de71fe63d2ce23127b58f92c90037c:/src/services/ancestors-service/ancestors-service.ts diff --git a/src/services/ancestors-service/ancestors-service.ts b/src/services/ancestors-service/ancestors-service.ts index 1cd42fb5..23e7729f 100644 --- a/src/services/ancestors-service/ancestors-service.ts +++ b/src/services/ancestors-service/ancestors-service.ts @@ -14,17 +14,30 @@ export class AncestorService { private userService: UserService ) { } - async ancestors(uuid: string, rootUuid: string): Promise> { - const service = this.getService(extractUuidObjectType(uuid)); + async ancestors(startUuid: string, endUuid: string): Promise> { + return this._ancestors(startUuid, endUuid); + } + + private async _ancestors(startUuid: string, endUuid: string, previousUuid = ''): Promise> { + + if (startUuid === previousUuid) { + return []; + } + + const service = this.getService(extractUuidObjectType(startUuid)); if (service) { - const resource = await service.get(uuid); - if (uuid === rootUuid) { - return [resource]; - } else { - return [ - ...await this.ancestors(resource.ownerUuid, rootUuid), - resource - ]; + try { + const resource = await service.get(startUuid); + if (startUuid === endUuid) { + return [resource]; + } else { + return [ + ...await this._ancestors(resource.ownerUuid, endUuid, startUuid), + resource + ]; + } + } catch (e) { + return []; } } else { return []; @@ -41,4 +54,4 @@ export class AncestorService { return undefined; } } -} \ No newline at end of file +}