From 62b1d6a3ed1ecf60c5f77851cee4129dff844c30 Mon Sep 17 00:00:00 2001 From: Nikita Nek Dudnik Date: Thu, 11 Jun 2020 11:55:48 +0200 Subject: [PATCH] fix(catalog): moar clean up --- .../src/catalog/DatabaseEntitiesCatalog.ts | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/plugins/catalog-backend/src/catalog/DatabaseEntitiesCatalog.ts b/plugins/catalog-backend/src/catalog/DatabaseEntitiesCatalog.ts index 578ae40daa..6ab660a587 100644 --- a/plugins/catalog-backend/src/catalog/DatabaseEntitiesCatalog.ts +++ b/plugins/catalog-backend/src/catalog/DatabaseEntitiesCatalog.ts @@ -81,30 +81,28 @@ export class DatabaseEntitiesCatalog implements EntitiesCatalog { async removeEntityByUid(uid: string): Promise { return await this.database.transaction(async tx => { - const currentEntity = await this.database.entityByUid(tx, uid); - if (!currentEntity) { + const entityResponse = await this.database.entityByUid(tx, uid); + if (!entityResponse) { throw new NotFoundError(`Entity with ID ${uid} was not found`); } - const colocatedEntities = currentEntity?.entity.metadata.annotations?.[ - LOCATION_ANNOTATION - ] + const location = + entityResponse.entity.metadata.annotations?.[LOCATION_ANNOTATION]; + const colocatedEntities = location ? await this.database.entities(tx, [ { key: LOCATION_ANNOTATION, - values: [ - currentEntity.entity.metadata.annotations[LOCATION_ANNOTATION], - ], + values: [location], }, ]) - : [currentEntity]; + : [entityResponse]; for (const dbResponse of colocatedEntities) { await this.database.removeEntity(tx, dbResponse?.entity.metadata.uid!); } - if (currentEntity?.locationId) { - await this.database.removeLocation(tx, currentEntity?.locationId!); + if (entityResponse.locationId) { + await this.database.removeLocation(tx, entityResponse?.locationId!); } - return Promise.resolve(); + return undefined; }); }