diff --git a/src/migrations/migration.service.ts b/src/migrations/migration.service.ts index 7b0c045e05f8d8fead1f2e29ca92b953f2e42115..2746f148312d76f019c5910ea088ada15bbb0802 100644 --- a/src/migrations/migration.service.ts +++ b/src/migrations/migration.service.ts @@ -15,17 +15,17 @@ import { Migration, MigrationResult } from './migration.type' export class MigrationService { private readonly _client: Client - private readonly _setinitStepError: React.Dispatch< + private readonly _setInitStepError: React.Dispatch< React.SetStateAction<InitStepsErrors | null> > constructor( _client: Client, - _setinitStepError: React.Dispatch< + _setInitStepError: React.Dispatch< React.SetStateAction<InitStepsErrors | null> > ) { this._client = _client - this._setinitStepError = _setinitStepError + this._setInitStepError = _setInitStepError } /** * Return schema version @@ -74,7 +74,7 @@ export class MigrationService { const result = await migrate(migration, this._client) if (result.type === MIGRATION_RESULT_FAILED) { // Error in case of second failure - this._setinitStepError(InitStepsErrors.MIGRATION_ERROR) + this._setInitStepError(InitStepsErrors.MIGRATION_ERROR) logApp.error(migrationLog(migration, result)) Sentry.captureException(migrationLog(migration, result)) throw new Error() diff --git a/src/services/initialization.service.ts b/src/services/initialization.service.ts index 9ca9943cb59c2440f26b11d4849f0cc5c9324397..13ee9ccb023351b1f1ec377c78bfbed8ca9fd387 100644 --- a/src/services/initialization.service.ts +++ b/src/services/initialization.service.ts @@ -57,21 +57,21 @@ const logStack = logger.namespace('initializationService') export default class InitializationService { private readonly _client: Client - private readonly _setinitStep: React.Dispatch<React.SetStateAction<InitSteps>> - private readonly _setinitStepError: React.Dispatch< + private readonly _setInitStep: React.Dispatch<React.SetStateAction<InitSteps>> + private readonly _setInitStepError: React.Dispatch< React.SetStateAction<InitStepsErrors | null> > constructor( _client: Client, - _setinitStep: React.Dispatch<React.SetStateAction<InitSteps>>, - _setinitStepError: React.Dispatch< + _setInitStep: React.Dispatch<React.SetStateAction<InitSteps>>, + _setInitStepError: React.Dispatch< React.SetStateAction<InitStepsErrors | null> > ) { this._client = _client - this._setinitStep = _setinitStep - this._setinitStepError = _setinitStepError + this._setInitStep = _setInitStep + this._setInitStepError = _setInitStepError } /** @@ -84,7 +84,7 @@ export default class InitializationService { const startTime = performance.now() const profileService = new ProfileService(this._client) try { - this._setinitStep(InitSteps.PROFILE) + this._setInitStep(InitSteps.PROFILE) const loadedProfile = await profileService.getProfile() if (!loadedProfile) { // Population with the data @@ -97,7 +97,7 @@ export default class InitializationService { // create schema to latest version await initSchemaDoctype(this._client, migrations.length) } else { - this._setinitStepError(InitStepsErrors.PROFILE_ERROR) + this._setInitStepError(InitStepsErrors.PROFILE_ERROR) throw new Error('initProfile: Profile not created') } } @@ -109,7 +109,7 @@ export default class InitializationService { logDuration('[Initialization] Profile loaded and updated in', startTime) return updatedProfile } catch (error) { - this._setinitStepError(InitStepsErrors.PROFILE_ERROR) + this._setInitStepError(InitStepsErrors.PROFILE_ERROR) const errorMessage = `Initialization error - initProfile: :${JSON.stringify( error @@ -135,7 +135,7 @@ export default class InitializationService { logDuration('[Initialization] ProfileType loaded', startTime) return loadedProfileType } catch (error) { - this._setinitStepError(InitStepsErrors.PROFILETYPE_ERROR) + this._setInitStepError(InitStepsErrors.PROFILETYPE_ERROR) const errorMessage = `Initialization error - initProfileType: ${JSON.stringify( error )}` @@ -154,7 +154,7 @@ export default class InitializationService { logDuration('[Initialization] ProfileEcogesture loaded', startTime) return loadedProfileEcogesture } catch (error) { - this._setinitStepError(InitStepsErrors.PROFILETYPE_ERROR) + this._setInitStepError(InitStepsErrors.PROFILETYPE_ERROR) const errorMessage = `Initialization error - initProfileEcogesture: ${JSON.stringify( error )}` @@ -167,7 +167,7 @@ export default class InitializationService { public async initEcogesture(hash: string): Promise<string> { const startTime = performance.now() - this._setinitStep(InitSteps.ECOGESTURE) + this._setInitStep(InitSteps.ECOGESTURE) const hashEcogestureType = hashFile(ecogestureData) const ecogestureService = new EcogestureService(this._client) // Populate data if none ecogesture exists @@ -184,7 +184,7 @@ export default class InitializationService { // Check of created document based on count const checkCount = await ecogestureService.getAllEcogestures() if (!checkCount || checkCount?.length !== ecogestureData.length) { - this._setinitStepError(InitStepsErrors.ECOGESTURE_ERROR) + this._setInitStepError(InitStepsErrors.ECOGESTURE_ERROR) throw new Error( 'initEcogesture: Created ecogesture type entities does not match' ) @@ -192,7 +192,7 @@ export default class InitializationService { logDuration('[Initialization] Ecogesture list created', startTime) return hashEcogestureType } catch (error) { - this._setinitStepError(InitStepsErrors.ECOGESTURE_ERROR) + this._setInitStepError(InitStepsErrors.ECOGESTURE_ERROR) const errorMessage = `Initialization error - initEcogesture: ${JSON.stringify( error )}` @@ -225,7 +225,7 @@ export default class InitializationService { // Check of created document based on count const checkCount = await ecogestureService.getAllEcogestures() if (!checkCount || checkCount?.length !== ecogestureData.length) { - this._setinitStepError(InitStepsErrors.ECOGESTURE_ERROR) + this._setInitStepError(InitStepsErrors.ECOGESTURE_ERROR) throw new Error( 'initEcogesture: Created ecogesture type entities does not match' ) @@ -233,7 +233,7 @@ export default class InitializationService { logDuration('[Initialization] Ecogesture updated', startTime) return hashEcogestureType } catch (error) { - this._setinitStepError(InitStepsErrors.ECOGESTURE_ERROR) + this._setInitStepError(InitStepsErrors.ECOGESTURE_ERROR) const errorMessage = `Initialization error - initEcogesture: ${JSON.stringify( error )}` @@ -295,7 +295,7 @@ export default class InitializationService { public async initChallengeEntity(hash: string): Promise<string> { const startTime = performance.now() - this._setinitStep(InitSteps.CHALLENGES) + this._setInitStep(InitSteps.CHALLENGES) const challengeHash = hashFile(challengeEntityData) const challengeService = new ChallengeService(this._client) // Populate data if none challengeEntity exists @@ -310,7 +310,7 @@ export default class InitializationService { // Check of created document const checkCount = await challengeService.getAllChallengeEntities() if (!checkCount || checkCount?.length !== challengeEntityData.length) { - this._setinitStepError(InitStepsErrors.CHALLENGES_ERROR) + this._setInitStepError(InitStepsErrors.CHALLENGES_ERROR) throw new Error( 'initChallengeEntity: Created challenge entities does not match' ) @@ -318,7 +318,7 @@ export default class InitializationService { logDuration('[Initialization] Challenge entities created', startTime) return challengeHash } catch (error) { - this._setinitStepError(InitStepsErrors.CHALLENGES_ERROR) + this._setInitStepError(InitStepsErrors.CHALLENGES_ERROR) const errorMessage = `Initialization error - initChallengeEntity: ${JSON.stringify( error )}` @@ -341,7 +341,7 @@ export default class InitializationService { // Check of created document const checkCount = await challengeService.getAllChallengeEntities() if (!checkCount || checkCount?.length !== challengeEntityData.length) { - this._setinitStepError(InitStepsErrors.CHALLENGES_ERROR) + this._setInitStepError(InitStepsErrors.CHALLENGES_ERROR) throw new Error( 'initChallengeEntity: Created challenge entities does not match' ) @@ -349,7 +349,7 @@ export default class InitializationService { logDuration('[Initialization] Challenge entities updated', startTime) return challengeHash } catch (error) { - this._setinitStepError(InitStepsErrors.CHALLENGES_ERROR) + this._setInitStepError(InitStepsErrors.CHALLENGES_ERROR) const errorMessage = `Initialization error - initChallengeEntity: ${JSON.stringify( error )}` @@ -380,7 +380,7 @@ export default class InitializationService { // Check of created document const checkCount = await duelService.getAllDuelEntities() if (!checkCount || checkCount?.length !== duelEntityData.length) { - this._setinitStepError(InitStepsErrors.CHALLENGES_ERROR) + this._setInitStepError(InitStepsErrors.CHALLENGES_ERROR) throw new Error( 'initDuelEntity: Created duel entities does not match' ) @@ -388,7 +388,7 @@ export default class InitializationService { logDuration('[Initialization] UserDuel entities created', startTime) return hashDuelEntity } catch (error) { - this._setinitStepError(InitStepsErrors.CHALLENGES_ERROR) + this._setInitStepError(InitStepsErrors.CHALLENGES_ERROR) const errorMessage = `Initialization error - initDuelEntity: ${JSON.stringify( error )}` @@ -411,7 +411,7 @@ export default class InitializationService { // Check of created document const checkCount = await duelService.getAllDuelEntities() if (!checkCount || checkCount?.length !== duelEntityData.length) { - this._setinitStepError(InitStepsErrors.CHALLENGES_ERROR) + this._setInitStepError(InitStepsErrors.CHALLENGES_ERROR) throw new Error( 'initDuelEntity: Created duel entities does not match' ) @@ -419,7 +419,7 @@ export default class InitializationService { logDuration('[Initialization] UserDuel entities updated', startTime) return hashDuelEntity } catch (error) { - this._setinitStepError(InitStepsErrors.CHALLENGES_ERROR) + this._setInitStepError(InitStepsErrors.CHALLENGES_ERROR) const errorMessage = `Initialization error - initDuelEntity: ${JSON.stringify( error )}` @@ -450,7 +450,7 @@ export default class InitializationService { // Check of created document const checkCount = await quizService.getAllQuizEntities() if (!checkCount || checkCount?.length !== quizEntityData.length) { - this._setinitStepError(InitStepsErrors.CHALLENGES_ERROR) + this._setInitStepError(InitStepsErrors.CHALLENGES_ERROR) throw new Error( 'initQuizEntity: Created quiz entities does not match' ) @@ -459,7 +459,7 @@ export default class InitializationService { logDuration('[Initialization] Quiz entities created', startTime) return quizHash } catch (error) { - this._setinitStepError(InitStepsErrors.CHALLENGES_ERROR) + this._setInitStepError(InitStepsErrors.CHALLENGES_ERROR) const errorMessage = `Initialization error - initQuizEntity: ${JSON.stringify( error )}` @@ -482,7 +482,7 @@ export default class InitializationService { // Check of created document const checkCount = await quizService.getAllQuizEntities() if (!checkCount || checkCount?.length !== quizEntityData.length) { - this._setinitStepError(InitStepsErrors.CHALLENGES_ERROR) + this._setInitStepError(InitStepsErrors.CHALLENGES_ERROR) throw new Error( 'initQuizEntity: Created quiz entities does not match' ) @@ -490,7 +490,7 @@ export default class InitializationService { logDuration('[Initialization] Quiz entities updated', startTime) return quizHash } catch (error) { - this._setinitStepError(InitStepsErrors.CHALLENGES_ERROR) + this._setInitStepError(InitStepsErrors.CHALLENGES_ERROR) const errorMessage = `Initialization error - initQuizEntity: ${JSON.stringify( error )}` @@ -525,7 +525,7 @@ export default class InitializationService { !checkCount || checkCount?.length !== explorationEntityData.length ) { - this._setinitStepError(InitStepsErrors.CHALLENGES_ERROR) + this._setInitStepError(InitStepsErrors.CHALLENGES_ERROR) throw new Error( 'initExplorationEntity: Created exploration entities does not match' ) @@ -533,7 +533,7 @@ export default class InitializationService { logDuration('[Initialization] Exploration entities created', startTime) return explorationHash } catch (error) { - this._setinitStepError(InitStepsErrors.CHALLENGES_ERROR) + this._setInitStepError(InitStepsErrors.CHALLENGES_ERROR) const errorMessage = `Initialization error - initExplorationEntity: ${JSON.stringify( error )}` @@ -559,7 +559,7 @@ export default class InitializationService { !checkCount || checkCount?.length !== explorationEntityData.length ) { - this._setinitStepError(InitStepsErrors.CHALLENGES_ERROR) + this._setInitStepError(InitStepsErrors.CHALLENGES_ERROR) throw new Error( 'initExplorationEntity: Created exploration entities does not match' ) @@ -567,7 +567,7 @@ export default class InitializationService { logDuration('[Initialization] Exploration entities updated', startTime) return explorationHash } catch (error) { - this._setinitStepError(InitStepsErrors.CHALLENGES_ERROR) + this._setInitStepError(InitStepsErrors.CHALLENGES_ERROR) const errorMessage = `Initialization error - initExplorationEntity: ${JSON.stringify( error )}` @@ -613,7 +613,7 @@ export default class InitializationService { } } } catch (error) { - this._setinitStepError(InitStepsErrors.ANALYSIS_ERROR) + this._setInitStepError(InitStepsErrors.ANALYSIS_ERROR) const errorMessage = `Initialization error - initAnalysis: ${JSON.stringify( error )}` @@ -638,11 +638,11 @@ export default class InitializationService { logDuration('[Initialization] Fluid Types loaded', startTime) return fluidtypes } else { - this._setinitStepError(InitStepsErrors.CONSOS_ERROR) + this._setInitStepError(InitStepsErrors.CONSOS_ERROR) throw new Error('initFluidTypes: FluidTypes not found') } } catch (error) { - this._setinitStepError(InitStepsErrors.CONSOS_ERROR) + this._setInitStepError(InitStepsErrors.CONSOS_ERROR) logApp.error('Initialization error - : ', error) const errorMessage = `Initialization error - initFluidTypes: ${JSON.stringify( error @@ -663,17 +663,17 @@ export default class InitializationService { const startTime = performance.now() const fs = new FluidService(this._client) try { - this._setinitStep(InitSteps.CONSOS) + this._setInitStep(InitSteps.CONSOS) const fluidStatus = await fs.getFluidStatus() if (fluidStatus) { logDuration('[Initialization] Fluid Status loaded', startTime) return fluidStatus } else { - this._setinitStepError(InitStepsErrors.CONSOS_ERROR) + this._setInitStepError(InitStepsErrors.CONSOS_ERROR) throw new Error('initFluidStatus: fluidStatus not found') } } catch (error) { - this._setinitStepError(InitStepsErrors.CONSOS_ERROR) + this._setInitStepError(InitStepsErrors.CONSOS_ERROR) const errorMessage = `Initialization error - initFluidStatus: ${JSON.stringify( error )}` @@ -702,11 +702,11 @@ export default class InitializationService { logDuration('[Initialization] initUserChallenges', startTime) return userChallengeList } else { - this._setinitStepError(InitStepsErrors.CHALLENGES_ERROR) + this._setInitStepError(InitStepsErrors.CHALLENGES_ERROR) throw new Error('initUserChallenges: userChallengeList not found') } } catch (error) { - this._setinitStepError(InitStepsErrors.CHALLENGES_ERROR) + this._setInitStepError(InitStepsErrors.CHALLENGES_ERROR) const errorMessage = `Initialization error - initUserChallenges: ${JSON.stringify( error )}` @@ -734,7 +734,7 @@ export default class InitializationService { logDuration('[Initialization] initDuelProgress finished', startTime) return { updatedUserChallenge, dataloads } } catch (error) { - this._setinitStepError(InitStepsErrors.CHALLENGES_ERROR) + this._setInitStepError(InitStepsErrors.CHALLENGES_ERROR) const errorMessage = `Initialization error - : ${JSON.stringify(error)}` logStack('error', errorMessage) logApp.error(errorMessage) @@ -750,7 +750,7 @@ export default class InitializationService { } const startTime = performance.now() try { - this._setinitStep(InitSteps.CONSENT) + this._setInitStep(InitSteps.CONSENT) const termService = new TermsService(this._client) const isUpToDate = await termService.isConsentVersionUpToDate() const lastTerm = await termService.getLastTerm() @@ -789,7 +789,7 @@ export default class InitializationService { return termsStatus } catch (error) { - this._setinitStepError(InitStepsErrors.CONSENT_ERROR) + this._setInitStepError(InitStepsErrors.CONSENT_ERROR) const errorMessage = `Initialization error - initConsent: ${JSON.stringify( error )}`