Skip to content

Commit 57748f1

Browse files
author
Sachin Maheshwari
committed
adding country code filteration for broadcast
1 parent 6efe6ce commit 57748f1

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ workflows:
102102
context : org-global
103103
filters:
104104
branches:
105-
only: [dev, 'bug/community-notification']
105+
only: [dev, 'feature/broadcast2']
106106
- "build-prod":
107107
context : org-global
108108
filters:

src/common/broadcastAPIHelper.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,13 @@ async function callApi(url, machineToken) {
118118
* @param {Object} m memberInfo
119119
*
120120
*/
121-
async function checkUserSkillsAndTracks(userId, bulkMessage, m) {
121+
async function filterOnMemberCondition(userId, bulkMessage, m) {
122122
try {
123123
const skills = _.get(bulkMessage, 'recipients.skills')
124124
const tracks = _.get(bulkMessage, 'recipients.tracks')
125-
let skillMatch, trackMatch = false // default
125+
const countryCodes = _.get(bulkMessage, 'recipients.countryCodes')
126+
127+
let skillMatch, trackMatch, countryCodeMatch = false // default
126128
if (skills && skills.length > 0) {
127129
const ms = _.get(m[0], "skills") // get member skills
128130
const memberSkills = []
@@ -166,10 +168,23 @@ async function checkUserSkillsAndTracks(userId, bulkMessage, m) {
166168
} else {
167169
trackMatch = true // no condition, means allow for all
168170
}
169-
const flag = (skillMatch && trackMatch) ? true : false
171+
172+
if (countryCodes.length > 0) {
173+
const mcc = _.get(m[0], 'competitionCountryCode') // get member country code
174+
countryCodeMatch = false
175+
if (_.indexOf(countryCodes, mcc) >= 0) {
176+
countryCodeMatch = true
177+
logger.info(`BroadcastMessageId: ${bulkMessage.id},` +
178+
` '${mcc}' country code matached for user id ${userId}`)
179+
}
180+
} else {
181+
countryCodeMatch = true // no codition on country code
182+
}
183+
184+
const flag = (skillMatch && trackMatch && countryCodeMatch) ? true : false
170185
return flag
171186
} catch (e) {
172-
throw new Error(`checkUserSkillsAndTracks() : ${e}`)
187+
throw new Error(`filterOnMemberCondition() : ${e}`)
173188
}
174189
}
175190

@@ -232,7 +247,7 @@ async function checkUserGroup(userId, bulkMessage, userGroupInfo) {
232247
async function checkBroadcastMessageForUser(userId, bulkMessage, memberInfo, userGroupInfo) {
233248
return new Promise(function (resolve, reject) {
234249
Promise.all([
235-
checkUserSkillsAndTracks(userId, bulkMessage, memberInfo),
250+
filterOnMemberCondition(userId, bulkMessage, memberInfo),
236251
checkUserGroup(userId, bulkMessage, userGroupInfo),
237252
]).then((results) => {
238253
let flag = true // TODO need to be sure about default value

0 commit comments

Comments
 (0)