Skip to content

Commit 2635b6f

Browse files
authored
Merge pull request #128 from BuildFire/fix-unique-id
Fix unique
2 parents 9fa78f0 + 3a021d8 commit 2635b6f

14 files changed

+60
-54
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
# loyaltyPlugin ![](https://api.travis-ci.org/BuildFire/loyaltyPlugin.svg)
22
Loyalty
3+
4+
5+
6+
Use https://uat-loyalty.buildfire.com Server URL for uat.
7+
8+
Use https://loyalty.buildfire.com Server URL for prod.

control/content/app.services.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@
209209
currentUser = user;
210210
resolve();
211211
}).catch(err => reject(err))
212-
}),
212+
}),
213213
new Promise((resolve, reject) => {
214214
Context.getContext().then(context => {
215215
currentContext = context;
@@ -234,7 +234,7 @@
234234
})
235235
})
236236
})
237-
237+
238238
Promise.allSettled(items).then(results => {
239239
itemsList = [];
240240
results.forEach(res => {
@@ -252,7 +252,7 @@
252252
type: "danger",
253253
});
254254
}
255-
255+
256256
// reset old data
257257
deleteAll().then(() => {
258258
// save new data
@@ -270,12 +270,12 @@
270270
resolve('Error while saving data : ', err);
271271
})
272272
})
273-
})
273+
})
274274
Promise.allSettled(promises).then(res => {
275275
if (isImport) {
276276
let sortedItems = orderedItems.sort((a,b) => a.order - b.order);
277277
let sortedIds =[];
278-
LoyaltyAPI.getRewards(currentContext.instanceId).then(results => {
278+
LoyaltyAPI.getRewards(`${currentContext.appId}_${currentContext.instanceId}`).then(results => {
279279
sortedItems.forEach(item => {
280280
if (results) {
281281
results.forEach(result => {
@@ -291,11 +291,11 @@
291291
})
292292
const data = {
293293
appId: currentContext.appId,
294-
loyaltyUnqiueId: currentContext.instanceId,
294+
loyaltyUnqiueId: `${currentContext.appId}_${currentContext.instanceId}`,
295295
userToken: currentUser && currentUser.userToken,
296296
auth: currentUser && currentUser.auth,
297297
loyaltyRewardIds: sortedIds
298-
}
298+
}
299299
LoyaltyAPI.sortRewards(data).finally(() => {
300300
$timeout(() => {
301301
sortedItems = [];
@@ -326,7 +326,7 @@
326326
stateSeederInstance?.requestResult?.complete();
327327
})
328328
}
329-
329+
330330
// UTILITIES
331331
let _applyDefaults = function(item) {
332332
if (item.title) {
@@ -338,7 +338,7 @@
338338
listImage: item.listImage || "",
339339
pointsPerItem: points.pointsPerItem,
340340
appId: currentContext.appId,
341-
loyaltyUnqiueId: currentContext.instanceId,
341+
loyaltyUnqiueId: `${currentContext.appId}_${currentContext.instanceId}`,
342342
userToken: currentUser && currentUser.userToken,
343343
auth: currentUser && currentUser.auth,
344344
}
@@ -366,7 +366,7 @@
366366
}
367367

368368
let elimanateNotFoundImages = function(url) {
369-
const optimisedURL = url.replace('1080x720', '100x100');
369+
const optimisedURL = url.replace('1080x720', '100x100');
370370
return new Promise((resolve) => {
371371
if (url.includes("http")){
372372
const xhr = new XMLHttpRequest();
@@ -386,7 +386,7 @@
386386
} else resolve(false);
387387
});
388388
};
389-
389+
390390
let deleteAll = function() {
391391
const data = {
392392
userToken: currentUser.userToken,
@@ -395,9 +395,9 @@
395395
};
396396
return new Promise(resolve => {
397397
if (stateSeederInstance.requestResult.resetData){
398-
LoyaltyAPI.getRewards(currentContext.instanceId).then(items => {
398+
LoyaltyAPI.getRewards(`${currentContext.appId}_${currentContext.instanceId}`).then(items => {
399399
const promises = items.map((item) => deleteItem(item._id, data));
400-
resolve(Promise.all(promises));
400+
resolve(Promise.all(promises));
401401
}).catch(err => console.warn('old data get error', err));
402402
}
403403
else {
@@ -432,7 +432,7 @@
432432
stateSeederInstance = new buildfire.components.aiStateSeeder({
433433
generateOptions: {
434434
userMessage: `Generate a sample of redeemable items for a new [business-type].`,
435-
maxRecords: 5,
435+
maxRecords: 5,
436436
systemMessage:
437437
'listImage URL related to title and the list type. use source.unsplash.com for image URL, URL should not have premium_photo or source.unsplash.com/random, cost to redeem which is a number greater than zero and less than 100, return description as HTML.',
438438
jsonTemplate: generateJSONTemplate,
@@ -451,4 +451,4 @@
451451
},
452452
}
453453
}])
454-
})(window.angular, window.buildfire);
454+
})(window.angular, window.buildfire);

control/content/controllers/content.home.controller.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
ContentHome.defaultPassCode = '12345';
1010
var _data = {
1111
redemptionPasscode: ContentHome.defaultPassCode,
12-
unqiueId: context.instanceId,
12+
unqiueId: `${context.appId}_${context.instanceId}`,
1313
externalAppId: context.appId,
1414
appId: context.appId,
1515
name: context.pluginId,
@@ -58,7 +58,7 @@
5858
});
5959
var data = {
6060
appId: context.appId,
61-
loyaltyUnqiueId: context.instanceId,
61+
loyaltyUnqiueId: `${context.appId}_${context.instanceId}`,
6262
loyaltyRewardIds: rewardsId,
6363
userToken: ContentHome.currentLoggedInUser.userToken,
6464
auth: ContentHome.currentLoggedInUser.auth
@@ -91,7 +91,7 @@
9191
ContentHome.showRedemptionPasscodeHint = false;
9292
}
9393
if (!$scope.$$phase) $scope.$digest();
94-
updateMasterItem(ContentHome.data);
94+
updateMasterItem(ContentHome.data);
9595
if(Number(ContentHome.data.pointsPerDollar) <= 0) {
9696
ContentHome.data.pointsPerDollar = 1;
9797
saveData(JSON.parse(angular.toJson(ContentHome.data)));
@@ -150,9 +150,9 @@
150150
if (tmrDelay) clearTimeout(tmrDelay);
151151
}
152152
};
153-
LoyaltyAPI.getRewards(context.instanceId).then(ContentHome.successloyaltyRewards, ContentHome.errorloyaltyRewards);
153+
LoyaltyAPI.getRewards(`${context.appId}_${context.instanceId}`).then(ContentHome.successloyaltyRewards, ContentHome.errorloyaltyRewards);
154154
ContentHome.loyaltyRewards = [];
155-
LoyaltyAPI.getApplication(context.instanceId).then(ContentHome.success, ContentHome.error);
155+
LoyaltyAPI.getApplication(`${context.appId}_${context.instanceId}`).then(ContentHome.success, ContentHome.error);
156156
buildfire.auth.getCurrentUser(function (err, user) {
157157
console.log("!!!!!!!!!!User!!!!!!!!!!!!", user);
158158
if (user && user._cpUser) {
@@ -182,7 +182,7 @@
182182
if (tmrDelay) clearTimeout(tmrDelay);
183183
}
184184
};
185-
LoyaltyAPI.getRewards(context.instanceId).then(ContentHome.successloyaltyRewards, ContentHome.errorloyaltyRewards);
185+
LoyaltyAPI.getRewards(`${context.appId}_${context.instanceId}`).then(ContentHome.successloyaltyRewards, ContentHome.errorloyaltyRewards);
186186
}
187187
}
188188

@@ -323,7 +323,7 @@
323323
ContentHome.removeDeeplink =function(loyaltyId){
324324
Deeplink.deleteById(loyaltyId);
325325
}
326-
326+
327327
ContentHome.openReward = function (data, index) {
328328
RewardCache.setReward(data);
329329
$location.path('/reward/' + data._id + '/' + index);

control/content/controllers/content.reward.controller.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,15 @@
157157
};
158158
if(!ContentReward.item.title || ContentReward.item.title.length == 0) {
159159
ContentReward.validations.title = true;
160-
}
161-
if (((!ContentReward.item.pointsToRedeem && ContentReward.item.pointsToRedeem !== 0) || ContentReward.item.pointsToRedeem.length == 0) &&
160+
}
161+
if (((!ContentReward.item.pointsToRedeem && ContentReward.item.pointsToRedeem !== 0) || ContentReward.item.pointsToRedeem.length == 0) &&
162162
(!ContentReward.item.pointsPerItem || ContentReward.item.pointsPerItem.length == 0) ){
163163
ContentReward.validations.points = true;
164-
}
164+
}
165165
if (!ContentReward.validations.title && !ContentReward.validations.points){
166166
// "Hack" for overcoming pointsToRedeem validation if the item can only be bought but not redeemed
167-
if(ContentReward.item.pointsPerItem && ContentReward.item.pointsPerItem.length > 0
168-
&&
167+
if(ContentReward.item.pointsPerItem && ContentReward.item.pointsPerItem.length > 0
168+
&&
169169
((!ContentReward.item.pointsToRedeem && ContentReward.item.pointsToRedeem !== 0) || ContentReward.item.pointsToRedeem.length === 0 || ContentReward.item.pointsToRedeem === '38762499627')) {
170170
ContentReward.item.pointsToRedeem = '38762499627'
171171
}
@@ -181,7 +181,7 @@
181181
ContentReward.loading = true;
182182
var data = newObj;
183183
data.appId = context.appId;
184-
data.loyaltyUnqiueId = context.instanceId;
184+
data.loyaltyUnqiueId = `${context.appId}_${context.instanceId}`;
185185
data.userToken = ContentReward.currentLoggedInUser && ContentReward.currentLoggedInUser.userToken;
186186
data.auth = ContentReward.currentLoggedInUser && ContentReward.currentLoggedInUser.auth;
187187
var success = function (result) {
@@ -226,7 +226,7 @@
226226
updateMasterItem(newObj);
227227
var data = newObj;
228228
data.appId = context.appId;
229-
data.loyaltyUnqiueId = context.instanceId;
229+
data.loyaltyUnqiueId = `${context.appId}_${context.instanceId}`;
230230
data.userToken = ContentReward.currentLoggedInUser.userToken;
231231
data.auth = ContentReward.currentLoggedInUser.auth;
232232
if(newObj.pointsToRedeem != '38762499627') {
@@ -308,7 +308,7 @@
308308
ContentReward.editor.loadItems([]);
309309
changeCarouselActionItemDesign()
310310
}
311-
311+
312312
else
313313
ContentReward.editor.loadItems(ContentReward.item.carouselImage);
314314
changeCarouselActionItemDesign()

control/content/enums.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@
2626
LOYALTY_INFO: 'loyaltyInfo',
2727
NEW_CURRENCY: 'newCurrency'
2828
});
29-
})(window.angular);
29+
})(window.angular);

control/results/controllers/results.home.controller.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
ResultsHome.loading = true;
101101
Transactions.get($scope.skip).then(success, error);
102102
}
103-
103+
104104
if(!ResultsHome.noMore) {
105105
getThreads();
106106
} else {
@@ -156,7 +156,7 @@
156156
ResultsHome.exporting = true;
157157

158158
function uploadFile() {
159-
LoyaltyAPI.getApplication(context.instanceId).then(loyaltyApp => {
159+
LoyaltyAPI.getApplication(`${context.appId}_${context.instanceId}`).then(loyaltyApp => {
160160
ResultsHome.getCurrentUser().then(user => {
161161
if (user && Object.keys(user).length && loyaltyApp && Object.keys(loyaltyApp).length) {
162162
ResultsHome.currentUser = user
@@ -271,7 +271,7 @@
271271
return Promise.resolve();
272272
}
273273
});
274-
}
274+
}
275275
else {
276276
ResultsHome.openWaitingPopup(false)
277277
ResultsHome.notFoundEmails=[...data.emails]
@@ -523,7 +523,7 @@
523523
} else {
524524
init();
525525
}
526-
526+
527527
}]);
528528
})(window.angular, window.buildfire);
529529

control/settings/controllers/settings.home.controller.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,10 @@
275275
}
276276
var _data = {
277277
redemptionPasscode: isPurchaseOptionFtqSelected ? "12345" : (newObj.settings.redemptionPasscode ? newObj.settings.redemptionPasscode : '12345'),
278-
unqiueId: SettingsHome.context.instanceId,
278+
unqiueId: `${SettingsHome.context.appId}_${SettingsHome.context.instanceId}`,
279279
externalAppId: SettingsHome.context.appId,
280280
appId: SettingsHome.context.appId,
281-
name: SettingsHome.context.pluginId,
281+
name: SettingsHome.context.pluginId,
282282
pointsPerVisit: isPurchaseOptionFtqSelected ? 0 : ((typeof (newObj.settings.pointsPerVisit) != undefined && newObj.settings.pointsPerVisit != null) ? newObj.settings.pointsPerVisit : 1),
283283
pointsPerDollar: isPurchaseOptionFtqSelected ? 0 : ((typeof (newObj.settings.pointsPerDollar) != undefined && newObj.settings.pointsPerDollar != null) ? newObj.settings.pointsPerDollar : 1),
284284
totalLimit: isPurchaseOptionFtqSelected ? 50000 : ((typeof (newObj.settings.totalLimit) != undefined && newObj.settings.totalLimit != null) ? newObj.settings.totalLimit : 5000),

control/settings/enums.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@
2626
LOYALTY_INFO: 'loyaltyInfo',
2727
NEW_CURRENCY: 'newCurrency'
2828
});
29-
})(window.angular);
29+
})(window.angular);

widget/controllers/widget.approvalrequests.controller.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
message: item.data.points + " points approved for " + item.title,
108108
type: "success"
109109
});
110-
LoyaltyAPI.redeemPoints(selectedItem.data.createdBy._id, selectedItem.data.createdBy.userToken, ApprovalRequests.context.instanceId, selectedItem.data.item._id).then();
110+
LoyaltyAPI.redeemPoints(selectedItem.data.createdBy._id, selectedItem.data.createdBy.userToken, `${ApprovalRequests.context.appId}_${ApprovalRequests.context.instanceId}`, selectedItem.data.item._id).then();
111111

112112
buildfire.notifications.pushNotification.schedule(
113113
{
@@ -208,7 +208,7 @@
208208
}
209209
Transactions.updateRequestedRedeemStatus(selectedItem, status, ApprovalRequests.currentLoggedInUser.displayName ? ApprovalRequests.currentLoggedInUser.displayName : ApprovalRequests.currentLoggedInUser.email).then(success, error).then(x=>{
210210
if(status == STATUS.Approved){
211-
LoyaltyAPI.addLoyaltyPoints(selectedItem.data.createdBy._id, selectedItem.data.createdBy.userToken, ApprovalRequests.context.instanceId, ApprovalRequests.Settings.redemptionPasscode, item.data.points).then(successLoyaltyPoints, errorLoyaltyPoints);
211+
LoyaltyAPI.addLoyaltyPoints(selectedItem.data.createdBy._id, selectedItem.data.createdBy.userToken, `${ApprovalRequests.context.appId}_${ApprovalRequests.context.instanceId}`, ApprovalRequests.Settings.redemptionPasscode, item.data.points).then(successLoyaltyPoints, errorLoyaltyPoints);
212212
} else {
213213
var updatedItem = ApprovalRequests.PointResult.find(x => x.id == item.id ) ;
214214
buildfire.dialog.toast({

widget/controllers/widget.code.controller.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
console.log(currentView.reward)
103103
if (WidgetCode.application.dailyLimit > currentView.pointsToRedeem) {
104104
Buildfire.spinner.show();
105-
LoyaltyAPI.redeemPoints(WidgetCode.currentLoggedInUser._id, WidgetCode.currentLoggedInUser.userToken, WidgetCode.context.instanceId, currentView.reward._id).then(redeemSuccess, redeemFailure);
105+
LoyaltyAPI.redeemPoints(WidgetCode.currentLoggedInUser._id, WidgetCode.currentLoggedInUser.userToken, `${WidgetCode.context.appId}_${WidgetCode.context.instanceId}`, currentView.reward._id).then(redeemSuccess, redeemFailure);
106106
}
107107
else {
108108
buildfire.dialog.toast({
@@ -118,7 +118,7 @@
118118
}
119119

120120
} else {
121-
LoyaltyAPI.addLoyaltyPoints(WidgetCode.currentLoggedInUser._id, WidgetCode.currentLoggedInUser.userToken, WidgetCode.context.instanceId, WidgetCode.passcode, currentView.amount).then(success, error);
121+
LoyaltyAPI.addLoyaltyPoints(WidgetCode.currentLoggedInUser._id, WidgetCode.currentLoggedInUser.userToken, `${WidgetCode.context.appId}_${WidgetCode.context.instanceId}`, WidgetCode.passcode, currentView.amount).then(success, error);
122122
}
123123
}
124124
})
@@ -152,7 +152,7 @@
152152
};
153153

154154

155-
LoyaltyAPI.validatePasscode(WidgetCode.currentLoggedInUser.userToken, WidgetCode.context.instanceId, WidgetCode.passcode).then(success, error);
155+
LoyaltyAPI.validatePasscode(WidgetCode.currentLoggedInUser.userToken, `${WidgetCode.context.appId}_${WidgetCode.context.instanceId}`, WidgetCode.passcode).then(success, error);
156156
};
157157

158158
WidgetCode.preventClickBehavior = function (event) {

0 commit comments

Comments
 (0)