diff --git a/app/ecolyo.9a707bce3dd4c125cb58.js b/app/ecolyo.6085fc8ae835cd7aff93.js similarity index 99% rename from app/ecolyo.9a707bce3dd4c125cb58.js rename to app/ecolyo.6085fc8ae835cd7aff93.js index 1522f5e29c2518054ee32160eb7c8c7a0a6209ce..7db23ffb5d140f181869e738af1af0ff06052a79 100644 --- a/app/ecolyo.9a707bce3dd4c125cb58.js +++ b/app/ecolyo.6085fc8ae835cd7aff93.js @@ -2253,14 +2253,11 @@ var ChallengeCardOnGoing = function ChallengeCardOnGoing(_ref) { while (1) { switch (_context5.prev = _context5.next) { case 0: - _context5.next = 2; - return challengeService.isChallengeDone(userChallenge, currentDataload); - case 2: - isChallengeDone = _context5.sent; + isChallengeDone = challengeService.isChallengeDone(userChallenge, currentDataload); if (subscribed) { setIsDone(isChallengeDone.isDone); } - case 4: + case 2: case "end": return _context5.stop(); } @@ -5733,29 +5730,11 @@ var DuelService = /*#__PURE__*/function () { */ }, { key: "unlockUserDuel", - value: function () { - var _unlockUserDuel = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(userDuel) { - var updatedUserDuel; - return _regenerator.default.wrap(function _callee6$(_context6) { - while (1) { - switch (_context6.prev = _context6.next) { - case 0: - updatedUserDuel = _objectSpread(_objectSpread({}, userDuel), {}, { - state: _enums.UserDuelState.UNLOCKED - }); - return _context6.abrupt("return", updatedUserDuel); - case 2: - case "end": - return _context6.stop(); - } - } - }, _callee6); - })); - function unlockUserDuel(_x8) { - return _unlockUserDuel.apply(this, arguments); - } - return unlockUserDuel; - }() + value: function unlockUserDuel(userDuel) { + return _objectSpread(_objectSpread({}, userDuel), {}, { + state: _enums.UserDuelState.UNLOCKED + }); + } }, { key: "getFluidTypesFromStatus", value: function getFluidTypesFromStatus(fluidStatus) { @@ -5775,7 +5754,7 @@ var DuelService = /*#__PURE__*/function () { }, { key: "updateUserDuelThreshold", value: function () { - var _updateUserDuelThreshold = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee7(userDuel) { + var _updateUserDuelThreshold = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(userDuel) { var fluidStatus, consumptionService, performanceService, @@ -5786,27 +5765,27 @@ var DuelService = /*#__PURE__*/function () { updatedThreshold, updatedUserDuel, _updatedUserDuel, - _args7 = arguments; - return _regenerator.default.wrap(function _callee7$(_context7) { + _args6 = arguments; + return _regenerator.default.wrap(function _callee6$(_context6) { while (1) { - switch (_context7.prev = _context7.next) { + switch (_context6.prev = _context6.next) { case 0: - fluidStatus = _args7.length > 1 && _args7[1] !== undefined ? _args7[1] : []; + fluidStatus = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : []; consumptionService = new _consumption.default(this._client); performanceService = new _performanceIndicator.default(); fluidTypes = this.getFluidTypesFromStatus(fluidStatus); // Get last period with all days known - _context7.next = 6; + _context6.next = 6; return this.getValidPeriod(fluidStatus, fluidTypes, userDuel); case 6: - period = _context7.sent; + period = _context6.sent; if (!(period !== false)) { - _context7.next = 17; + _context6.next = 17; break; } - _context7.next = 10; + _context6.next = 10; return consumptionService.getPerformanceIndicators(period, _enums.TimeStep.DAY, fluidTypes); case 10: - fetchLastValidData = _context7.sent; + fetchLastValidData = _context6.sent; maxData = performanceService.aggregatePerformanceIndicators(fetchLastValidData); // Set the threshold if (maxData !== null && maxData !== void 0 && maxData.value && maxData.value > 0) { updatedThreshold = (0, _math.getRoundFloat)(maxData.value); @@ -5818,20 +5797,20 @@ var DuelService = /*#__PURE__*/function () { threshold: updatedThreshold, fluidTypes: fluidTypes }); - return _context7.abrupt("return", updatedUserDuel); + return _context6.abrupt("return", updatedUserDuel); case 17: _updatedUserDuel = _objectSpread(_objectSpread({}, userDuel), {}, { state: _enums.UserDuelState.NO_REF_PERIOD_VALID }); - return _context7.abrupt("return", _updatedUserDuel); + return _context6.abrupt("return", _updatedUserDuel); case 19: case "end": - return _context7.stop(); + return _context6.stop(); } } - }, _callee7, this); + }, _callee6, this); })); - function updateUserDuelThreshold(_x9) { + function updateUserDuelThreshold(_x8) { return _updateUserDuelThreshold.apply(this, arguments); } return updateUserDuelThreshold; @@ -5842,91 +5821,42 @@ var DuelService = /*#__PURE__*/function () { */ }, { key: "startUserDuel", - value: function () { - var _startUserDuel = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee8(userDuel) { - var updatedUserDuel; - return _regenerator.default.wrap(function _callee8$(_context8) { - while (1) { - switch (_context8.prev = _context8.next) { - case 0: - updatedUserDuel = _objectSpread(_objectSpread({}, userDuel), {}, { - state: _enums.UserDuelState.ONGOING, - startDate: _luxon.DateTime.local().setZone('utc', { - keepLocalTime: true - }).startOf('day') - }); - return _context8.abrupt("return", updatedUserDuel); - case 2: - case "end": - return _context8.stop(); - } - } - }, _callee8); - })); - function startUserDuel(_x10) { - return _startUserDuel.apply(this, arguments); - } - return startUserDuel; - }() + value: function startUserDuel(userDuel) { + return _objectSpread(_objectSpread({}, userDuel), {}, { + state: _enums.UserDuelState.ONGOING, + startDate: _luxon.DateTime.local().setZone('utc', { + keepLocalTime: true + }).startOf('day') + }); + } + /** * Return duel with updated state to UserDuelState.DONE * @param {UserDuel} userDuel - userDuel to update */ }, { key: "endUserDuel", - value: function () { - var _endUserDuel = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee9(userDuel) { - var updatedUserDuel; - return _regenerator.default.wrap(function _callee9$(_context9) { - while (1) { - switch (_context9.prev = _context9.next) { - case 0: - updatedUserDuel = _objectSpread(_objectSpread({}, userDuel), {}, { - state: _enums.UserDuelState.DONE - }); - return _context9.abrupt("return", updatedUserDuel); - case 2: - case "end": - return _context9.stop(); - } - } - }, _callee9); - })); - function endUserDuel(_x11) { - return _endUserDuel.apply(this, arguments); - } - return endUserDuel; - }() + value: function endUserDuel(userDuel) { + return _objectSpread(_objectSpread({}, userDuel), {}, { + state: _enums.UserDuelState.DONE + }); + } + /** * Return duel with updated state to UserDuelState.UNLOCKED * @param {UserDuel} userDuel - userDuel to reset */ }, { key: "resetUserDuel", - value: function () { - var _resetUserDuel = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee10(userDuel) { - return _regenerator.default.wrap(function _callee10$(_context10) { - while (1) { - switch (_context10.prev = _context10.next) { - case 0: - return _context10.abrupt("return", _objectSpread(_objectSpread({}, userDuel), {}, { - startDate: null, - state: _enums.UserDuelState.UNLOCKED, - threshold: 0, - userConsumption: 0 - })); - case 1: - case "end": - return _context10.stop(); - } - } - }, _callee10); - })); - function resetUserDuel(_x12) { - return _resetUserDuel.apply(this, arguments); - } - return resetUserDuel; - }() + value: function resetUserDuel(userDuel) { + return _objectSpread(_objectSpread({}, userDuel), {}, { + startDate: null, + state: _enums.UserDuelState.UNLOCKED, + threshold: 0, + userConsumption: 0 + }); + } + /** * Return duel created from duel entity * @param {DuelEntity} duel - userDuel to update @@ -5934,7 +5864,7 @@ var DuelService = /*#__PURE__*/function () { }, { key: "parseDuelEntityToDuel", value: function parseDuelEntityToDuel(duel) { - var userDuel = { + return { id: duel.id, title: duel.title, description: duel.description, @@ -5945,7 +5875,6 @@ var DuelService = /*#__PURE__*/function () { fluidTypes: [], userConsumption: 0 }; - return userDuel; } /** @@ -9049,16 +8978,13 @@ var QuizQuestionContent = function QuizQuestionContent(_ref) { }); setAnswerIndex(resultIndex); setOpenModal(true); - _context.next = 6; - return quizService.updateUserQuiz(userChallenge.quiz, result[0].isTrue, questionIndex); - case 6: - quizUpdated = _context.sent; - _context.next = 9; + quizUpdated = quizService.updateUserQuiz(userChallenge.quiz, result[0].isTrue, questionIndex); + _context.next = 7; return challengeService.updateUserChallenge(userChallenge, _enums.UserChallengeUpdateFlag.QUIZ_UPDATE, quizUpdated); - case 9: + case 7: userChallengeUpdated = _context.sent; dispatch((0, _challenge2.updateUserChallengeList)(userChallengeUpdated)); - case 11: + case 9: case "end": return _context.stop(); } @@ -9912,16 +9838,13 @@ var QuizQuestionContentCustom = function QuizQuestionContentCustom(_ref) { result = customQuestion.answers.filter(function (answer) { return answer.answerLabel === userChoice; }); - _context.next = 6; - return quizService.updateUserQuiz(userChallenge.quiz, result[0].isTrue); - case 6: - quizUpdated = _context.sent; - _context.next = 9; + quizUpdated = quizService.updateUserQuiz(userChallenge.quiz, result[0].isTrue); + _context.next = 7; return challengeService.updateUserChallenge(userChallenge, _enums.UserChallengeUpdateFlag.QUIZ_UPDATE, quizUpdated); - case 9: + case 7: userChallengeUpdated = _context.sent; dispatch((0, _challenge2.updateUserChallengeList)(userChallengeUpdated)); - case 11: + case 9: case "end": return _context.stop(); } @@ -11019,7 +10942,7 @@ var SplashRoot = function SplashRoot(_ref) { Sentry.startSpan({ name: 'Initialize app' }, /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee7() { - var initializationService, customPopupService, partnersInfoService, ms, _yield$Promise$all, _yield$Promise$all2, termsStatus, profile, profileType, profileEcogesture, fluidStatus, migrationsResult, _yield$Promise$all3, _yield$Promise$all4, duelHash, quizHash, challengeHash, explorationHash, analysisResult, updatedProfile, lastDataDate, _iterator, _step, fluid, userChallengeList, _filteredCurrentOngoi, _filteredCurrentOngoi2, _filteredCurrentOngoi3, _filteredCurrentDuelC, filteredCurrentOngoingChallenge, actionService, updatedUserChallenge, filteredCurrentDuelChallenge, _yield$initialization, _updatedUserChallenge, dataloads, challengeService, _yield$challengeServi, isDone; + var initializationService, customPopupService, partnersInfoService, ms, _yield$Promise$all, _yield$Promise$all2, termsStatus, profile, profileType, profileEcogesture, fluidStatus, migrationsResult, _yield$Promise$all3, _yield$Promise$all4, duelHash, quizHash, challengeHash, explorationHash, analysisResult, updatedProfile, lastDataDate, _iterator, _step, fluid, userChallengeList, _filteredCurrentOngoi, _filteredCurrentOngoi2, _filteredCurrentOngoi3, _filteredCurrentDuelC, filteredCurrentOngoingChallenge, actionService, updatedUserChallenge, filteredCurrentDuelChallenge, _yield$initialization, _updatedUserChallenge, dataloads, challengeService, _challengeService$isC, isDone; return _regenerator.default.wrap(function _callee7$(_context7) { while (1) { switch (_context7.prev = _context7.next) { @@ -11116,7 +11039,7 @@ var SplashRoot = function SplashRoot(_ref) { case 45: userChallengeList = _context7.sent; if (!subscribed) { - _context7.next = 72; + _context7.next = 65; break; } dispatch((0, _challenge2.setUserChallengeList)(userChallengeList)); @@ -11148,7 +11071,7 @@ var SplashRoot = function SplashRoot(_ref) { return challenge.state === _enums.UserChallengeState.DUEL; }); if (!(((_filteredCurrentDuelC = filteredCurrentDuelChallenge[0]) === null || _filteredCurrentDuelC === void 0 ? void 0 : _filteredCurrentDuelC.duel.state) === _enums.UserDuelState.ONGOING)) { - _context7.next = 72; + _context7.next = 65; break; } _context7.next = 61; @@ -11157,23 +11080,17 @@ var SplashRoot = function SplashRoot(_ref) { _yield$initialization = _context7.sent; _updatedUserChallenge = _yield$initialization.updatedUserChallenge; dataloads = _yield$initialization.dataloads; - if (!subscribed) { - _context7.next = 72; - break; + if (subscribed) { + dispatch((0, _challenge2.setChallengeConsumption)({ + userChallenge: _updatedUserChallenge, + currentDataload: dataloads + })); + // Check is duel is done and display notification + challengeService = new _challenge.default(client); + _challengeService$isC = challengeService.isChallengeDone(_updatedUserChallenge, dataloads), isDone = _challengeService$isC.isDone; + dispatch((0, _global.toggleChallengeDuelNotification)(isDone)); } - dispatch((0, _challenge2.setChallengeConsumption)({ - userChallenge: _updatedUserChallenge, - currentDataload: dataloads - })); - // Check is duel is done and display notification - challengeService = new _challenge.default(client); - _context7.next = 69; - return challengeService.isChallengeDone(_updatedUserChallenge, dataloads); - case 69: - _yield$challengeServi = _context7.sent; - isDone = _yield$challengeServi.isDone; - dispatch((0, _global.toggleChallengeDuelNotification)(isDone)); - case 72: + case 65: /** * Load custom popup and partners info synchronously so these treatments don't block the loading */ @@ -11234,26 +11151,26 @@ var SplashRoot = function SplashRoot(_ref) { }); }); } - _context7.next = 82; + _context7.next = 75; break; - case 77: - _context7.prev = 77; + case 70: + _context7.prev = 70; _context7.t0 = _context7["catch"](4); if (_context7.t0.message === 'Failed to fetch' && !initStepErrors) { setInitStepErrors(_models.InitStepsErrors.UNKNOWN_ERROR); } _logger.default.error("[Initialization] Error : ".concat(_context7.t0)); Sentry.captureException(_context7.t0); - case 82: - _context7.prev = 82; + case 75: + _context7.prev = 75; console.groupEnd(); - return _context7.finish(82); - case 85: + return _context7.finish(75); + case 78: case "end": return _context7.stop(); } } - }, _callee7, null, [[4, 77, 82, 85]]); + }, _callee7, null, [[4, 70, 75, 78]]); }))); case 2: case "end": @@ -12247,31 +12164,16 @@ var ChallengeService = /*#__PURE__*/function () { */ }, { key: "isExplorationConditionVerified", - value: function () { - var _isExplorationConditionVerified = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(exploration, fluidStatus) { - var isValid, fluidCondition; - return _regenerator.default.wrap(function _callee$(_context) { - while (1) { - switch (_context.prev = _context.next) { - case 0: - isValid = false; - fluidCondition = exploration.fluid_condition; // check if the fluid is connected - if (fluidStatus[fluidCondition[0]].status !== _enums.FluidState.KONNECTOR_NOT_FOUND && fluidStatus[fluidCondition[0]].status !== _enums.FluidState.NOT_CONNECTED) { - isValid = true; - } - return _context.abrupt("return", isValid); - case 4: - case "end": - return _context.stop(); - } - } - }, _callee); - })); - function isExplorationConditionVerified(_x, _x2) { - return _isExplorationConditionVerified.apply(this, arguments); + value: function isExplorationConditionVerified(exploration, fluidStatus) { + var isValid = false; + var fluidCondition = exploration.fluid_condition; + // check if the fluid is connected + if (fluidStatus[fluidCondition[0]].status !== _enums.FluidState.KONNECTOR_NOT_FOUND && fluidStatus[fluidCondition[0]].status !== _enums.FluidState.NOT_CONNECTED) { + isValid = true; } - return isExplorationConditionVerified; - }() + return isValid; + } + /** * * @param {ChallengeEntity} challenge - get all relations entities of a challenge @@ -12279,11 +12181,11 @@ var ChallengeService = /*#__PURE__*/function () { }, { key: "getRelationEntities", value: function () { - var _getRelationEntities = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(challenge) { + var _getRelationEntities = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(challenge) { var duelEntityRelation, quizEntityRelation, explorationEntityRelation, result; - return _regenerator.default.wrap(function _callee2$(_context2) { + return _regenerator.default.wrap(function _callee$(_context) { while (1) { - switch (_context2.prev = _context2.next) { + switch (_context.prev = _context.next) { case 0: duelEntityRelation = (0, _utils.getRelationship)(challenge, 'duel'); quizEntityRelation = (0, _utils.getRelationship)(challenge, 'quiz'); @@ -12293,15 +12195,15 @@ var ChallengeService = /*#__PURE__*/function () { quizEntityRelation: quizEntityRelation, explorationEntityRelation: explorationEntityRelation }; - return _context2.abrupt("return", result); + return _context.abrupt("return", result); case 5: case "end": - return _context2.stop(); + return _context.stop(); } } - }, _callee2); + }, _callee); })); - function getRelationEntities(_x3) { + function getRelationEntities(_x) { return _getRelationEntities.apply(this, arguments); } return getRelationEntities; @@ -12311,46 +12213,22 @@ var ChallengeService = /*#__PURE__*/function () { */ }, { key: "getUpdatedUserChallengeIfExplorationConditionIsValid", - value: function () { - var _getUpdatedUserChallengeIfExplorationConditionIsValid = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(exploration, challenge, duel, quiz, fluidStatus) { - var userChallenge, isConditionVerified; - return _regenerator.default.wrap(function _callee3$(_context3) { - while (1) { - switch (_context3.prev = _context3.next) { - case 0: - userChallenge = null; // Check if it's a conditional exploration - if (!(exploration.fluid_condition.length > 0)) { - _context3.next = 10; - break; - } - _context3.next = 4; - return this.isExplorationConditionVerified(exploration, fluidStatus); - case 4: - isConditionVerified = _context3.sent; - if (!isConditionVerified) { - _context3.next = 8; - break; - } - userChallenge = this.parseChallengeEntityToUserChallenge(challenge, duel, quiz, exploration); - return _context3.abrupt("return", userChallenge); - case 8: - _context3.next = 12; - break; - case 10: - userChallenge = this.parseChallengeEntityToUserChallenge(challenge, duel, quiz, exploration); - return _context3.abrupt("return", userChallenge); - case 12: - case "end": - return _context3.stop(); - } - } - }, _callee3, this); - })); - function getUpdatedUserChallengeIfExplorationConditionIsValid(_x4, _x5, _x6, _x7, _x8) { - return _getUpdatedUserChallengeIfExplorationConditionIsValid.apply(this, arguments); + value: function getUpdatedUserChallengeIfExplorationConditionIsValid(exploration, challenge, duel, quiz, fluidStatus) { + var userChallenge = null; + // Check if it's a conditional exploration + if (exploration.fluid_condition.length > 0) { + var isConditionVerified = this.isExplorationConditionVerified(exploration, fluidStatus); + // if condition is verified, add exploration to UserChallenge and return it + if (isConditionVerified) { + userChallenge = this.parseChallengeEntityToUserChallenge(challenge, duel, quiz, exploration); + return userChallenge; + } + } // if there is no condition, add the exploration + else { + userChallenge = this.parseChallengeEntityToUserChallenge(challenge, duel, quiz, exploration); + return userChallenge; } - return getUpdatedUserChallengeIfExplorationConditionIsValid; - }() + } /** * The whole exploration process, checks if the exploration fluid condition exists and is valid for each existing * Exploration related to given challenge @@ -12358,76 +12236,41 @@ var ChallengeService = /*#__PURE__*/function () { */ }, { key: "processExploration", - value: function () { - var _processExploration = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(explorationEntities, explorationEntityRelation, challenge, duel, quiz, buildList, fluidStatus) { - var explorationService, _iterator, _step, explorationRelation, exploration, userChallenge; - return _regenerator.default.wrap(function _callee4$(_context4) { - while (1) { - switch (_context4.prev = _context4.next) { - case 0: - explorationService = new _exploration.default(this._client); - _iterator = _createForOfIteratorHelper(explorationEntityRelation); - _context4.prev = 2; - _iterator.s(); - case 4: - if ((_step = _iterator.n()).done) { - _context4.next = 15; - break; - } - explorationRelation = _step.value; - exploration = explorationService.getUserExplorationFromExplorationEntities(explorationEntities || [], explorationRelation._id); - _context4.next = 9; - return this.getUpdatedUserChallengeIfExplorationConditionIsValid(exploration, challenge, duel, quiz, fluidStatus); - case 9: - userChallenge = _context4.sent; - if (!userChallenge) { - _context4.next = 13; - break; - } - buildList.push(userChallenge); - return _context4.abrupt("break", 15); - case 13: - _context4.next = 4; - break; - case 15: - _context4.next = 20; - break; - case 17: - _context4.prev = 17; - _context4.t0 = _context4["catch"](2); - _iterator.e(_context4.t0); - case 20: - _context4.prev = 20; - _iterator.f(); - return _context4.finish(20); - case 23: - return _context4.abrupt("return", buildList); - case 24: - case "end": - return _context4.stop(); - } + value: function processExploration(explorationEntities, explorationEntityRelation, challenge, duel, quiz, buildList, fluidStatus) { + var explorationService = new _exploration.default(this._client); + var _iterator = _createForOfIteratorHelper(explorationEntityRelation), + _step; + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var explorationRelation = _step.value; + var exploration = explorationService.getUserExplorationFromExplorationEntities(explorationEntities || [], explorationRelation._id); + var userChallenge = this.getUpdatedUserChallengeIfExplorationConditionIsValid(exploration, challenge, duel, quiz, fluidStatus); + if (userChallenge) { + buildList.push(userChallenge); + break; } - }, _callee4, this, [[2, 17, 20, 23]]); - })); - function processExploration(_x9, _x10, _x11, _x12, _x13, _x14, _x15) { - return _processExploration.apply(this, arguments); + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); } - return processExploration; - }() + return buildList; + } /** * Checks if the exploration condition exists and is valid when updating the buildList */ }, { key: "loopVerificationExplorationCondition", value: function () { - var _loopVerificationExplorationCondition = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(userChallenge, challengeEntityList, fluidStatus) { + var _loopVerificationExplorationCondition = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(userChallenge, challengeEntityList, fluidStatus) { var currentEntity, relationsArray, explorationService, updatedUserChallenge, _iterator2, _step2, relation, newExploEntity, newUserExplo, isConditionValid; - return _regenerator.default.wrap(function _callee5$(_context5) { + return _regenerator.default.wrap(function _callee2$(_context2) { while (1) { - switch (_context5.prev = _context5.next) { + switch (_context2.prev = _context2.next) { case 0: if (!(userChallenge.exploration.state === _enums.UserExplorationState.UNLOCKED)) { - _context5.next = 36; + _context2.next = 34; break; } currentEntity = challengeEntityList.filter(function (challenge) { @@ -12437,69 +12280,66 @@ var ChallengeService = /*#__PURE__*/function () { explorationService = new _exploration.default(this._client); updatedUserChallenge = _objectSpread({}, userChallenge); _iterator2 = _createForOfIteratorHelper(relationsArray.data); - _context5.prev = 6; + _context2.prev = 6; _iterator2.s(); case 8: if ((_step2 = _iterator2.n()).done) { - _context5.next = 27; + _context2.next = 25; break; } relation = _step2.value; - _context5.next = 12; + _context2.next = 12; return explorationService.getExplorationEntityById(relation._id); case 12: - newExploEntity = _context5.sent; + newExploEntity = _context2.sent; newUserExplo = explorationService.parseExplorationEntityToUserExploration(newExploEntity); if (!(newExploEntity.fluid_condition.length > 0)) { - _context5.next = 23; + _context2.next = 21; break; } - _context5.next = 17; - return this.isExplorationConditionVerified(newExploEntity, fluidStatus); - case 17: - isConditionValid = _context5.sent; + isConditionValid = this.isExplorationConditionVerified(newExploEntity, fluidStatus); if (!isConditionValid) { - _context5.next = 21; + _context2.next = 19; break; } updatedUserChallenge = _objectSpread(_objectSpread({}, updatedUserChallenge), {}, { exploration: newUserExplo }); - return _context5.abrupt("break", 27); - case 21: - _context5.next = 25; + return _context2.abrupt("break", 25); + case 19: + _context2.next = 23; break; - case 23: + case 21: updatedUserChallenge = _objectSpread(_objectSpread({}, updatedUserChallenge), {}, { exploration: newUserExplo }); - return _context5.abrupt("break", 27); + return _context2.abrupt("break", 25); + case 23: + _context2.next = 8; + break; case 25: - _context5.next = 8; + _context2.next = 30; break; case 27: - _context5.next = 32; - break; - case 29: - _context5.prev = 29; - _context5.t0 = _context5["catch"](6); - _iterator2.e(_context5.t0); - case 32: - _context5.prev = 32; + _context2.prev = 27; + _context2.t0 = _context2["catch"](6); + _iterator2.e(_context2.t0); + case 30: + _context2.prev = 30; _iterator2.f(); - return _context5.finish(32); + return _context2.finish(30); + case 33: + return _context2.abrupt("return", updatedUserChallenge); + case 34: + return _context2.abrupt("return", userChallenge); case 35: - return _context5.abrupt("return", updatedUserChallenge); - case 36: - return _context5.abrupt("return", userChallenge); - case 37: case "end": - return _context5.stop(); + return _context2.stop(); } } - }, _callee5, this, [[6, 29, 32, 35]]); + }, _callee2, this, [[6, 27, 30, 33]]); })); - function loopVerificationExplorationCondition(_x16, _x17, _x18) { + function loopVerificationExplorationCondition(_x2, _x3, _x4) { return _loopVerificationExplorationCondition.apply(this, arguments); } return loopVerificationExplorationCondition; @@ -12510,167 +12350,163 @@ var ChallengeService = /*#__PURE__*/function () { }, { key: "buildUserChallengeList", value: function () { - var _buildUserChallengeList = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(fluidStatus) { + var _buildUserChallengeList = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(fluidStatus) { var _this = this; var queryChallengeEntity, querySeasonEntityIncludeQuiz, querySeasonEntityIncludeExploration, _yield$this$_client$q, challengeEntityList, duelEntities, _yield$this$_client$q2, explorationEntities, _yield$this$_client$q3, quizEntities, userChallengeList, duelService, quizService, explorationService, buildList, _iterator3, _step3, challenge, relationEntities, duel, quiz, exploration, userChallenge, _iterator4, _step4, _loop; - return _regenerator.default.wrap(function _callee6$(_context7) { + return _regenerator.default.wrap(function _callee3$(_context4) { while (1) { - switch (_context7.prev = _context7.next) { + switch (_context4.prev = _context4.next) { case 0: queryChallengeEntity = (0, _cozyClient.Q)(_doctypes.CHALLENGE_DOCTYPE).include(['duel']); querySeasonEntityIncludeQuiz = (0, _cozyClient.Q)(_doctypes.CHALLENGE_DOCTYPE).include(['quiz']); querySeasonEntityIncludeExploration = (0, _cozyClient.Q)(_doctypes.CHALLENGE_DOCTYPE).include(['exploration']); - _context7.next = 5; + _context4.next = 5; return this._client.query(queryChallengeEntity); case 5: - _yield$this$_client$q = _context7.sent; + _yield$this$_client$q = _context4.sent; challengeEntityList = _yield$this$_client$q.data; duelEntities = _yield$this$_client$q.included; - _context7.next = 10; + _context4.next = 10; return this._client.query(querySeasonEntityIncludeExploration); case 10: - _yield$this$_client$q2 = _context7.sent; + _yield$this$_client$q2 = _context4.sent; explorationEntities = _yield$this$_client$q2.included; - _context7.next = 14; + _context4.next = 14; return this._client.query(querySeasonEntityIncludeQuiz); case 14: - _yield$this$_client$q3 = _context7.sent; + _yield$this$_client$q3 = _context4.sent; quizEntities = _yield$this$_client$q3.included; - _context7.next = 18; + _context4.next = 18; return this.getAllUserChallengeEntities(); case 18: - userChallengeList = _context7.sent; + userChallengeList = _context4.sent; duelService = new _duel2.default(this._client); quizService = new _quiz2.default(this._client); explorationService = new _exploration.default(this._client); buildList = []; // Case UserChallengeList is empty if (!(challengeEntityList.length > 0 && userChallengeList.length === 0)) { - _context7.next = 55; + _context4.next = 48; break; } _iterator3 = _createForOfIteratorHelper(challengeEntityList); - _context7.prev = 25; + _context4.prev = 25; _iterator3.s(); case 27: if ((_step3 = _iterator3.n()).done) { - _context7.next = 44; + _context4.next = 37; break; } challenge = _step3.value; - _context7.next = 31; + _context4.next = 31; return this.getRelationEntities(challenge); case 31: - relationEntities = _context7.sent; + relationEntities = _context4.sent; duel = duelService.getDuelFromDuelEntities(duelEntities || [], relationEntities.duelEntityRelation._id); quiz = quizService.getUserQuizFromQuizEntities(quizEntities || [], relationEntities.quizEntityRelation._id); // Only one exploration relation - if (!(relationEntities.explorationEntityRelation.length === 1)) { - _context7.next = 40; - break; + if (relationEntities.explorationEntityRelation.length === 1) { + exploration = explorationService.getUserExplorationFromExplorationEntities(explorationEntities || [], relationEntities.explorationEntityRelation[0]._id); + userChallenge = this.parseChallengeEntityToUserChallenge(challenge, duel, quiz, exploration); + buildList.push(userChallenge); } - exploration = explorationService.getUserExplorationFromExplorationEntities(explorationEntities || [], relationEntities.explorationEntityRelation[0]._id); - userChallenge = this.parseChallengeEntityToUserChallenge(challenge, duel, quiz, exploration); - buildList.push(userChallenge); - _context7.next = 42; - break; - case 40: - _context7.next = 42; - return this.processExploration(explorationEntities, relationEntities.explorationEntityRelation, challenge, duel, quiz, buildList, fluidStatus); - case 42: - _context7.next = 27; + // Several explorations with fluid condition + else { + this.processExploration(explorationEntities, relationEntities.explorationEntityRelation, challenge, duel, quiz, buildList, fluidStatus); + } + case 35: + _context4.next = 27; break; - case 44: - _context7.next = 49; + case 37: + _context4.next = 42; break; - case 46: - _context7.prev = 46; - _context7.t0 = _context7["catch"](25); - _iterator3.e(_context7.t0); - case 49: - _context7.prev = 49; + case 39: + _context4.prev = 39; + _context4.t0 = _context4["catch"](25); + _iterator3.e(_context4.t0); + case 42: + _context4.prev = 42; _iterator3.f(); - return _context7.finish(49); - case 52: + return _context4.finish(42); + case 45: buildList = this.unLockCurrentUserChallenge(buildList); - _context7.next = 73; + _context4.next = 66; break; - case 55: + case 48: if (!(challengeEntityList.length > 0 && userChallengeList.length > 0)) { - _context7.next = 73; + _context4.next = 66; break; } _iterator4 = _createForOfIteratorHelper(challengeEntityList); - _context7.prev = 57; + _context4.prev = 50; _loop = /*#__PURE__*/_regenerator.default.mark(function _loop() { var challenge, userChallengeIndex, _userChallenge2, _relationEntities, _duel, _quiz; - return _regenerator.default.wrap(function _loop$(_context6) { + return _regenerator.default.wrap(function _loop$(_context3) { while (1) { - switch (_context6.prev = _context6.next) { + switch (_context3.prev = _context3.next) { case 0: challenge = _step4.value; userChallengeIndex = userChallengeList.findIndex(function (entity) { return entity.id === challenge.id; }); if (!(userChallengeIndex >= 0)) { - _context6.next = 10; + _context3.next = 10; break; } _userChallenge2 = userChallengeList[userChallengeIndex]; - _context6.next = 6; + _context3.next = 6; return _this.loopVerificationExplorationCondition(_userChallenge2, challengeEntityList, fluidStatus); case 6: - _userChallenge2 = _context6.sent; + _userChallenge2 = _context3.sent; buildList.push(_userChallenge2); - _context6.next = 17; + _context3.next = 16; break; case 10: - _context6.next = 12; + _context3.next = 12; return _this.getRelationEntities(challenge); case 12: - _relationEntities = _context6.sent; + _relationEntities = _context3.sent; _duel = duelService.getDuelFromDuelEntities(duelEntities || [], _relationEntities.duelEntityRelation._id); _quiz = quizService.getUserQuizFromQuizEntities(quizEntities || [], _relationEntities.quizEntityRelation._id); - _context6.next = 17; - return _this.processExploration(explorationEntities, _relationEntities.explorationEntityRelation, challenge, _duel, _quiz, buildList, fluidStatus); - case 17: + _this.processExploration(explorationEntities, _relationEntities.explorationEntityRelation, challenge, _duel, _quiz, buildList, fluidStatus); + case 16: case "end": - return _context6.stop(); + return _context3.stop(); } } }, _loop); }); _iterator4.s(); - case 60: + case 53: if ((_step4 = _iterator4.n()).done) { - _context7.next = 64; + _context4.next = 57; break; } - return _context7.delegateYield(_loop(), "t1", 62); - case 62: - _context7.next = 60; + return _context4.delegateYield(_loop(), "t1", 55); + case 55: + _context4.next = 53; break; - case 64: - _context7.next = 69; + case 57: + _context4.next = 62; break; - case 66: - _context7.prev = 66; - _context7.t2 = _context7["catch"](57); - _iterator4.e(_context7.t2); - case 69: - _context7.prev = 69; + case 59: + _context4.prev = 59; + _context4.t2 = _context4["catch"](50); + _iterator4.e(_context4.t2); + case 62: + _context4.prev = 62; _iterator4.f(); - return _context7.finish(69); - case 72: + return _context4.finish(62); + case 65: buildList = this.unLockCurrentUserChallenge(buildList); - case 73: - return _context7.abrupt("return", buildList); - case 74: + case 66: + return _context4.abrupt("return", buildList); + case 67: case "end": - return _context7.stop(); + return _context4.stop(); } } - }, _callee6, this, [[25, 46, 49, 52], [57, 66, 69, 72]]); + }, _callee3, this, [[25, 39, 42, 45], [50, 59, 62, 65]]); })); - function buildUserChallengeList(_x19) { + function buildUserChallengeList(_x5) { return _buildUserChallengeList.apply(this, arguments); } return buildUserChallengeList; @@ -12681,25 +12517,25 @@ var ChallengeService = /*#__PURE__*/function () { }, { key: "getAllChallengeEntities", value: function () { - var _getAllChallengeEntities = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee7() { + var _getAllChallengeEntities = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4() { var query, _yield$this$_client$q4, challenges; - return _regenerator.default.wrap(function _callee7$(_context8) { + return _regenerator.default.wrap(function _callee4$(_context5) { while (1) { - switch (_context8.prev = _context8.next) { + switch (_context5.prev = _context5.next) { case 0: query = (0, _cozyClient.Q)(_doctypes.CHALLENGE_DOCTYPE); - _context8.next = 3; + _context5.next = 3; return this._client.query(query); case 3: - _yield$this$_client$q4 = _context8.sent; + _yield$this$_client$q4 = _context5.sent; challenges = _yield$this$_client$q4.data; - return _context8.abrupt("return", challenges); + return _context5.abrupt("return", challenges); case 6: case "end": - return _context8.stop(); + return _context5.stop(); } } - }, _callee7, this); + }, _callee4, this); })); function getAllChallengeEntities() { return _getAllChallengeEntities.apply(this, arguments); @@ -12713,64 +12549,64 @@ var ChallengeService = /*#__PURE__*/function () { }, { key: "deleteAllChallengeEntities", value: function () { - var _deleteAllChallengeEntities = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee8() { + var _deleteAllChallengeEntities = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5() { var challengeEntity, _iterator5, _step5, entity, errorMessage; - return _regenerator.default.wrap(function _callee8$(_context9) { + return _regenerator.default.wrap(function _callee5$(_context6) { while (1) { - switch (_context9.prev = _context9.next) { + switch (_context6.prev = _context6.next) { case 0: - _context9.prev = 0; - _context9.next = 3; + _context6.prev = 0; + _context6.next = 3; return this.getAllChallengeEntities(); case 3: - challengeEntity = _context9.sent; + challengeEntity = _context6.sent; if (challengeEntity) { - _context9.next = 6; + _context6.next = 6; break; } - return _context9.abrupt("return", true); + return _context6.abrupt("return", true); case 6: _iterator5 = _createForOfIteratorHelper(challengeEntity); - _context9.prev = 7; + _context6.prev = 7; _iterator5.s(); case 9: if ((_step5 = _iterator5.n()).done) { - _context9.next = 15; + _context6.next = 15; break; } entity = _step5.value; - _context9.next = 13; + _context6.next = 13; return this._client.destroy(entity); case 13: - _context9.next = 9; + _context6.next = 9; break; case 15: - _context9.next = 20; + _context6.next = 20; break; case 17: - _context9.prev = 17; - _context9.t0 = _context9["catch"](7); - _iterator5.e(_context9.t0); + _context6.prev = 17; + _context6.t0 = _context6["catch"](7); + _iterator5.e(_context6.t0); case 20: - _context9.prev = 20; + _context6.prev = 20; _iterator5.f(); - return _context9.finish(20); + return _context6.finish(20); case 23: - return _context9.abrupt("return", true); + return _context6.abrupt("return", true); case 26: - _context9.prev = 26; - _context9.t1 = _context9["catch"](0); - errorMessage = "deleteAllChallengeEntities :".concat(JSON.stringify(_context9.t1)); + _context6.prev = 26; + _context6.t1 = _context6["catch"](0); + errorMessage = "deleteAllChallengeEntities :".concat(JSON.stringify(_context6.t1)); logStack('error', errorMessage); _logger.default.error(errorMessage); - Sentry.captureException(_context9.t1); - throw _context9.t1; + Sentry.captureException(_context6.t1); + throw _context6.t1; case 33: case "end": - return _context9.stop(); + return _context6.stop(); } } - }, _callee8, this, [[0, 26], [7, 17, 20, 23]]); + }, _callee5, this, [[0, 26], [7, 17, 20, 23]]); })); function deleteAllChallengeEntities() { return _deleteAllChallengeEntities.apply(this, arguments); @@ -12783,29 +12619,29 @@ var ChallengeService = /*#__PURE__*/function () { }, { key: "getAllUserChallengeEntities", value: function () { - var _getAllUserChallengeEntities = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee9() { + var _getAllUserChallengeEntities = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6() { var _this2 = this; var query, _yield$this$_client$q5, userChallengeEntities, userChallenges; - return _regenerator.default.wrap(function _callee9$(_context10) { + return _regenerator.default.wrap(function _callee6$(_context7) { while (1) { - switch (_context10.prev = _context10.next) { + switch (_context7.prev = _context7.next) { case 0: query = (0, _cozyClient.Q)(_doctypes.USERCHALLENGE_DOCTYPE); - _context10.next = 3; + _context7.next = 3; return this._client.query(query); case 3: - _yield$this$_client$q5 = _context10.sent; + _yield$this$_client$q5 = _context7.sent; userChallengeEntities = _yield$this$_client$q5.data; userChallenges = userChallengeEntities.map(function (userChallengeEntity) { return _this2.parseUserChallengeEntityToUserChallenge(userChallengeEntity); }); - return _context10.abrupt("return", userChallenges); + return _context7.abrupt("return", userChallenges); case 7: case "end": - return _context10.stop(); + return _context7.stop(); } } - }, _callee9, this); + }, _callee6, this); })); function getAllUserChallengeEntities() { return _getAllUserChallengeEntities.apply(this, arguments); @@ -12820,48 +12656,48 @@ var ChallengeService = /*#__PURE__*/function () { }, { key: "initChallengeDuelProgress", value: function () { - var _initChallengeDuelProgress = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee10(userChallenge) { + var _initChallengeDuelProgress = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee7(userChallenge) { var consumptionService, dataloads, userConsumption, _userChallenge, updatedUserChallenge, errorMessage; - return _regenerator.default.wrap(function _callee10$(_context11) { + return _regenerator.default.wrap(function _callee7$(_context8) { while (1) { - switch (_context11.prev = _context11.next) { + switch (_context8.prev = _context8.next) { case 0: consumptionService = new _consumption.default(this._client); - _context11.prev = 1; - _context11.next = 4; + _context8.prev = 1; + _context8.next = 4; return this.getUserChallengeDataload(userChallenge); case 4: - dataloads = _context11.sent; + dataloads = _context8.sent; userConsumption = (0, _math.getRoundFloat)(consumptionService.calculatePerformanceIndicatorValue(dataloads)); _userChallenge = _objectSpread(_objectSpread({}, userChallenge), {}, { duel: _objectSpread(_objectSpread({}, userChallenge.duel), {}, { userConsumption: userConsumption }) }); - _context11.next = 9; + _context8.next = 9; return this.updateUserChallenge(_userChallenge, _enums.UserChallengeUpdateFlag.DUEL_CONSUMPTION); case 9: - updatedUserChallenge = _context11.sent; - return _context11.abrupt("return", { + updatedUserChallenge = _context8.sent; + return _context8.abrupt("return", { updatedUserChallenge: updatedUserChallenge, dataloads: dataloads }); case 13: - _context11.prev = 13; - _context11.t0 = _context11["catch"](1); - errorMessage = "Challenge service error on initChallengeDuelProgress: ".concat(JSON.stringify(_context11.t0)); + _context8.prev = 13; + _context8.t0 = _context8["catch"](1); + errorMessage = "Challenge service error on initChallengeDuelProgress: ".concat(JSON.stringify(_context8.t0)); logStack('error', errorMessage); _logger.default.error(errorMessage); - Sentry.captureException(_context11.t0); - throw _context11.t0; + Sentry.captureException(_context8.t0); + throw _context8.t0; case 20: case "end": - return _context11.stop(); + return _context8.stop(); } } - }, _callee10, this, [[1, 13]]); + }, _callee7, this, [[1, 13]]); })); - function initChallengeDuelProgress(_x20) { + function initChallengeDuelProgress(_x6) { return _initChallengeDuelProgress.apply(this, arguments); } return initChallengeDuelProgress; @@ -12873,11 +12709,11 @@ var ChallengeService = /*#__PURE__*/function () { }, { key: "startUserChallenge", value: function () { - var _startUserChallenge = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee11(userChallenge) { + var _startUserChallenge = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee8(userChallenge) { var newChallenge, _yield$this$_client$c, updatedUserChallengeEntity, updatedUserChallenge, errorMessage; - return _regenerator.default.wrap(function _callee11$(_context12) { + return _regenerator.default.wrap(function _callee8$(_context9) { while (1) { - switch (_context12.prev = _context12.next) { + switch (_context9.prev = _context9.next) { case 0: newChallenge = _objectSpread(_objectSpread({}, userChallenge), {}, { state: _enums.UserChallengeState.ONGOING, @@ -12891,30 +12727,30 @@ var ChallengeService = /*#__PURE__*/function () { }).startOf('day'), success: _enums.UserChallengeSuccess.ONGOING }); - _context12.prev = 1; - _context12.next = 4; + _context9.prev = 1; + _context9.next = 4; return this._client.create(_doctypes.USERCHALLENGE_DOCTYPE, newChallenge); case 4: - _yield$this$_client$c = _context12.sent; + _yield$this$_client$c = _context9.sent; updatedUserChallengeEntity = _yield$this$_client$c.data; updatedUserChallenge = this.parseUserChallengeEntityToUserChallenge(updatedUserChallengeEntity); - return _context12.abrupt("return", updatedUserChallenge); + return _context9.abrupt("return", updatedUserChallenge); case 10: - _context12.prev = 10; - _context12.t0 = _context12["catch"](1); - errorMessage = "Challenge service error on startUserChallenge: ".concat(JSON.stringify(_context12.t0)); + _context9.prev = 10; + _context9.t0 = _context9["catch"](1); + errorMessage = "Challenge service error on startUserChallenge: ".concat(JSON.stringify(_context9.t0)); logStack('error', errorMessage); _logger.default.error(errorMessage); - Sentry.captureException(_context12.t0); - throw _context12.t0; + Sentry.captureException(_context9.t0); + throw _context9.t0; case 17: case "end": - return _context12.stop(); + return _context9.stop(); } } - }, _callee11, this, [[1, 10]]); + }, _callee8, this, [[1, 10]]); })); - function startUserChallenge(_x21) { + function startUserChallenge(_x7) { return _startUserChallenge.apply(this, arguments); } return startUserChallenge; @@ -12929,11 +12765,11 @@ var ChallengeService = /*#__PURE__*/function () { }, { key: "updateUserChallenge", value: function () { - var _updateUserChallenge = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee12(userChallenge, flag, quizWithUpdatedQuestions, fluidStatus, action) { + var _updateUserChallenge = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee9(userChallenge, flag, quizWithUpdatedQuestions, fluidStatus, action) { var updatedUserChallenge, updatedDuel, updatedQuiz, updatedExploration, updatedAction, duelService, quizService, explorationService, actionService, updateQuizProgress, userAction, _yield$this$_client$s, userChallengeEntity, result, errorMessage; - return _regenerator.default.wrap(function _callee12$(_context13) { + return _regenerator.default.wrap(function _callee9$(_context10) { while (1) { - switch (_context13.prev = _context13.next) { + switch (_context10.prev = _context10.next) { case 0: updatedDuel = userChallenge.duel; updatedQuiz = userChallenge.quiz; @@ -12943,47 +12779,38 @@ var ChallengeService = /*#__PURE__*/function () { quizService = new _quiz2.default(this._client); explorationService = new _exploration.default(this._client); actionService = new _action.default(this._client); - _context13.t0 = flag; - _context13.next = _context13.t0 === _enums.UserChallengeUpdateFlag.CHALLENGE ? 11 : _context13.t0 === _enums.UserChallengeUpdateFlag.DUEL_CONSUMPTION ? 11 : _context13.t0 === _enums.UserChallengeUpdateFlag.DUEL_UNLOCK ? 13 : _context13.t0 === _enums.UserChallengeUpdateFlag.DUEL_UPDATE_THRESHOLD ? 18 : _context13.t0 === _enums.UserChallengeUpdateFlag.DUEL_START ? 23 : _context13.t0 === _enums.UserChallengeUpdateFlag.DUEL_WIN ? 28 : _context13.t0 === _enums.UserChallengeUpdateFlag.DUEL_LOSS ? 33 : _context13.t0 === _enums.UserChallengeUpdateFlag.DUEL_RESET ? 38 : _context13.t0 === _enums.UserChallengeUpdateFlag.QUIZ_START ? 43 : _context13.t0 === _enums.UserChallengeUpdateFlag.QUIZ_DONE ? 48 : _context13.t0 === _enums.UserChallengeUpdateFlag.QUIZ_UPDATE ? 54 : _context13.t0 === _enums.UserChallengeUpdateFlag.QUIZ_RESET ? 56 : _context13.t0 === _enums.UserChallengeUpdateFlag.EXPLORATION_START ? 61 : _context13.t0 === _enums.UserChallengeUpdateFlag.EXPLORATION_UPDATE ? 66 : _context13.t0 === _enums.UserChallengeUpdateFlag.EXPLORATION_NOTIFICATION ? 71 : _context13.t0 === _enums.UserChallengeUpdateFlag.EXPLORATION_DONE ? 76 : _context13.t0 === _enums.UserChallengeUpdateFlag.ACTION_START ? 79 : _context13.t0 === _enums.UserChallengeUpdateFlag.ACTION_NOTIFICATION ? 83 : _context13.t0 === _enums.UserChallengeUpdateFlag.ACTION_DONE ? 86 : 89; + _context10.t0 = flag; + _context10.next = _context10.t0 === _enums.UserChallengeUpdateFlag.CHALLENGE ? 11 : _context10.t0 === _enums.UserChallengeUpdateFlag.DUEL_CONSUMPTION ? 11 : _context10.t0 === _enums.UserChallengeUpdateFlag.DUEL_UNLOCK ? 13 : _context10.t0 === _enums.UserChallengeUpdateFlag.DUEL_UPDATE_THRESHOLD ? 16 : _context10.t0 === _enums.UserChallengeUpdateFlag.DUEL_START ? 21 : _context10.t0 === _enums.UserChallengeUpdateFlag.DUEL_WIN ? 24 : _context10.t0 === _enums.UserChallengeUpdateFlag.DUEL_LOSS ? 27 : _context10.t0 === _enums.UserChallengeUpdateFlag.DUEL_RESET ? 30 : _context10.t0 === _enums.UserChallengeUpdateFlag.QUIZ_START ? 33 : _context10.t0 === _enums.UserChallengeUpdateFlag.QUIZ_DONE ? 36 : _context10.t0 === _enums.UserChallengeUpdateFlag.QUIZ_UPDATE ? 40 : _context10.t0 === _enums.UserChallengeUpdateFlag.QUIZ_RESET ? 42 : _context10.t0 === _enums.UserChallengeUpdateFlag.EXPLORATION_START ? 45 : _context10.t0 === _enums.UserChallengeUpdateFlag.EXPLORATION_UPDATE ? 48 : _context10.t0 === _enums.UserChallengeUpdateFlag.EXPLORATION_NOTIFICATION ? 51 : _context10.t0 === _enums.UserChallengeUpdateFlag.EXPLORATION_DONE ? 54 : _context10.t0 === _enums.UserChallengeUpdateFlag.ACTION_START ? 57 : _context10.t0 === _enums.UserChallengeUpdateFlag.ACTION_NOTIFICATION ? 61 : _context10.t0 === _enums.UserChallengeUpdateFlag.ACTION_DONE ? 64 : 67; break; case 11: updatedUserChallenge = userChallenge; - return _context13.abrupt("break", 91); + return _context10.abrupt("break", 69); case 13: - _context13.next = 15; - return duelService.unlockUserDuel(userChallenge.duel); - case 15: - updatedDuel = _context13.sent; + updatedDuel = duelService.unlockUserDuel(userChallenge.duel); updatedUserChallenge = _objectSpread(_objectSpread({}, userChallenge), {}, { state: _enums.UserChallengeState.DUEL, duel: updatedDuel }); - return _context13.abrupt("break", 91); - case 18: - _context13.next = 20; + return _context10.abrupt("break", 69); + case 16: + _context10.next = 18; return duelService.updateUserDuelThreshold(userChallenge.duel, fluidStatus); - case 20: - updatedDuel = _context13.sent; + case 18: + updatedDuel = _context10.sent; updatedUserChallenge = _objectSpread(_objectSpread({}, userChallenge), {}, { state: _enums.UserChallengeState.DUEL, duel: updatedDuel }); - return _context13.abrupt("break", 91); - case 23: - _context13.next = 25; - return duelService.startUserDuel(userChallenge.duel); - case 25: - updatedDuel = _context13.sent; + return _context10.abrupt("break", 69); + case 21: + updatedDuel = duelService.startUserDuel(userChallenge.duel); updatedUserChallenge = _objectSpread(_objectSpread({}, userChallenge), {}, { state: _enums.UserChallengeState.DUEL, duel: updatedDuel }); - return _context13.abrupt("break", 91); - case 28: - _context13.next = 30; - return duelService.endUserDuel(userChallenge.duel); - case 30: - updatedDuel = _context13.sent; + return _context10.abrupt("break", 69); + case 24: + updatedDuel = duelService.endUserDuel(userChallenge.duel); updatedUserChallenge = _objectSpread(_objectSpread({}, userChallenge), {}, { state: _enums.UserChallengeState.DONE, duel: updatedDuel, @@ -12992,12 +12819,9 @@ var ChallengeService = /*#__PURE__*/function () { }).startOf('day'), success: _enums.UserChallengeSuccess.WIN }); - return _context13.abrupt("break", 91); - case 33: - _context13.next = 35; - return duelService.endUserDuel(userChallenge.duel); - case 35: - updatedDuel = _context13.sent; + return _context10.abrupt("break", 69); + case 27: + updatedDuel = duelService.endUserDuel(userChallenge.duel); updatedUserChallenge = _objectSpread(_objectSpread({}, userChallenge), {}, { state: _enums.UserChallengeState.DONE, duel: updatedDuel, @@ -13006,82 +12830,61 @@ var ChallengeService = /*#__PURE__*/function () { }).startOf('day'), success: _enums.UserChallengeSuccess.LOST }); - return _context13.abrupt("break", 91); - case 38: - _context13.next = 40; - return duelService.resetUserDuel(userChallenge.duel); - case 40: - updatedDuel = _context13.sent; + return _context10.abrupt("break", 69); + case 30: + updatedDuel = duelService.resetUserDuel(userChallenge.duel); updatedUserChallenge = _objectSpread(_objectSpread({}, userChallenge), {}, { state: _enums.UserChallengeState.DUEL, duel: updatedDuel, success: _enums.UserChallengeSuccess.ONGOING }); - return _context13.abrupt("break", 91); - case 43: - _context13.next = 45; - return quizService.startUserQuiz(userChallenge.quiz); - case 45: - updatedQuiz = _context13.sent; + return _context10.abrupt("break", 69); + case 33: + updatedQuiz = quizService.startUserQuiz(userChallenge.quiz); updatedUserChallenge = _objectSpread(_objectSpread({}, userChallenge), {}, { quiz: updatedQuiz }); - return _context13.abrupt("break", 91); - case 48: + return _context10.abrupt("break", 69); + case 36: updateQuizProgress = Math.min(userChallenge.quiz.result, 5); - _context13.next = 51; - return quizService.endUserQuiz(userChallenge.quiz); - case 51: - updatedQuiz = _context13.sent; + updatedQuiz = quizService.endUserQuiz(userChallenge.quiz); updatedUserChallenge = _objectSpread(_objectSpread({}, userChallenge), {}, { quiz: updatedQuiz, progress: _objectSpread(_objectSpread({}, userChallenge.progress), {}, { quizProgress: updateQuizProgress }) }); - return _context13.abrupt("break", 91); - case 54: + return _context10.abrupt("break", 69); + case 40: updatedUserChallenge = _objectSpread(_objectSpread({}, userChallenge), {}, { quiz: quizWithUpdatedQuestions ? quizWithUpdatedQuestions : userChallenge.quiz }); - return _context13.abrupt("break", 91); - case 56: - _context13.next = 58; - return quizService.resetUserQuiz(userChallenge.quiz); - case 58: - updatedQuiz = _context13.sent; + return _context10.abrupt("break", 69); + case 42: + updatedQuiz = quizService.resetUserQuiz(userChallenge.quiz); updatedUserChallenge = _objectSpread(_objectSpread({}, userChallenge), {}, { quiz: updatedQuiz }); - return _context13.abrupt("break", 91); - case 61: - _context13.next = 63; - return explorationService.startUserExploration(userChallenge.exploration); - case 63: - updatedExploration = _context13.sent; + return _context10.abrupt("break", 69); + case 45: + updatedExploration = explorationService.startUserExploration(userChallenge.exploration); updatedUserChallenge = _objectSpread(_objectSpread({}, userChallenge), {}, { exploration: updatedExploration }); - return _context13.abrupt("break", 91); - case 66: - _context13.next = 68; - return explorationService.updateUserExploration(userChallenge.exploration); - case 68: - updatedExploration = _context13.sent; + return _context10.abrupt("break", 69); + case 48: + updatedExploration = explorationService.updateUserExploration(userChallenge.exploration); updatedUserChallenge = _objectSpread(_objectSpread({}, userChallenge), {}, { exploration: updatedExploration }); - return _context13.abrupt("break", 91); - case 71: - _context13.next = 73; - return explorationService.setNotificationUserExploration(userChallenge.exploration); - case 73: - updatedExploration = _context13.sent; + return _context10.abrupt("break", 69); + case 51: + updatedExploration = explorationService.setNotificationUserExploration(userChallenge.exploration); updatedUserChallenge = _objectSpread(_objectSpread({}, userChallenge), {}, { exploration: updatedExploration }); - return _context13.abrupt("break", 91); - case 76: + return _context10.abrupt("break", 69); + case 54: updatedExploration = explorationService.endUserExploration(userChallenge.exploration); updatedUserChallenge = _objectSpread(_objectSpread({}, userChallenge), {}, { exploration: updatedExploration, @@ -13089,8 +12892,8 @@ var ChallengeService = /*#__PURE__*/function () { explorationProgress: updatedExploration.progress }) }); - return _context13.abrupt("break", 91); - case 79: + return _context10.abrupt("break", 69); + case 57: userAction = userChallenge.action; if (action) { userAction = actionService.launchAction(action); @@ -13098,14 +12901,14 @@ var ChallengeService = /*#__PURE__*/function () { updatedUserChallenge = _objectSpread(_objectSpread({}, userChallenge), {}, { action: userAction }); - return _context13.abrupt("break", 91); - case 83: + return _context10.abrupt("break", 69); + case 61: updatedAction = actionService.setNotificationAction(userChallenge.action); updatedUserChallenge = _objectSpread(_objectSpread({}, userChallenge), {}, { action: updatedAction }); - return _context13.abrupt("break", 91); - case 86: + return _context10.abrupt("break", 69); + case 64: updatedAction = actionService.endAction(userChallenge.action); updatedUserChallenge = _objectSpread(_objectSpread({}, userChallenge), {}, { action: updatedAction, @@ -13113,35 +12916,35 @@ var ChallengeService = /*#__PURE__*/function () { actionProgress: 5 }) }); - return _context13.abrupt("break", 91); - case 89: + return _context10.abrupt("break", 69); + case 67: updatedUserChallenge = userChallenge; - return _context13.abrupt("break", 91); - case 91: - _context13.prev = 91; - _context13.next = 94; + return _context10.abrupt("break", 69); + case 69: + _context10.prev = 69; + _context10.next = 72; return this._client.save(updatedUserChallenge); - case 94: - _yield$this$_client$s = _context13.sent; + case 72: + _yield$this$_client$s = _context10.sent; userChallengeEntity = _yield$this$_client$s.data; result = this.parseUserChallengeEntityToUserChallenge(userChallengeEntity); - return _context13.abrupt("return", result); - case 100: - _context13.prev = 100; - _context13.t1 = _context13["catch"](91); - errorMessage = "Update user challenge error: ".concat(JSON.stringify(_context13.t1)); + return _context10.abrupt("return", result); + case 78: + _context10.prev = 78; + _context10.t1 = _context10["catch"](69); + errorMessage = "Update user challenge error: ".concat(JSON.stringify(_context10.t1)); logStack('error', errorMessage); _logger.default.error(errorMessage); - Sentry.captureException(_context13.t1); - throw _context13.t1; - case 107: + Sentry.captureException(_context10.t1); + throw _context10.t1; + case 85: case "end": - return _context13.stop(); + return _context10.stop(); } } - }, _callee12, this, [[91, 100]]); + }, _callee9, this, [[69, 78]]); })); - function updateUserChallenge(_x22, _x23, _x24, _x25, _x26) { + function updateUserChallenge(_x8, _x9, _x10, _x11, _x12) { return _updateUserChallenge.apply(this, arguments); } return updateUserChallenge; @@ -13153,14 +12956,14 @@ var ChallengeService = /*#__PURE__*/function () { }, { key: "getUserChallengeDataload", value: function () { - var _getUserChallengeDataload = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee13(userChallenge) { + var _getUserChallengeDataload = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee10(userChallenge) { var consumptionService, timePeriod, dataChart; - return _regenerator.default.wrap(function _callee13$(_context14) { + return _regenerator.default.wrap(function _callee10$(_context11) { while (1) { - switch (_context14.prev = _context14.next) { + switch (_context11.prev = _context11.next) { case 0: if (!userChallenge.duel.startDate) { - _context14.next = 8; + _context11.next = 8; break; } consumptionService = new _consumption.default(this._client); @@ -13170,7 +12973,7 @@ var ChallengeService = /*#__PURE__*/function () { day: userChallenge.duel.duration.days - 1 }) }; - _context14.next = 5; + _context11.next = 5; return consumptionService.getGraphData({ timePeriod: timePeriod, timeStep: _enums.TimeStep.DAY, @@ -13178,22 +12981,22 @@ var ChallengeService = /*#__PURE__*/function () { isHome: true }); case 5: - dataChart = _context14.sent; + dataChart = _context11.sent; if (!dataChart) { - _context14.next = 8; + _context11.next = 8; break; } - return _context14.abrupt("return", dataChart.actualData); + return _context11.abrupt("return", dataChart.actualData); case 8: - return _context14.abrupt("return", []); + return _context11.abrupt("return", []); case 9: case "end": - return _context14.stop(); + return _context11.stop(); } } - }, _callee13, this); + }, _callee10, this); })); - function getUserChallengeDataload(_x27) { + function getUserChallengeDataload(_x13) { return _getUserChallengeDataload.apply(this, arguments); } return getUserChallengeDataload; @@ -13205,59 +13008,42 @@ var ChallengeService = /*#__PURE__*/function () { */ }, { key: "isChallengeDone", - value: function () { - var _isChallengeDone = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee14(userChallenge, dataloads) { - var isDone, isWin, fullDuration, diffFromNow, duration; - return _regenerator.default.wrap(function _callee14$(_context15) { - while (1) { - switch (_context15.prev = _context15.next) { - case 0: + value: function isChallengeDone(userChallenge, dataloads) { + var isDone = false; + var isWin = false; + if (userChallenge.state === _enums.UserChallengeState.DUEL && userChallenge.duel.state === _enums.UserDuelState.ONGOING && userChallenge.duel.duration) { + var fullDuration = userChallenge.duel.duration.days + (0, _date.getLagDays)(userChallenge.duel.fluidTypes) + 1; + var diffFromNow = userChallenge.duel.startDate ? userChallenge.duel.startDate.diff(_luxon.DateTime.local().setZone('utc', { + keepLocalTime: true + }), 'days').toObject().days : 0; + diffFromNow = diffFromNow ? Math.abs(diffFromNow) : 0; + if (diffFromNow >= fullDuration) { + isDone = true; + if (isDone && userChallenge.duel.userConsumption < userChallenge.duel.threshold) { + isWin = true; + } + } else { + var duration = userChallenge.duel.duration.days; + if (dataloads.length === duration && dataloads[duration - 1].value !== -1) { + isDone = true; + dataloads.forEach(function (d) { + if (d.value === -1 || d.valueDetail && d.valueDetail.filter(function (data) { + return data.value === -1; + }).length > 0) { isDone = false; - isWin = false; - if (userChallenge.state === _enums.UserChallengeState.DUEL && userChallenge.duel.state === _enums.UserDuelState.ONGOING && userChallenge.duel.duration) { - fullDuration = userChallenge.duel.duration.days + (0, _date.getLagDays)(userChallenge.duel.fluidTypes) + 1; - diffFromNow = userChallenge.duel.startDate ? userChallenge.duel.startDate.diff(_luxon.DateTime.local().setZone('utc', { - keepLocalTime: true - }), 'days').toObject().days : 0; - diffFromNow = diffFromNow ? Math.abs(diffFromNow) : 0; - if (diffFromNow >= fullDuration) { - isDone = true; - if (isDone && userChallenge.duel.userConsumption < userChallenge.duel.threshold) { - isWin = true; - } - } else { - duration = userChallenge.duel.duration.days; - if (dataloads.length === duration && dataloads[duration - 1].value !== -1) { - isDone = true; - dataloads.forEach(function (d) { - if (d.value === -1 || d.valueDetail && d.valueDetail.filter(function (data) { - return data.value === -1; - }).length > 0) { - isDone = false; - } - }); - if (isDone && userChallenge.duel.userConsumption < userChallenge.duel.threshold) { - isWin = true; - } - } - } - } - return _context15.abrupt("return", { - isDone: isDone, - isWin: isWin - }); - case 4: - case "end": - return _context15.stop(); + } + }); + if (isDone && userChallenge.duel.userConsumption < userChallenge.duel.threshold) { + isWin = true; } } - }, _callee14); - })); - function isChallengeDone(_x28, _x29) { - return _isChallengeDone.apply(this, arguments); + } } - return isChallengeDone; - }() + return { + isDone: isDone, + isWin: isWin + }; + } }]); return ChallengeService; }(); @@ -15660,158 +15446,92 @@ var QuizService = /*#__PURE__*/function () { */ }, { key: "startUserQuiz", - value: function () { - var _startUserQuiz = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(userQuiz) { - var questions; - return _regenerator.default.wrap(function _callee4$(_context4) { - while (1) { - switch (_context4.prev = _context4.next) { - case 0: - questions = userQuiz.questions.map(function (question) { - return _objectSpread(_objectSpread({}, question), {}, { - answers: (0, _lodash.shuffle)(question.answers) - }); - }); - return _context4.abrupt("return", _objectSpread(_objectSpread({}, userQuiz), {}, { - questions: (0, _lodash.shuffle)(questions), - state: _enums.UserQuizState.ONGOING, - startDate: _luxon.DateTime.local().setZone('utc', { - keepLocalTime: true - }) - })); - case 2: - case "end": - return _context4.stop(); - } - } - }, _callee4); - })); - function startUserQuiz(_x2) { - return _startUserQuiz.apply(this, arguments); - } - return startUserQuiz; - }() + value: function startUserQuiz(userQuiz) { + var questions = userQuiz.questions.map(function (question) { + return _objectSpread(_objectSpread({}, question), {}, { + answers: (0, _lodash.shuffle)(question.answers) + }); + }); + return _objectSpread(_objectSpread({}, userQuiz), {}, { + questions: (0, _lodash.shuffle)(questions), + state: _enums.UserQuizState.ONGOING, + startDate: _luxon.DateTime.local().setZone('utc', { + keepLocalTime: true + }) + }); + } /** * Return quiz with updated state to UserQuizState.UNLOCKED and updated questions with false result * @param {UserQuiz} userQuiz - userQuiz to update */ }, { key: "resetUserQuiz", - value: function () { - var _resetUserQuiz = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(userQuiz) { - var updatedQuestions, updatedCustomQuestion; - return _regenerator.default.wrap(function _callee5$(_context5) { - while (1) { - switch (_context5.prev = _context5.next) { - case 0: - updatedQuestions = userQuiz.questions.map(function (question) { - return _objectSpread(_objectSpread({}, question), {}, { - result: _enums.UserQuestionState.UNLOCKED - }); - }); - updatedCustomQuestion = _objectSpread(_objectSpread({}, userQuiz.customQuestion), {}, { - result: _enums.UserQuestionState.UNLOCKED - }); - return _context5.abrupt("return", _objectSpread(_objectSpread({}, userQuiz), {}, { - customQuestion: updatedCustomQuestion, - questions: updatedQuestions, - result: 0, - state: _enums.UserQuizState.UNLOCKED - })); - case 3: - case "end": - return _context5.stop(); - } - } - }, _callee5); - })); - function resetUserQuiz(_x3) { - return _resetUserQuiz.apply(this, arguments); - } - return resetUserQuiz; - }() + value: function resetUserQuiz(userQuiz) { + var updatedQuestions = userQuiz.questions.map(function (question) { + return _objectSpread(_objectSpread({}, question), {}, { + result: _enums.UserQuestionState.UNLOCKED + }); + }); + var updatedCustomQuestion = _objectSpread(_objectSpread({}, userQuiz.customQuestion), {}, { + result: _enums.UserQuestionState.UNLOCKED + }); + return _objectSpread(_objectSpread({}, userQuiz), {}, { + customQuestion: updatedCustomQuestion, + questions: updatedQuestions, + result: 0, + state: _enums.UserQuizState.UNLOCKED + }); + } + /** * Return quiz with updated state to UserQuizState.DONE * @param {UserQuiz} userQuiz - userQuiz to update */ }, { key: "endUserQuiz", - value: function () { - var _endUserQuiz = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(userQuiz) { - var updatedUserQuiz; - return _regenerator.default.wrap(function _callee6$(_context6) { - while (1) { - switch (_context6.prev = _context6.next) { - case 0: - updatedUserQuiz = _objectSpread(_objectSpread({}, userQuiz), {}, { - state: _enums.UserQuizState.DONE - }); - return _context6.abrupt("return", updatedUserQuiz); - case 2: - case "end": - return _context6.stop(); - } - } - }, _callee6); - })); - function endUserQuiz(_x4) { - return _endUserQuiz.apply(this, arguments); - } - return endUserQuiz; - }() + value: function endUserQuiz(userQuiz) { + return _objectSpread(_objectSpread({}, userQuiz), {}, { + state: _enums.UserQuizState.DONE + }); + } + /** * Return quiz with result and updated question or customQuestion if no index is passed * @param {UserQuiz} userQuiz - userQuiz to update */ }, { key: "updateUserQuiz", - value: function () { - var _updateUserQuiz = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee7(userQuiz, questionResult, questionIndex) { - var result, updatedQuestions, updatedCustomQuestion; - return _regenerator.default.wrap(function _callee7$(_context7) { - while (1) { - switch (_context7.prev = _context7.next) { - case 0: - result = questionResult ? _enums.UserQuestionState.CORRECT : _enums.UserQuestionState.INCORRECT; - updatedQuestions = userQuiz.questions.map(function (question, index) { - if (index === questionIndex) { - return _objectSpread(_objectSpread({}, question), {}, { - result: result - }); - } - return question; - }); - updatedCustomQuestion = _objectSpread(_objectSpread({}, userQuiz.customQuestion), {}, { - result: result - }); - return _context7.abrupt("return", _objectSpread(_objectSpread({}, userQuiz), {}, { - questions: updatedQuestions, - customQuestion: questionIndex === undefined ? updatedCustomQuestion : userQuiz.customQuestion, - result: questionResult ? Math.min(userQuiz.result + 1, 5) : userQuiz.result - })); - case 4: - case "end": - return _context7.stop(); - } - } - }, _callee7); - })); - function updateUserQuiz(_x5, _x6, _x7) { - return _updateUserQuiz.apply(this, arguments); - } - return updateUserQuiz; - }() + value: function updateUserQuiz(userQuiz, questionResult, questionIndex) { + var result = questionResult ? _enums.UserQuestionState.CORRECT : _enums.UserQuestionState.INCORRECT; + var updatedQuestions = userQuiz.questions.map(function (question, index) { + if (index === questionIndex) { + return _objectSpread(_objectSpread({}, question), {}, { + result: result + }); + } + return question; + }); + var updatedCustomQuestion = _objectSpread(_objectSpread({}, userQuiz.customQuestion), {}, { + result: result + }); + return _objectSpread(_objectSpread({}, userQuiz), {}, { + questions: updatedQuestions, + customQuestion: questionIndex === undefined ? updatedCustomQuestion : userQuiz.customQuestion, + result: questionResult ? Math.min(userQuiz.result + 1, 5) : userQuiz.result + }); + } + /** * Build a custom question with the customQuestionEntity */ }, { key: "getCustomQuestion", value: function () { - var _getCustomQuestion = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee8(customQuestionEntity, fluidTypes) { + var _getCustomQuestion = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(customQuestionEntity, fluidTypes) { var answers, explanation, finalInterval, useFluidTypes, questionLabel, unit, unitLabel, fluidLabel, intervalAnswer, _maxLoad, consumptionService, maxLoad, averageLoad, finalQuestion; - return _regenerator.default.wrap(function _callee8$(_context8) { + return _regenerator.default.wrap(function _callee4$(_context4) { while (1) { - switch (_context8.prev = _context8.next) { + switch (_context4.prev = _context4.next) { case 0: explanation = 'Vous pouvez vérifier cette information sur l’écran Conso.'; finalInterval = this.getTimePeriodFromInterval(customQuestionEntity.interval, customQuestionEntity.period.weekday ? {} : customQuestionEntity.period); @@ -15839,24 +15559,24 @@ var QuizService = /*#__PURE__*/function () { questionLabel = questionLabel.replace('#fluid', fluidLabel); } if (!(customQuestionEntity.type === _enums.CustomQuestionType.DATE)) { - _context8.next = 13; + _context4.next = 13; break; } - _context8.next = 9; + _context4.next = 9; return this.getMaxLoadOnLastInterval(customQuestionEntity.timeStep, finalInterval, useFluidTypes); case 9: - intervalAnswer = _context8.sent; + intervalAnswer = _context4.sent; answers = this.getAnswersForInterval(intervalAnswer.date, customQuestionEntity.timeStep, finalInterval); - _context8.next = 26; + _context4.next = 26; break; case 13: if (!(customQuestionEntity.type === _enums.CustomQuestionType.MAXDATA)) { - _context8.next = 22; + _context4.next = 22; break; } // Max data consumptionService = new _consumption.default(this._client); - _context8.next = 17; + _context4.next = 17; return consumptionService.getMaxLoad({ maxTimePeriod: finalInterval, timeStep: customQuestionEntity.timeStep, @@ -15864,16 +15584,16 @@ var QuizService = /*#__PURE__*/function () { isHome: !customQuestionEntity.singleFluid }); case 17: - maxLoad = _context8.sent; + maxLoad = _context4.sent; maxLoad = (_maxLoad = maxLoad) !== null && _maxLoad !== void 0 ? _maxLoad : 0; answers = this.getAnswersForNumberValue(maxLoad, unit); - _context8.next = 26; + _context4.next = 26; break; case 22: - _context8.next = 24; + _context4.next = 24; return this.getAverageOnGivenPeriod(customQuestionEntity.timeStep, finalInterval, useFluidTypes, customQuestionEntity.period.weekday ? customQuestionEntity.period.weekday : undefined, customQuestionEntity.singleFluid); case 24: - averageLoad = _context8.sent; + averageLoad = _context4.sent; answers = this.getAnswersForNumberValue(averageLoad, unit); case 26: finalQuestion = { @@ -15882,15 +15602,15 @@ var QuizService = /*#__PURE__*/function () { explanation: explanation, source: '' }; - return _context8.abrupt("return", finalQuestion); + return _context4.abrupt("return", finalQuestion); case 28: case "end": - return _context8.stop(); + return _context4.stop(); } } - }, _callee8, this); + }, _callee4, this); })); - function getCustomQuestion(_x8, _x9) { + function getCustomQuestion(_x2, _x3) { return _getCustomQuestion.apply(this, arguments); } return getCustomQuestion; @@ -15948,12 +15668,12 @@ var QuizService = /*#__PURE__*/function () { }, { key: "getMaxLoadOnLastInterval", value: function () { - var _getMaxLoadOnLastInterval = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee9(timeStep, interval, fluidTypes) { + var _getMaxLoadOnLastInterval = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(timeStep, interval, fluidTypes) { var _graphData; var dateMax, max, consumptionService, limit, graphData, _graphData4, newInterval, objectTimeStep, _graphData2, _graphData3, _newInterval; - return _regenerator.default.wrap(function _callee9$(_context9) { + return _regenerator.default.wrap(function _callee5$(_context5) { while (1) { - switch (_context9.prev = _context9.next) { + switch (_context5.prev = _context5.next) { case 0: dateMax = _luxon.DateTime.local().setZone('utc', { keepLocalTime: true @@ -15964,39 +15684,39 @@ var QuizService = /*#__PURE__*/function () { date: interval.startDate, reached: false }; - _context9.next = 6; + _context5.next = 6; return consumptionService.getGraphData({ timePeriod: interval, timeStep: timeStep, fluidTypes: fluidTypes }); case 6: - graphData = _context9.sent; + graphData = _context5.sent; if (!((_graphData = graphData) !== null && _graphData !== void 0 && _graphData.actualData)) { - _context9.next = 34; + _context5.next = 34; break; } max = Math.max.apply(Math, (0, _toConsumableArray2.default)(graphData.actualData.map(function (d) { return d.value; }))); if (!(max == -1)) { - _context9.next = 28; + _context5.next = 28; break; } newInterval = _objectSpread({}, interval); - _context9.t0 = timeStep; - _context9.next = _context9.t0 === _enums.TimeStep.MONTH ? 14 : _context9.t0 === _enums.TimeStep.YEAR ? 16 : 18; + _context5.t0 = timeStep; + _context5.next = _context5.t0 === _enums.TimeStep.MONTH ? 14 : _context5.t0 === _enums.TimeStep.YEAR ? 16 : 18; break; case 14: objectTimeStep = { month: 1 }; - return _context9.abrupt("break", 19); + return _context5.abrupt("break", 19); case 16: objectTimeStep = { year: 1 }; - return _context9.abrupt("break", 19); + return _context5.abrupt("break", 19); case 18: objectTimeStep = { week: 1 @@ -16005,14 +15725,14 @@ var QuizService = /*#__PURE__*/function () { newInterval.startDate = newInterval.startDate.minus(objectTimeStep); newInterval.endDate = newInterval.endDate.minus(objectTimeStep); limit.date = newInterval.startDate; - _context9.next = 24; + _context5.next = 24; return consumptionService.getGraphData({ timePeriod: newInterval, timeStep: timeStep, fluidTypes: fluidTypes }); case 24: - graphData = _context9.sent; + graphData = _context5.sent; if (limit.date < _luxon.DateTime.now().minus({ year: 5 })) { @@ -16025,12 +15745,12 @@ var QuizService = /*#__PURE__*/function () { } case 27: if (max == -1 && (_graphData2 = graphData) !== null && _graphData2 !== void 0 && _graphData2.actualData && !limit.reached) { - _context9.next = 19; + _context5.next = 19; break; } case 28: if (!limit.reached) { - _context9.next = 33; + _context5.next = 33; break; } _newInterval = { @@ -16043,14 +15763,14 @@ var QuizService = /*#__PURE__*/function () { keepLocalTime: true }).startOf('month') }; - _context9.next = 32; + _context5.next = 32; return consumptionService.getGraphData({ timePeriod: _newInterval, timeStep: timeStep, fluidTypes: fluidTypes }); case 32: - graphData = _context9.sent; + graphData = _context5.sent; case 33: if ((_graphData4 = graphData) !== null && _graphData4 !== void 0 && _graphData4.actualData) { max = Math.max.apply(Math, (0, _toConsumableArray2.default)(graphData.actualData.map(function (d) { @@ -16061,18 +15781,18 @@ var QuizService = /*#__PURE__*/function () { }); } case 34: - return _context9.abrupt("return", { + return _context5.abrupt("return", { date: dateMax, value: max }); case 35: case "end": - return _context9.stop(); + return _context5.stop(); } } - }, _callee9, this); + }, _callee5, this); })); - function getMaxLoadOnLastInterval(_x10, _x11, _x12) { + function getMaxLoadOnLastInterval(_x4, _x5, _x6) { return _getMaxLoadOnLastInterval.apply(this, arguments); } return getMaxLoadOnLastInterval; @@ -16083,15 +15803,15 @@ var QuizService = /*#__PURE__*/function () { }, { key: "getAverageOnGivenPeriod", value: function () { - var _getAverageOnGivenPeriod = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee10(timeStep, interval, fluidTypes, weekday, singleFluid) { + var _getAverageOnGivenPeriod = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(timeStep, interval, fluidTypes, weekday, singleFluid) { var consumptionService, graphData, average, total, length; - return _regenerator.default.wrap(function _callee10$(_context10) { + return _regenerator.default.wrap(function _callee6$(_context6) { while (1) { - switch (_context10.prev = _context10.next) { + switch (_context6.prev = _context6.next) { case 0: consumptionService = new _consumption.default(this._client); _logger.default.info('GetAverageOnGivenPeriod is about to call getGraphData'); - _context10.next = 4; + _context6.next = 4; return consumptionService.getGraphData({ timePeriod: interval, timeStep: timeStep, @@ -16099,7 +15819,7 @@ var QuizService = /*#__PURE__*/function () { isHome: !singleFluid }); case 4: - graphData = _context10.sent; + graphData = _context6.sent; average = 0; if (graphData !== null && graphData !== void 0 && graphData.actualData) { total = 0; @@ -16121,15 +15841,15 @@ var QuizService = /*#__PURE__*/function () { }); average = total / length; } - return _context10.abrupt("return", average); + return _context6.abrupt("return", average); case 8: case "end": - return _context10.stop(); + return _context6.stop(); } } - }, _callee10, this); + }, _callee6, this); })); - function getAverageOnGivenPeriod(_x13, _x14, _x15, _x16, _x17) { + function getAverageOnGivenPeriod(_x7, _x8, _x9, _x10, _x11) { return _getAverageOnGivenPeriod.apply(this, arguments); } return getAverageOnGivenPeriod; @@ -18150,20 +17870,12 @@ var DuelOngoing = function DuelOngoing(_ref) { userChallengeList = _useAppSelector.userChallengeList; var _useState = (0, _react.useState)(false), _useState2 = (0, _slicedToArray2.default)(_useState, 2), - resultModal = _useState2[0], - setResultModal = _useState2[1]; - var _useState3 = (0, _react.useState)(false), + showLastDuelModal = _useState2[0], + setShowLastDuelModal = _useState2[1]; + var _useState3 = (0, _react.useState)(), _useState4 = (0, _slicedToArray2.default)(_useState3, 2), - winChallenge = _useState4[0], - setWinChallenge = _useState4[1]; - var _useState5 = (0, _react.useState)(false), - _useState6 = (0, _slicedToArray2.default)(_useState5, 2), - showLastDuelModal = _useState6[0], - setShowLastDuelModal = _useState6[1]; - var _useState7 = (0, _react.useState)(), - _useState8 = (0, _slicedToArray2.default)(_useState7, 2), - finishedDataLoad = _useState8[0], - setFinishedDataLoad = _useState8[1]; + finishedDataLoad = _useState4[0], + setFinishedDataLoad = _useState4[1]; var chartContainer = (0, _react.useRef)(null); var _useChartResize = (0, _useChartResize2.useChartResize)(chartContainer, false), height = _useChartResize.height, @@ -18171,6 +17883,9 @@ var DuelOngoing = function DuelOngoing(_ref) { var challengeService = (0, _react.useMemo)(function () { return new _challenge.default(client); }, [client]); + var _challengeService$isC = challengeService.isChallengeDone(userChallenge, currentDataload), + isDone = _challengeService$isC.isDone, + isWin = _challengeService$isC.isWin; var duel = userChallenge.duel; var isLastDuel = userChallenge.id == ((_userChallengeList = userChallengeList[userChallengeList.length - 1]) === null || _userChallengeList === void 0 ? void 0 : _userChallengeList.id); var userConsumption = (0, _utils.formatNumberValues)(userChallenge.duel.userConsumption).toString(); @@ -18182,7 +17897,7 @@ var DuelOngoing = function DuelOngoing(_ref) { switch (_context.prev = _context.next) { case 0: _context.next = 2; - return challengeService.updateUserChallenge(userChallenge, winChallenge ? _enums.UserChallengeUpdateFlag.DUEL_WIN : _enums.UserChallengeUpdateFlag.DUEL_LOSS); + return challengeService.updateUserChallenge(userChallenge, isWin ? _enums.UserChallengeUpdateFlag.DUEL_WIN : _enums.UserChallengeUpdateFlag.DUEL_LOSS); case 2: updatedChallenge = _context.sent; dispatch((0, _challenge2.updateUserChallengeList)(updatedChallenge)); @@ -18199,72 +17914,36 @@ var DuelOngoing = function DuelOngoing(_ref) { } } }, _callee); - })), [challengeService, userChallenge, winChallenge, dispatch, isLastDuel, navigate]); - (0, _react.useEffect)(function () { - var subscribed = true; - function setChallengeResult() { - return _setChallengeResult.apply(this, arguments); - } - function _setChallengeResult() { - _setChallengeResult = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() { - var _yield$challengeServi, isDone, isWin; - return _regenerator.default.wrap(function _callee2$(_context2) { - while (1) { - switch (_context2.prev = _context2.next) { - case 0: - _context2.next = 2; - return challengeService.isChallengeDone(userChallenge, currentDataload); - case 2: - _yield$challengeServi = _context2.sent; - isDone = _yield$challengeServi.isDone; - isWin = _yield$challengeServi.isWin; - if (subscribed) { - setResultModal(isDone); - setWinChallenge(isWin); - } - case 6: - case "end": - return _context2.stop(); - } - } - }, _callee2); - })); - return _setChallengeResult.apply(this, arguments); - } - setChallengeResult(); - return function () { - subscribed = false; - }; - }, [challengeService, client, currentDataload, userChallenge]); + })), [challengeService, userChallenge, isWin, dispatch, isLastDuel, navigate]); (0, _react.useEffect)(function () { var subscribed = true; function populateData() { return _populateData.apply(this, arguments); } function _populateData() { - _populateData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() { + _populateData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() { var dataloads; - return _regenerator.default.wrap(function _callee3$(_context3) { + return _regenerator.default.wrap(function _callee2$(_context2) { while (1) { - switch (_context3.prev = _context3.next) { + switch (_context2.prev = _context2.next) { case 0: if (!isFinished) { - _context3.next = 5; + _context2.next = 5; break; } - _context3.next = 3; + _context2.next = 3; return challengeService.getUserChallengeDataload(userChallenge); case 3: - dataloads = _context3.sent; + dataloads = _context2.sent; if (subscribed) { setFinishedDataLoad(dataloads); } case 5: case "end": - return _context3.stop(); + return _context2.stop(); } } - }, _callee3); + }, _callee2); })); return _populateData.apply(this, arguments); } @@ -18318,9 +17997,9 @@ var DuelOngoing = function DuelOngoing(_ref) { icon: _captionIncoming.default, size: 25 }), /*#__PURE__*/_react.default.createElement("span", null, t('duel.caption_incoming'))))), /*#__PURE__*/_react.default.createElement(_DuelResultModal.default, { - open: resultModal, + open: isDone, userChallenge: userChallenge, - win: winChallenge, + win: isWin, handleCloseClick: setResult }), /*#__PURE__*/_react.default.createElement(_lastDuelModal.default, { open: showLastDuelModal, @@ -22576,59 +22255,24 @@ var ExplorationService = /*#__PURE__*/function () { */ }, { key: "startUserExploration", - value: function () { - var _startUserExploration = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(userExploration) { - var updatedUserExploration; - return _regenerator.default.wrap(function _callee4$(_context4) { - while (1) { - switch (_context4.prev = _context4.next) { - case 0: - updatedUserExploration = _objectSpread(_objectSpread({}, userExploration), {}, { - state: _enums.UserExplorationState.ONGOING - }); - return _context4.abrupt("return", updatedUserExploration); - case 2: - case "end": - return _context4.stop(); - } - } - }, _callee4); - })); - function startUserExploration(_x2) { - return _startUserExploration.apply(this, arguments); - } - return startUserExploration; - }() + value: function startUserExploration(userExploration) { + return _objectSpread(_objectSpread({}, userExploration), {}, { + state: _enums.UserExplorationState.ONGOING + }); + } + /** * Return exploration with updated state to UserExplorationState.NOTIFICATION * @param {UserExploration} userExploration - userExploration to update */ }, { key: "setNotificationUserExploration", - value: function () { - var _setNotificationUserExploration = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(userExploration) { - var updatedUserExploration; - return _regenerator.default.wrap(function _callee5$(_context5) { - while (1) { - switch (_context5.prev = _context5.next) { - case 0: - updatedUserExploration = _objectSpread(_objectSpread({}, userExploration), {}, { - state: _enums.UserExplorationState.NOTIFICATION, - progress: 5 // userExploration.type === UserExplorationType.ACTION ? 3 : 1, - }); - return _context5.abrupt("return", updatedUserExploration); - case 2: - case "end": - return _context5.stop(); - } - } - }, _callee5); - })); - function setNotificationUserExploration(_x3) { - return _setNotificationUserExploration.apply(this, arguments); - } - return setNotificationUserExploration; - }() + value: function setNotificationUserExploration(userExploration) { + return _objectSpread(_objectSpread({}, userExploration), {}, { + state: _enums.UserExplorationState.NOTIFICATION, + progress: 5 // userExploration.type === UserExplorationType.ACTION ? 3 : 1, + }); + } /** * Return exploration with updated state to UserExplorationState.DONE * @param {UserExploration} userExploration - userExploration to update @@ -22636,12 +22280,10 @@ var ExplorationService = /*#__PURE__*/function () { }, { key: "endUserExploration", value: function endUserExploration(userExploration) { - var updatedUserExploration = _objectSpread(_objectSpread({}, userExploration), {}, { + return _objectSpread(_objectSpread({}, userExploration), {}, { state: _enums.UserExplorationState.DONE, progress: 5 // userExploration.type === UserExplorationType.ACTION ? 3 : 1, }); - - return updatedUserExploration; } /** @@ -22650,30 +22292,12 @@ var ExplorationService = /*#__PURE__*/function () { */ }, { key: "updateUserExploration", - value: function () { - var _updateUserExploration = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(userExploration) { - var updatedProgress, updatedUserExploration; - return _regenerator.default.wrap(function _callee6$(_context6) { - while (1) { - switch (_context6.prev = _context6.next) { - case 0: - updatedProgress = userExploration.progress + 1; - updatedUserExploration = _objectSpread(_objectSpread({}, userExploration), {}, { - progress: updatedProgress - }); - return _context6.abrupt("return", updatedUserExploration); - case 3: - case "end": - return _context6.stop(); - } - } - }, _callee6); - })); - function updateUserExploration(_x4) { - return _updateUserExploration.apply(this, arguments); - } - return updateUserExploration; - }() + value: function updateUserExploration(userExploration) { + return _objectSpread(_objectSpread({}, userExploration), {}, { + progress: userExploration.progress + 1 + }); + } + /** * Return updated UserChallenge with updated UserExploration * @param {UserChallenge} currentChallenge - currentUserChallenge ongoing @@ -22682,36 +22306,36 @@ var ExplorationService = /*#__PURE__*/function () { }, { key: "checkExploration", value: function () { - var _checkExploration = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee7(currentChallenge, explorationID) { + var _checkExploration = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(currentChallenge, explorationID) { var challengeService; - return _regenerator.default.wrap(function _callee7$(_context7) { + return _regenerator.default.wrap(function _callee4$(_context4) { while (1) { - switch (_context7.prev = _context7.next) { + switch (_context4.prev = _context4.next) { case 0: challengeService = new _challenge.default(this._client); - _context7.t0 = explorationID; - _context7.next = _context7.t0 === _enums.UserExplorationID.EXPLORATION007 ? 4 : _context7.t0 === _enums.UserExplorationID.EXPLORATION002 ? 9 : _context7.t0 === _enums.UserExplorationID.EXPLORATION004_0 ? 9 : _context7.t0 === _enums.UserExplorationID.EXPLORATION005 ? 9 : _context7.t0 === _enums.UserExplorationID.EXPLORATION004 ? 9 : _context7.t0 === _enums.UserExplorationID.EXPLORATION003 ? 9 : _context7.t0 === _enums.UserExplorationID.EXPLORATION008 ? 9 : _context7.t0 === _enums.UserExplorationID.EXPLORATION001 ? 9 : 10; + _context4.t0 = explorationID; + _context4.next = _context4.t0 === _enums.UserExplorationID.EXPLORATION007 ? 4 : _context4.t0 === _enums.UserExplorationID.EXPLORATION002 ? 9 : _context4.t0 === _enums.UserExplorationID.EXPLORATION004_0 ? 9 : _context4.t0 === _enums.UserExplorationID.EXPLORATION005 ? 9 : _context4.t0 === _enums.UserExplorationID.EXPLORATION004 ? 9 : _context4.t0 === _enums.UserExplorationID.EXPLORATION003 ? 9 : _context4.t0 === _enums.UserExplorationID.EXPLORATION008 ? 9 : _context4.t0 === _enums.UserExplorationID.EXPLORATION001 ? 9 : 10; break; case 4: if (!(currentChallenge.exploration.progress + 1 < currentChallenge.exploration.target)) { - _context7.next = 8; + _context4.next = 8; break; } - return _context7.abrupt("return", challengeService.updateUserChallenge(currentChallenge, _enums.UserChallengeUpdateFlag.EXPLORATION_UPDATE)); + return _context4.abrupt("return", challengeService.updateUserChallenge(currentChallenge, _enums.UserChallengeUpdateFlag.EXPLORATION_UPDATE)); case 8: - return _context7.abrupt("return", challengeService.updateUserChallenge(currentChallenge, _enums.UserChallengeUpdateFlag.EXPLORATION_NOTIFICATION)); + return _context4.abrupt("return", challengeService.updateUserChallenge(currentChallenge, _enums.UserChallengeUpdateFlag.EXPLORATION_NOTIFICATION)); case 9: - return _context7.abrupt("return", challengeService.updateUserChallenge(currentChallenge, _enums.UserChallengeUpdateFlag.EXPLORATION_NOTIFICATION)); + return _context4.abrupt("return", challengeService.updateUserChallenge(currentChallenge, _enums.UserChallengeUpdateFlag.EXPLORATION_NOTIFICATION)); case 10: - return _context7.abrupt("return", currentChallenge); + return _context4.abrupt("return", currentChallenge); case 11: case "end": - return _context7.stop(); + return _context4.stop(); } } - }, _callee7, this); + }, _callee4, this); })); - function checkExploration(_x5, _x6) { + function checkExploration(_x2, _x3) { return _checkExploration.apply(this, arguments); } return checkExploration; @@ -27257,104 +26881,82 @@ var InitializationService = /*#__PURE__*/function () { }() }, { key: "initAnalysis", - value: function () { - var _initAnalysis = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee9(profile) { - var startTime, actualAnalysisDate, errorMessage; - return _regenerator.default.wrap(function _callee9$(_context9) { - while (1) { - switch (_context9.prev = _context9.next) { - case 0: - startTime = performance.now(); - _context9.prev = 1; - actualAnalysisDate = (0, _date.getActualAnalysisDate)(); - if (!(profile.monthlyAnalysisDate && actualAnalysisDate <= profile.monthlyAnalysisDate)) { - _context9.next = 8; - break; - } - (0, _duration.logDuration)('[Initialization] Analysis information from profile loaded', startTime); - return _context9.abrupt("return", { - monthlyAnalysisDate: profile.monthlyAnalysisDate, - haveSeenLastAnalysis: profile.haveSeenLastAnalysis - }); - case 8: - (0, _duration.logDuration)('[Initialization] Analysis information from profile updated', startTime); - return _context9.abrupt("return", { - monthlyAnalysisDate: actualAnalysisDate, - haveSeenLastAnalysis: profile.isFirstConnection - }); - case 10: - _context9.next = 20; - break; - case 12: - _context9.prev = 12; - _context9.t0 = _context9["catch"](1); - this._setInitStepError(_models.InitStepsErrors.ANALYSIS_ERROR); - errorMessage = "Initialization error - initAnalysis: ".concat(JSON.stringify(_context9.t0)); - logStack('error', errorMessage); - _logger.default.error(errorMessage); - Sentry.captureException(_context9.t0); - throw _context9.t0; - case 20: - case "end": - return _context9.stop(); - } - } - }, _callee9, this, [[1, 12]]); - })); - function initAnalysis(_x5) { - return _initAnalysis.apply(this, arguments); + value: function initAnalysis(profile) { + var startTime = performance.now(); + try { + var actualAnalysisDate = (0, _date.getActualAnalysisDate)(); + if (profile.monthlyAnalysisDate && actualAnalysisDate <= profile.monthlyAnalysisDate) { + (0, _duration.logDuration)('[Initialization] Analysis information from profile loaded', startTime); + return { + monthlyAnalysisDate: profile.monthlyAnalysisDate, + haveSeenLastAnalysis: profile.haveSeenLastAnalysis + }; + } else { + (0, _duration.logDuration)('[Initialization] Analysis information from profile updated', startTime); + return { + monthlyAnalysisDate: actualAnalysisDate, + haveSeenLastAnalysis: profile.isFirstConnection + }; + } + } catch (error) { + this._setInitStepError(_models.InitStepsErrors.ANALYSIS_ERROR); + var errorMessage = "Initialization error - initAnalysis: ".concat(JSON.stringify(error)); + logStack('error', errorMessage); + _logger.default.error(errorMessage); + Sentry.captureException(error); + throw error; } - return initAnalysis; - }() + } + /** * Check if FluidTypes exist - * success return: FluidType[] - * failure throw error + * - success return: FluidType[] + * - failure throw error */ }, { key: "initFluidTypes", value: function () { - var _initFluidTypes = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee10() { + var _initFluidTypes = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee9() { var startTime, kss, fluidTypes, errorMessage; - return _regenerator.default.wrap(function _callee10$(_context10) { + return _regenerator.default.wrap(function _callee9$(_context9) { while (1) { - switch (_context10.prev = _context10.next) { + switch (_context9.prev = _context9.next) { case 0: startTime = performance.now(); kss = new _konnectorStatus.default(this._client); - _context10.prev = 2; - _context10.next = 5; + _context9.prev = 2; + _context9.next = 5; return kss.getKonnectorAccountStatus(); case 5: - fluidTypes = _context10.sent; + fluidTypes = _context9.sent; if (!fluidTypes) { - _context10.next = 11; + _context9.next = 11; break; } (0, _duration.logDuration)('[Initialization] Fluid Types loaded', startTime); - return _context10.abrupt("return", fluidTypes); + return _context9.abrupt("return", fluidTypes); case 11: this._setInitStepError(_models.InitStepsErrors.CONSOS_ERROR); throw new Error('initFluidTypes: FluidTypes not found'); case 13: - _context10.next = 24; + _context9.next = 24; break; case 15: - _context10.prev = 15; - _context10.t0 = _context10["catch"](2); + _context9.prev = 15; + _context9.t0 = _context9["catch"](2); this._setInitStepError(_models.InitStepsErrors.CONSOS_ERROR); - _logger.default.error('Initialization error - : ', _context10.t0); - errorMessage = "Initialization error - initFluidTypes: ".concat(JSON.stringify(_context10.t0)); + _logger.default.error('Initialization error - : ', _context9.t0); + errorMessage = "Initialization error - initFluidTypes: ".concat(JSON.stringify(_context9.t0)); logStack('error', errorMessage); _logger.default.error(errorMessage); - Sentry.captureException(_context10.t0); - throw _context10.t0; + Sentry.captureException(_context9.t0); + throw _context9.t0; case 24: case "end": - return _context10.stop(); + return _context9.stop(); } } - }, _callee10, this, [[2, 15]]); + }, _callee9, this, [[2, 15]]); })); function initFluidTypes() { return _initFluidTypes.apply(this, arguments); @@ -27363,52 +26965,52 @@ var InitializationService = /*#__PURE__*/function () { }() /** * For each fluid get the trigger status and the last data date - * success return: FluidStatus[] - * failure throw error + * - success return: FluidStatus[] + * - failure throw error */ }, { key: "initFluidStatus", value: function () { - var _initFluidStatus = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee11() { + var _initFluidStatus = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee10() { var startTime, fs, fluidStatus, errorMessage; - return _regenerator.default.wrap(function _callee11$(_context11) { + return _regenerator.default.wrap(function _callee10$(_context10) { while (1) { - switch (_context11.prev = _context11.next) { + switch (_context10.prev = _context10.next) { case 0: startTime = performance.now(); fs = new _fluid.default(this._client); - _context11.prev = 2; - _context11.next = 5; + _context10.prev = 2; + _context10.next = 5; return fs.getFluidStatus(); case 5: - fluidStatus = _context11.sent; + fluidStatus = _context10.sent; if (!fluidStatus) { - _context11.next = 11; + _context10.next = 11; break; } (0, _duration.logDuration)('[Initialization] Fluid Status loaded', startTime); - return _context11.abrupt("return", fluidStatus); + return _context10.abrupt("return", fluidStatus); case 11: this._setInitStepError(_models.InitStepsErrors.CONSOS_ERROR); throw new Error('initFluidStatus: fluidStatus not found'); case 13: - _context11.next = 23; + _context10.next = 23; break; case 15: - _context11.prev = 15; - _context11.t0 = _context11["catch"](2); + _context10.prev = 15; + _context10.t0 = _context10["catch"](2); this._setInitStepError(_models.InitStepsErrors.CONSOS_ERROR); - errorMessage = "Initialization error - initFluidStatus: ".concat(JSON.stringify(_context11.t0)); + errorMessage = "Initialization error - initFluidStatus: ".concat(JSON.stringify(_context10.t0)); logStack('error', errorMessage); _logger.default.error(errorMessage); - Sentry.captureException(_context11.t0); - throw _context11.t0; + Sentry.captureException(_context10.t0); + throw _context10.t0; case 23: case "end": - return _context11.stop(); + return _context10.stop(); } } - }, _callee11, this, [[2, 15]]); + }, _callee10, this, [[2, 15]]); })); function initFluidStatus() { return _initFluidStatus.apply(this, arguments); @@ -27423,48 +27025,48 @@ var InitializationService = /*#__PURE__*/function () { }, { key: "initUserChallenges", value: function () { - var _initUserChallenges = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee12(fluidStatus) { + var _initUserChallenges = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee11(fluidStatus) { var startTime, challengeService, userChallengeList, errorMessage; - return _regenerator.default.wrap(function _callee12$(_context12) { + return _regenerator.default.wrap(function _callee11$(_context11) { while (1) { - switch (_context12.prev = _context12.next) { + switch (_context11.prev = _context11.next) { case 0: startTime = performance.now(); challengeService = new _challenge.default(this._client); - _context12.prev = 2; - _context12.next = 5; + _context11.prev = 2; + _context11.next = 5; return challengeService.buildUserChallengeList(fluidStatus); case 5: - userChallengeList = _context12.sent; + userChallengeList = _context11.sent; if (!userChallengeList) { - _context12.next = 11; + _context11.next = 11; break; } (0, _duration.logDuration)('[Initialization] initUserChallenges', startTime); - return _context12.abrupt("return", userChallengeList); + return _context11.abrupt("return", userChallengeList); case 11: this._setInitStepError(_models.InitStepsErrors.CHALLENGES_ERROR); throw new Error('initUserChallenges: userChallengeList not found'); case 13: - _context12.next = 23; + _context11.next = 23; break; case 15: - _context12.prev = 15; - _context12.t0 = _context12["catch"](2); + _context11.prev = 15; + _context11.t0 = _context11["catch"](2); this._setInitStepError(_models.InitStepsErrors.CHALLENGES_ERROR); - errorMessage = "Initialization error - initUserChallenges: ".concat(JSON.stringify(_context12.t0)); + errorMessage = "Initialization error - initUserChallenges: ".concat(JSON.stringify(_context11.t0)); logStack('error', errorMessage); _logger.default.error(errorMessage); - Sentry.captureException(_context12.t0); - throw _context12.t0; + Sentry.captureException(_context11.t0); + throw _context11.t0; case 23: case "end": - return _context12.stop(); + return _context11.stop(); } } - }, _callee12, this, [[2, 15]]); + }, _callee11, this, [[2, 15]]); })); - function initUserChallenges(_x6) { + function initUserChallenges(_x5) { return _initUserChallenges.apply(this, arguments); } return initUserChallenges; @@ -27477,43 +27079,43 @@ var InitializationService = /*#__PURE__*/function () { }, { key: "initDuelProgress", value: function () { - var _initDuelProgress = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee13(userChallenge) { + var _initDuelProgress = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee12(userChallenge) { var startTime, challengeService, _yield$challengeServi, updatedUserChallenge, dataloads, errorMessage; - return _regenerator.default.wrap(function _callee13$(_context13) { + return _regenerator.default.wrap(function _callee12$(_context12) { while (1) { - switch (_context13.prev = _context13.next) { + switch (_context12.prev = _context12.next) { case 0: startTime = performance.now(); challengeService = new _challenge.default(this._client); - _context13.prev = 2; - _context13.next = 5; + _context12.prev = 2; + _context12.next = 5; return challengeService.initChallengeDuelProgress(userChallenge); case 5: - _yield$challengeServi = _context13.sent; + _yield$challengeServi = _context12.sent; updatedUserChallenge = _yield$challengeServi.updatedUserChallenge; dataloads = _yield$challengeServi.dataloads; (0, _duration.logDuration)('[Initialization] initDuelProgress finished', startTime); - return _context13.abrupt("return", { + return _context12.abrupt("return", { updatedUserChallenge: updatedUserChallenge, dataloads: dataloads }); case 12: - _context13.prev = 12; - _context13.t0 = _context13["catch"](2); + _context12.prev = 12; + _context12.t0 = _context12["catch"](2); this._setInitStepError(_models.InitStepsErrors.CHALLENGES_ERROR); - errorMessage = "Initialization error - : ".concat(JSON.stringify(_context13.t0)); + errorMessage = "Initialization error - : ".concat(JSON.stringify(_context12.t0)); logStack('error', errorMessage); _logger.default.error(errorMessage); - Sentry.captureException(_context13.t0); - throw _context13.t0; + Sentry.captureException(_context12.t0); + throw _context12.t0; case 20: case "end": - return _context13.stop(); + return _context12.stop(); } } - }, _callee13, this, [[2, 12]]); + }, _callee12, this, [[2, 12]]); })); - function initDuelProgress(_x7) { + function initDuelProgress(_x6) { return _initDuelProgress.apply(this, arguments); } return initDuelProgress; @@ -27521,95 +27123,95 @@ var InitializationService = /*#__PURE__*/function () { }, { key: "initConsent", value: function () { - var _initConsent = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee14() { + var _initConsent = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee13() { var startTime, termService, isUpToDate, lastTerm, isLastConsentValidated, versionType, errorMessage; - return _regenerator.default.wrap(function _callee14$(_context14) { + return _regenerator.default.wrap(function _callee13$(_context13) { while (1) { - switch (_context14.prev = _context14.next) { + switch (_context13.prev = _context13.next) { case 0: startTime = performance.now(); - _context14.prev = 1; + _context13.prev = 1; termService = new _terms.default(this._client); - _context14.next = 5; + _context13.next = 5; return termService.isConsentVersionUpToDate(); case 5: - isUpToDate = _context14.sent; - _context14.next = 8; + isUpToDate = _context13.sent; + _context13.next = 8; return termService.getLastTerm(); case 8: - lastTerm = _context14.sent; + lastTerm = _context13.sent; if (lastTerm) { - _context14.next = 12; + _context13.next = 12; break; } _logger.default.info('[Initialization] Init first terms'); - return _context14.abrupt("return", { + return _context13.abrupt("return", { accepted: false, versionType: 'init' }); case 12: if (!isUpToDate) { - _context14.next = 21; + _context13.next = 21; break; } - _context14.next = 15; + _context13.next = 15; return termService.isLastTermValidated(); case 15: - isLastConsentValidated = _context14.sent; + isLastConsentValidated = _context13.sent; if (!isLastConsentValidated) { - _context14.next = 19; + _context13.next = 19; break; } _logger.default.info('[Initialization] Last Consent successfully loaded and valid'); - return _context14.abrupt("return", { + return _context13.abrupt("return", { accepted: true, versionType: 'init' }); case 19: _logger.default.info('[Initialization] Consent not up-to-date'); - return _context14.abrupt("return", { + return _context13.abrupt("return", { accepted: false, versionType: 'init' }); case 21: - _context14.next = 23; + _context13.next = 23; return termService.getTermsVersionType(); case 23: - versionType = _context14.sent; + versionType = _context13.sent; if (!(versionType === 'minor')) { - _context14.next = 27; + _context13.next = 27; break; } _logger.default.info('[Initialization] Minor Terms update detected'); - return _context14.abrupt("return", { + return _context13.abrupt("return", { accepted: false, versionType: 'minor' }); case 27: _logger.default.info('[Initialization] Major Terms update detected'); - return _context14.abrupt("return", { + return _context13.abrupt("return", { accepted: false, versionType: 'major' }); case 31: - _context14.prev = 31; - _context14.t0 = _context14["catch"](1); + _context13.prev = 31; + _context13.t0 = _context13["catch"](1); this._setInitStepError(_models.InitStepsErrors.CONSENT_ERROR); - errorMessage = "Initialization error - initConsent: ".concat(JSON.stringify(_context14.t0)); + errorMessage = "Initialization error - initConsent: ".concat(JSON.stringify(_context13.t0)); logStack('error', errorMessage); _logger.default.error(errorMessage); - Sentry.captureException(_context14.t0); - throw _context14.t0; + Sentry.captureException(_context13.t0); + throw _context13.t0; case 39: - _context14.prev = 39; + _context13.prev = 39; (0, _duration.logDuration)('[Initialization] initConsent finished', startTime); - return _context14.finish(39); + return _context13.finish(39); case 42: case "end": - return _context14.stop(); + return _context13.stop(); } } - }, _callee14, this, [[1, 31, 39, 42]]); + }, _callee13, this, [[1, 31, 39, 42]]); })); function initConsent() { return _initConsent.apply(this, arguments); diff --git a/index.html b/index.html index 96361bbf88d54cb7843585f9c3a515b4459eabc2..9698e3b89fddac44b5d0914c4b9049d8d51249e1 100644 --- a/index.html +++ b/index.html @@ -1 +1 @@ -<!DOCTYPE html><html lang="{{.Locale}}"><head><meta charset="utf-8"><title>Ecolyo</title><link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32"><link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16"><!-- PWA Manifest --><link rel="manifest" href="/manifest.json" crossorigin="use-credentials"><link rel="mask-icon" href="/safari-pinned-tab.svg" color="#297EF2"><meta name="viewport" content="width=device-width,height=device-height,initial-scale=1,viewport-fit=cover"><!-- PWA Chrome --><link rel="icon" sizes="192x192" href="/android-chrome-192x192.png"><link rel="icon" sizes="512x512" href="/android-chrome-512x512.png"><!-- PWA iOS --><link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"><link rel="apple-touch-startup-image" href="/apple-touch-icon.png"><meta name="apple-mobile-web-app-title" content="Ecolyo"><meta name="apple-mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-status-bar-style" content="black"><!-- PWA Colors --><meta name="theme-color" content="#343641"><meta name="background-color" content="#121212">{{.ThemeCSS}} {{.CozyBar}}<script src="//{{.Domain}}/assets/js/piwik.js"></script></head><body><div role="application" class="application" data-cozy="{{.CozyData}}"><script src="vendors/ecolyo.9cebad5ae7ea932ed345.js"></script><script src="app/ecolyo.9a707bce3dd4c125cb58.js"></script></div></body></html> \ No newline at end of file +<!DOCTYPE html><html lang="{{.Locale}}"><head><meta charset="utf-8"><title>Ecolyo</title><link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32"><link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16"><!-- PWA Manifest --><link rel="manifest" href="/manifest.json" crossorigin="use-credentials"><link rel="mask-icon" href="/safari-pinned-tab.svg" color="#297EF2"><meta name="viewport" content="width=device-width,height=device-height,initial-scale=1,viewport-fit=cover"><!-- PWA Chrome --><link rel="icon" sizes="192x192" href="/android-chrome-192x192.png"><link rel="icon" sizes="512x512" href="/android-chrome-512x512.png"><!-- PWA iOS --><link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"><link rel="apple-touch-startup-image" href="/apple-touch-icon.png"><meta name="apple-mobile-web-app-title" content="Ecolyo"><meta name="apple-mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-status-bar-style" content="black"><!-- PWA Colors --><meta name="theme-color" content="#343641"><meta name="background-color" content="#121212">{{.ThemeCSS}} {{.CozyBar}}<script src="//{{.Domain}}/assets/js/piwik.js"></script></head><body><div role="application" class="application" data-cozy="{{.CozyData}}"><script src="vendors/ecolyo.9cebad5ae7ea932ed345.js"></script><script src="app/ecolyo.6085fc8ae835cd7aff93.js"></script></div></body></html> \ No newline at end of file