From 5094dc75a51f973f1b635397813651bce18b5fd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Mon, 1 Jun 2020 21:27:38 +0200 Subject: [PATCH] Add ability to specify locationId on addOrUpdateEntity --- .../src/catalog/DatabaseEntitiesCatalog.ts | 14 ++++++++++---- plugins/catalog-backend/src/catalog/types.ts | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/plugins/catalog-backend/src/catalog/DatabaseEntitiesCatalog.ts b/plugins/catalog-backend/src/catalog/DatabaseEntitiesCatalog.ts index d13ac9a1ba..606b6dc475 100644 --- a/plugins/catalog-backend/src/catalog/DatabaseEntitiesCatalog.ts +++ b/plugins/catalog-backend/src/catalog/DatabaseEntitiesCatalog.ts @@ -49,13 +49,16 @@ export class DatabaseEntitiesCatalog implements EntitiesCatalog { ); } - async addOrUpdateEntity(entity: Entity): Promise { + async addOrUpdateEntity( + entity: Entity, + locationId?: string, + ): Promise { await this.policy.enforce(entity); return await this.database.transaction(async tx => { let response: DbEntityResponse; if (entity.metadata.uid) { - response = await this.database.updateEntity(tx, { entity }); + response = await this.database.updateEntity(tx, { locationId, entity }); } else { const existing = await this.entityByNameInternal( tx, @@ -64,9 +67,12 @@ export class DatabaseEntitiesCatalog implements EntitiesCatalog { entity.metadata.namespace, ); if (existing) { - response = await this.database.updateEntity(tx, { entity }); + response = await this.database.updateEntity(tx, { + locationId, + entity, + }); } else { - response = await this.database.addEntity(tx, { entity }); + response = await this.database.addEntity(tx, { locationId, entity }); } } diff --git a/plugins/catalog-backend/src/catalog/types.ts b/plugins/catalog-backend/src/catalog/types.ts index 61fba33ebf..2ef5fd9e56 100644 --- a/plugins/catalog-backend/src/catalog/types.ts +++ b/plugins/catalog-backend/src/catalog/types.ts @@ -30,7 +30,7 @@ export type EntitiesCatalog = { namespace: string | undefined, name: string, ): Promise; - addOrUpdateEntity(entity: Entity): Promise; + addOrUpdateEntity(entity: Entity, locationId?: string): Promise; removeEntityByUid(uid: string): Promise; };