From 463006bf86b86e637638af724602393e23ea46a7 Mon Sep 17 00:00:00 2001 From: Benjamin Blanchard Date: Wed, 25 Jun 2025 15:28:34 -0400 Subject: [PATCH] don't await response from csv export endpoint --- .../src/api/services/AnalyticsService.ts | 32 +++++++++++++------ .../store/experiments.effects.spec.ts | 1 + .../experiments/store/experiments.effects.ts | 8 +++-- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/backend/packages/Upgrade/src/api/services/AnalyticsService.ts b/backend/packages/Upgrade/src/api/services/AnalyticsService.ts index f993546a1e..4c89f63fae 100644 --- a/backend/packages/Upgrade/src/api/services/AnalyticsService.ts +++ b/backend/packages/Upgrade/src/api/services/AnalyticsService.ts @@ -170,6 +170,22 @@ export class AnalyticsService { public async getCSVData(experimentId: string, email: string, logger: UpgradeLogger): Promise { logger.info({ message: `Inside getCSVData ${experimentId} , ${email}` }); + + const experimentDetails: ExperimentDetailsForCSVData[] = + await this.experimentService.getExperimentDetailsForCSVDataExport(experimentId); + if (!experimentDetails || experimentDetails.length === 0) { + throw new HttpError(404, `Experiment not found for id: ${experimentId}`); + } + + this.sendExportData(experimentDetails, email, logger); + return 'Exporting CSV data for the experiment...'; + } + + private async sendExportData( + experimentDetails: ExperimentDetailsForCSVData[], + email: string, + logger: UpgradeLogger + ): Promise { try { const timeStamp = new Date().toISOString(); const folderPath = 'src/api/assets/files/'; @@ -181,13 +197,6 @@ export class AnalyticsService { const userRepository: UserRepository = Container.getCustomRepository(UserRepository, 'export'); const user = await userRepository.findOneBy({ email }); - - const experimentDetails: ExperimentDetailsForCSVData[] = - await this.experimentService.getExperimentDetailsForCSVDataExport(experimentId); - if (!experimentDetails || experimentDetails.length === 0) { - throw new HttpError(404, `Experiment not found for id: ${experimentId}`); - } - const experimentMap = new Map(); const formattedExperiment: ExperimentDetailsForCSVData[] = experimentDetails.reduce((acc, item) => { @@ -225,12 +234,15 @@ export class AnalyticsService { let csvExportData: CSVExportDataRow[]; if (experimentDetails[0].assignmentUnit === ASSIGNMENT_UNIT.WITHIN_SUBJECTS) { - csvExportData = await this.analyticsRepository.getCSVDataForWithInSubExport(experimentId); + csvExportData = await this.analyticsRepository.getCSVDataForWithInSubExport(experimentDetails[0].experimentId); } else { - csvExportData = await this.analyticsRepository.getCSVDataForSimpleExport(formattedExperiment[0], experimentId); + csvExportData = await this.analyticsRepository.getCSVDataForSimpleExport( + formattedExperiment[0], + experimentDetails[0].experimentId + ); } - const queryData = await this.logRepository.getLogPerExperimentQuery(experimentId); + const queryData = await this.logRepository.getLogPerExperimentQuery(experimentDetails[0].experimentId); type queryDataArrayType = typeof queryData; type queryDataType = queryDataArrayType[0]; diff --git a/frontend/projects/upgrade/src/app/core/experiments/store/experiments.effects.spec.ts b/frontend/projects/upgrade/src/app/core/experiments/store/experiments.effects.spec.ts index 6d03325710..0ac0a43e15 100644 --- a/frontend/projects/upgrade/src/app/core/experiments/store/experiments.effects.spec.ts +++ b/frontend/projects/upgrade/src/app/core/experiments/store/experiments.effects.spec.ts @@ -85,6 +85,7 @@ describe('ExperimentEffects', () => { }; notificationService = { showError: jest.fn(), + showInfo: jest.fn(), showSuccess: jest.fn(), }; translate = { diff --git a/frontend/projects/upgrade/src/app/core/experiments/store/experiments.effects.ts b/frontend/projects/upgrade/src/app/core/experiments/store/experiments.effects.ts index d2a19b58e9..1414c142b6 100644 --- a/frontend/projects/upgrade/src/app/core/experiments/store/experiments.effects.ts +++ b/frontend/projects/upgrade/src/app/core/experiments/store/experiments.effects.ts @@ -456,8 +456,12 @@ export class ExperimentEffects { this.experimentDataService.exportExperimentInfo(experimentId, email).pipe( tap(() => { email - ? this.notificationService.showSuccess(`Email will be sent to ${email}`) - : this.notificationService.showSuccess('Email will be sent to registered email'); + ? this.notificationService.showInfo( + `Export requested. If the export succeeds, email will be sent to ${email}` + ) + : this.notificationService.showInfo( + 'Export requested. If the export succeeds, email will be sent to registered email' + ); }), map(() => experimentAction.actionExportExperimentInfoSuccess()), catchError(() => [experimentAction.actionExportExperimentInfoFailure()])