From 985d18def6198c36c90e5d9e6014b8fd0ab17b62 Mon Sep 17 00:00:00 2001 From: Fred <10602047+freddieptf@users.noreply.github.com> Date: Mon, 10 Feb 2025 19:16:24 +0300 Subject: [PATCH] explicitly convert remote place values to string (#249) * Update remote-place-cache.ts * Update remote-place-cache.ts * test * 2.1.2 --- package-lock.json | 4 ++-- package.json | 2 +- scripts/deploy/values/users-chis-civ.yaml | 4 ++-- scripts/deploy/values/users-chis-ke.yaml | 4 ++-- scripts/deploy/values/users-chis-tg.yaml | 4 ++-- src/lib/remote-place-cache.ts | 4 ++-- test/lib/remote-place-cache.spec.ts | 19 +++++++++++++++++++ 7 files changed, 30 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index a1abf6a..5bdbf53 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "cht-user-management", - "version": "2.1.1", + "version": "2.1.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "cht-user-management", - "version": "2.1.1", + "version": "2.1.2", "license": "ISC", "dependencies": { "@bull-board/api": "^5.17.0", diff --git a/package.json b/package.json index 11a69de..c1cec38 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cht-user-management", - "version": "2.1.1", + "version": "2.1.2", "main": "dist/index.js", "dependencies": { "@bull-board/api": "^5.17.0", diff --git a/scripts/deploy/values/users-chis-civ.yaml b/scripts/deploy/values/users-chis-civ.yaml index c8f8da1..023ed5d 100644 --- a/scripts/deploy/values/users-chis-civ.yaml +++ b/scripts/deploy/values/users-chis-civ.yaml @@ -5,7 +5,7 @@ cht-user-management: enabled: true image: repository: public.ecr.aws/medic/cht-user-management - tag: "2.1.1" # Set this to the version of the docker image + tag: "2.1.2" # Set this to the version of the docker image # Environment variablues to set in the pod, for example: # env: @@ -51,7 +51,7 @@ cht-user-management-worker: replicaCount: 1 image: repository: public.ecr.aws/medic/cht-user-management-worker - tag: "2.1.1" + tag: "2.1.2" env: NODE_ENV: production REDIS_HOST: users-chis-civ-redis-master.users-chis-prod.svc.cluster.local diff --git a/scripts/deploy/values/users-chis-ke.yaml b/scripts/deploy/values/users-chis-ke.yaml index 2e0787b..009447b 100644 --- a/scripts/deploy/values/users-chis-ke.yaml +++ b/scripts/deploy/values/users-chis-ke.yaml @@ -5,7 +5,7 @@ cht-user-management: enabled: true image: repository: public.ecr.aws/medic/cht-user-management - tag: "2.1.1" # Set this to the version of the docker image + tag: "2.1.2" # Set this to the version of the docker image # Environment variablues to set in the pod, for example: # env: @@ -51,7 +51,7 @@ cht-user-management-worker: replicaCount: 1 image: repository: public.ecr.aws/medic/cht-user-management-worker - tag: "2.1.1" + tag: "2.1.2" env: NODE_ENV: production REDIS_HOST: users-chis-ke-redis-master.users-chis-prod.svc.cluster.local diff --git a/scripts/deploy/values/users-chis-tg.yaml b/scripts/deploy/values/users-chis-tg.yaml index 249d61a..4b0cba0 100644 --- a/scripts/deploy/values/users-chis-tg.yaml +++ b/scripts/deploy/values/users-chis-tg.yaml @@ -5,7 +5,7 @@ cht-user-management: enabled: true image: repository: public.ecr.aws/medic/cht-user-management - tag: "2.1.1" # Set this to the version of the docker image + tag: "2.1.2" # Set this to the version of the docker image # Environment variablues to set in the pod, for example: # env: @@ -51,7 +51,7 @@ cht-user-management-worker: replicaCount: 1 image: repository: public.ecr.aws/medic/cht-user-management-worker - tag: "2.1.1" + tag: "2.1.2" env: NODE_ENV: production REDIS_HOST: users-chis-tg-redis-master.users-chis-prod.svc.cluster.local diff --git a/src/lib/remote-place-cache.ts b/src/lib/remote-place-cache.ts index 90d4ee5..11a2b26 100644 --- a/src/lib/remote-place-cache.ts +++ b/src/lib/remote-place-cache.ts @@ -95,7 +95,7 @@ export default class RemotePlaceCache { private static convertContactToRemotePlace(doc: any, uniqueKeyProperties: ContactProperty[], hierarchyLevel: HierarchyConstraint): RemotePlace { const uniqueKeyStringValues: FormattedPropertyCollection = {}; for (const property of uniqueKeyProperties) { - const value = doc[property.property_name]; + const value = doc[property.property_name]?.toString(); if (value) { uniqueKeyStringValues[property.property_name] = new RemotePlacePropertyValue(value, property); } @@ -103,7 +103,7 @@ export default class RemotePlaceCache { return { id: doc._id, - name: new RemotePlacePropertyValue(doc.name, hierarchyLevel), + name: new RemotePlacePropertyValue(doc.name?.toString(), hierarchyLevel), placeType: hierarchyLevel.contact_type, lineage: this.extractLineage(doc), uniquePlaceValues: uniqueKeyStringValues, diff --git a/test/lib/remote-place-cache.spec.ts b/test/lib/remote-place-cache.spec.ts index b42abd4..664c169 100644 --- a/test/lib/remote-place-cache.spec.ts +++ b/test/lib/remote-place-cache.spec.ts @@ -81,4 +81,23 @@ describe('lib/remote-place-cache.ts', () => { chtApi.chtSession.authInfo.domain = 'http://other'; RemotePlaceCache.clear(chtApi, 'other'); }); + + it('unique key properties', async () => { + const chtApi = mockChtApi([{_id: 'id', name: 1 }]); + const contactType = mockSimpleContactType('string', undefined); + contactType.place_properties.find(p => p.property_name === 'name').unique = 'all'; + const contactTypeAsHierarchyLevel: HierarchyConstraint = { + contact_type: contactType.name, + property_name: 'level', + friendly_name: 'pretend another ContactType needs this', + type: 'name', + required: true, + level: 0, + }; + try { + await RemotePlaceCache.getRemotePlaces(chtApi, contactType, contactTypeAsHierarchyLevel); + } catch (e) { + expect(e).to.be.undefined; + } + }); });