Skip to content
This repository has been archived by the owner on Jul 4, 2019. It is now read-only.

Commit

Permalink
Merge pull request #40 from Financial-Times/fix-user-email-digest-prefs
Browse files Browse the repository at this point in the history
Calling new next-myft-api endpoint for setting user email preferences
  • Loading branch information
dapenguin authored Nov 30, 2017
2 parents c0d86cb + 2a1159a commit ba1807c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
31 changes: 19 additions & 12 deletions lib/myFTClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -853,12 +853,26 @@ 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) {
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,
// Make sure we pass uuid as an array
userIds: Array.isArray(uuid) ? uuid : [uuid]
};

return _doRelationshipRequest('POST', theUrl, data, params)
.then(helpers.parseJsonRes)
.then(res => {
log.debug({operation: 'myFTClient.setEmailDigestPreferences', uuid, res: 'success'});
return res;
});
}

/**
Expand Down Expand Up @@ -1329,14 +1343,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 => {
Expand Down
10 changes: 1 addition & 9 deletions lib/syncUserFollows.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,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 => {
Expand Down
2 changes: 1 addition & 1 deletion test/myFTClient.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ba1807c

Please sign in to comment.