From f5c33d2c5ad14757922207fa3c5fcabc7a62b1ed Mon Sep 17 00:00:00 2001 From: dapenguin Date: Fri, 24 Nov 2017 17:05:36 +0000 Subject: [PATCH 1/6] =?UTF-8?q?Updated=20setEmailDigestPreference=20to=20c?= =?UTF-8?q?all=20new=20endpoint=20in=20next-myft-api=20=20=F0=9F=90=BF=20v?= =?UTF-8?q?2.5.16?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/myFTClient.js | 17 +++++++++++++---- test/myFTClient.spec.js | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/myFTClient.js b/lib/myFTClient.js index 0c50085..6b86eae 100644 --- a/lib/myFTClient.js +++ b/lib/myFTClient.js @@ -853,12 +853,21 @@ function getEmailDigestPreference (uuid) { * at a minimum this should be type and timezone. For example: * {type: "daily", timezone:"Europe/London", byTool: "KAT", * byUser: "[user-id]"} - * @param {Object} [options] - additional options {supressEvents: true|false, waitForPurge: true|false } - * default behaviour not to supress event generation and wait for a cache purge * @return {Promise} response - EmailDigestPreference json structure */ -function setEmailDigestPreference (uuid, preference, options) { - return _multiAddRemoveRelationships('POST', myftConst.userNodeName, uuid, myftConst.prefRelType, myftConst.prefRelName, [{uuid: myftConst.prefRelId}], preference, options); +function setEmailDigestPreference (uuid, preference) { + // check whether uuid is an array of ids or a single one + const theUrl = `${config.MYFT_API_URL}/kat/user/email-digest`; + const params = { + noEvent: config.MYFT_NO_EVENT, + waitForPurge: config.MYFT_WAIT_FOR_PURGE_ADD + }; + const data = { + preferenceData: preference, + userIds: Array.isArray(uuid) ? uuid : [uuid] + }; + + return _doRelationshipRequest('POST', theUrl, data, params); } /** diff --git a/test/myFTClient.spec.js b/test/myFTClient.spec.js index 4dc375e..44f1d5d 100644 --- a/test/myFTClient.spec.js +++ b/test/myFTClient.spec.js @@ -55,7 +55,7 @@ describe('myFT Client proxy', () => { it('Should set an EmailDigestPreference for a valid user uuid', done => { nock(baseUrl) - .post(`/${myftConst.userNodeName}/${myftConst.prefRelType}/${myftConst.prefRelName}${extraParams}`) + .post(`/kat/user/email-digest${extraParams}`) .reply(200, () => ({})); nock(baseUrl) From 49ad73bc480a4aa6535526385a82d64685e63227 Mon Sep 17 00:00:00 2001 From: dapenguin Date: Fri, 24 Nov 2017 17:47:56 +0000 Subject: [PATCH 2/6] =?UTF-8?q?No=20longer=20need=20to=20check=20for=20an?= =?UTF-8?q?=20existing=20email=20digest=20preference=20before=20setting=20?= =?UTF-8?q?it=20=20=F0=9F=90=BF=20v2.5.16?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/myFTClient.js | 9 +-------- lib/syncUserFollows.js | 10 +--------- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/lib/myFTClient.js b/lib/myFTClient.js index 6b86eae..ea3815e 100644 --- a/lib/myFTClient.js +++ b/lib/myFTClient.js @@ -1317,14 +1317,7 @@ function syncUserFollowers (groupId, userId) { return addConceptsFollowedByUser(userId, newConceptsToFollow, followProps) .then(() => { log.silly({operation, subOp: 'setEmailDigestPreference', userId}); - return getEmailDigestPreference(userId) - .catch(err => { - // if no preferences are found - if (err instanceof clientErrors.NotFoundError) { - return setEmailDigestPreference(userId, digestProperties); - } - throw err; - }); + return setEmailDigestPreference(userId, digestProperties); }) .then(() => { const cleanConcepts = newConceptsToFollow.map(item => { diff --git a/lib/syncUserFollows.js b/lib/syncUserFollows.js index 9139e9f..8948ee2 100644 --- a/lib/syncUserFollows.js +++ b/lib/syncUserFollows.js @@ -85,15 +85,7 @@ function userFollows (groupId, userId) { .then(() => { //Not sure we need to be doing this log.info({operation, subOp: 'getEmailDigestPreference', userId}); - return myFT.getEmailDigestPreference(userId) - .catch(err => { - // if no preferences are found - if (err instanceof clientErrors.NotFoundError) { - log.info({operation, subOp: 'getEmailDigestPreference', userId}); - return myFT.setEmailDigestPreference(userId, digestProperties); - } - throw err; - }); + return myFT.setEmailDigestPreference(userId, digestProperties); }) .then(() => { const cleanConcepts = newConceptsToFollow.map(item => { From 9393db0eec996351bfa1e677e5a9d4249e23cdbe Mon Sep 17 00:00:00 2001 From: dapenguin Date: Mon, 27 Nov 2017 11:24:22 +0000 Subject: [PATCH 3/6] =?UTF-8?q?Adjusted=20and=20moved=20comment=20closer?= =?UTF-8?q?=20to=20the=20line=20it=20relates=20to=20=20=F0=9F=90=BF=20v2.5?= =?UTF-8?q?.16?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/myFTClient.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/myFTClient.js b/lib/myFTClient.js index ea3815e..ded6c49 100644 --- a/lib/myFTClient.js +++ b/lib/myFTClient.js @@ -856,7 +856,6 @@ function getEmailDigestPreference (uuid) { * @return {Promise} response - EmailDigestPreference json structure */ function setEmailDigestPreference (uuid, preference) { - // check whether uuid is an array of ids or a single one const theUrl = `${config.MYFT_API_URL}/kat/user/email-digest`; const params = { noEvent: config.MYFT_NO_EVENT, @@ -864,6 +863,7 @@ function setEmailDigestPreference (uuid, preference) { }; const data = { preferenceData: preference, + // Make sure we pass uuid as an array userIds: Array.isArray(uuid) ? uuid : [uuid] }; From 749efb28e2ee7e5a52e2a8555e5a7f74cb7eeb71 Mon Sep 17 00:00:00 2001 From: dapenguin Date: Mon, 27 Nov 2017 11:34:59 +0000 Subject: [PATCH 4/6] =?UTF-8?q?Upped=20version=20number=20=20=F0=9F=90=BF?= =?UTF-8?q?=20v2.5.16?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 40d9f93..390b817 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kat-client-proxies", - "version": "2.1.10", + "version": "2.2.0", "description": "A library of client proxies for various ft platform apis", "main": "index.js", "engines": { From 8a6163a810d8de8b7e89c908413722a2a9fd6a2c Mon Sep 17 00:00:00 2001 From: Anthony Jeffery Date: Tue, 28 Nov 2017 15:16:22 +0000 Subject: [PATCH 5/6] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 390b817..d856ee9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kat-client-proxies", - "version": "2.2.0", + "version": "2.1.13", "description": "A library of client proxies for various ft platform apis", "main": "index.js", "engines": { From 8c33a0bd91948ea53c741e5c9071102120dc9e35 Mon Sep 17 00:00:00 2001 From: dapenguin Date: Wed, 29 Nov 2017 14:05:05 +0000 Subject: [PATCH 6/6] =?UTF-8?q?Forgot=20to=20parse=20JSON=20response=20whe?= =?UTF-8?q?n=20setting=20Email=20Digest=20Preferences=20=20=F0=9F=90=BF=20?= =?UTF-8?q?v2.5.16?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/myFTClient.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/myFTClient.js b/lib/myFTClient.js index ded6c49..b45ca0a 100644 --- a/lib/myFTClient.js +++ b/lib/myFTClient.js @@ -867,7 +867,12 @@ function setEmailDigestPreference (uuid, preference) { userIds: Array.isArray(uuid) ? uuid : [uuid] }; - return _doRelationshipRequest('POST', theUrl, data, params); + return _doRelationshipRequest('POST', theUrl, data, params) + .then(helpers.parseJsonRes) + .then(res => { + log.debug({operation: 'myFTClient.setEmailDigestPreferences', uuid, res: 'success'}); + return res; + }); } /**