From 4e3cefd4fa42762aac756f3163dfff9047f2e516 Mon Sep 17 00:00:00 2001 From: Michal Klobukowski Date: Mon, 10 Dec 2018 10:26:55 +0100 Subject: [PATCH] Refactor AncestorService to hide recursion implementation and give more meaningful names to arguments Feature #14553 Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski --- .../ancestors-service/ancestors-service.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/services/ancestors-service/ancestors-service.ts b/src/services/ancestors-service/ancestors-service.ts index 697cd8fd..d6351455 100644 --- a/src/services/ancestors-service/ancestors-service.ts +++ b/src/services/ancestors-service/ancestors-service.ts @@ -14,21 +14,25 @@ export class AncestorService { private userService: UserService ) { } - async ancestors(uuid: string, rootUuid: string, previousUuid = ''): Promise> { + async ancestors(startUuid: string, endUuid: string): Promise> { + return this._ancestors(startUuid, endUuid); + } + + private async _ancestors(startUuid: string, endUuid: string, previousUuid = ''): Promise> { - if (uuid === previousUuid) { + if (startUuid === previousUuid) { return []; } - const service = this.getService(extractUuidObjectType(uuid)); + const service = this.getService(extractUuidObjectType(startUuid)); if (service) { try { - const resource = await service.get(uuid); - if (uuid === rootUuid) { + const resource = await service.get(startUuid); + if (startUuid === endUuid) { return [resource]; } else { return [ - ...await this.ancestors(resource.ownerUuid, rootUuid, uuid), + ...await this._ancestors(resource.ownerUuid, endUuid, startUuid), resource ]; } -- 2.30.2