Skip to content

Commit

Permalink
fix: Optimize Fetch calls using extensions - MEED-7288 (#539)
Browse files Browse the repository at this point in the history
This change will Optimize Fetch calls using extensions

Co-authored-by: Boubaker Khanfir <boubaker.khanfir@exoplatform.com>
  • Loading branch information
2 people authored and exo-swf committed Jul 22, 2024
1 parent 8928746 commit d4eb2fb
Showing 1 changed file with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,27 @@ import {getRewardReportPeriods} from './js/service';
export function init() {
extensionRegistry.registerExtension('engagementCenterAchievements', 'achievements-extensions', {
type: 'wallet',
rewardPeriods: [],
computedCanUpdateStatus: {},
rewardReportPeriods: null,
init(from, to) {
getRewardReportPeriods(from, to, 0, -1).then(period => {
this.rewardPeriods = period;
});
this.rewardReportPeriods = getRewardReportPeriods(from, to, 0, -1);
},
canUpdateStatus(createdDate) {
return this.rewardPeriods.filter(rewardPeriod => this.isInPeriod(rewardPeriod, createdDate)).length === 0;
},
isInPeriod(period, timestamp) {
return timestamp >= period?.startDateInSeconds && timestamp <= period?.endDateInSeconds;
canUpdateStatus(createdDate, updateStatusExtension) {
if (typeof this.computedCanUpdateStatus !== 'undefined' && createdDate in this.computedCanUpdateStatus) {
return this.computedCanUpdateStatus[createdDate];
} else {
this.computedCanUpdateStatus = {};
if (updateStatusExtension !== null && typeof updateStatusExtension !== 'undefined') {
this.rewardReportPeriods = updateStatusExtension?.rewardReportPeriods;
}
this.rewardReportPeriods = (this.rewardReportPeriods === null || typeof this.rewardReportPeriods === 'undefined') ? getRewardReportPeriods(null, null, 0, -1) : this.rewardReportPeriods;
this.computedCanUpdateStatus[createdDate] = this.rewardReportPeriods
.then(period => {
this.computedCanUpdateStatus[createdDate] = period.filter(rewardPeriod => createdDate >= rewardPeriod?.startDateInSeconds && createdDate <= rewardPeriod?.endDateInSeconds).length === 0;
return this.computedCanUpdateStatus[createdDate];
});
return this.computedCanUpdateStatus[createdDate];
}
},
cannotUpdateStatusLabel: 'gamification.achievement.cannotUpdateStatus.tooltip',
});
Expand Down

0 comments on commit d4eb2fb

Please sign in to comment.