X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/cc493b89840b48f40c2beaf626994724331aa196..b545b17633d2d37242a39a2d1b474e3206d44e41:/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 1cd42fb523..23e7729f7d 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 +}