diff --git a/lib/actions/report-actions.js b/lib/actions/report-actions.js index bbedaa037..b898bbdee 100644 --- a/lib/actions/report-actions.js +++ b/lib/actions/report-actions.js @@ -1,62 +1,50 @@ // @flow import type { ClientReportCreationRequest, ReportCreationResponse, } from '../types/report-types.js'; -import type { CallServerEndpoint } from '../utils/call-server-endpoint.js'; +import { sendReports as callSendReports } from '../utils/reports-service.js'; const sendReportActionTypes = Object.freeze({ started: 'SEND_REPORT_STARTED', success: 'SEND_REPORT_SUCCESS', failed: 'SEND_REPORT_FAILED', }); -const callServerEndpointOptions = { timeout: 60000 }; const sendReport = - ( - callServerEndpoint: CallServerEndpoint, - ): (( + (): (( request: ClientReportCreationRequest, ) => Promise) => async request => { - const { id, ...report } = request; - const response = await callServerEndpoint( - 'create_report', - report, - callServerEndpointOptions, - ); - return { id: response.id }; + const { + reportIDs: [id], + } = await callSendReports([request]); + + if (!id) { + throw new Error('Server did not return report ID'); + } + return { id }; }; const sendReportsActionTypes = Object.freeze({ started: 'SEND_REPORTS_STARTED', success: 'SEND_REPORTS_SUCCESS', failed: 'SEND_REPORTS_FAILED', }); const sendReports = - ( - callServerEndpoint: CallServerEndpoint, - ): (( + (): (( reports: $ReadOnlyArray, ) => Promise) => async clientReports => { - const reports = clientReports.map(clientReport => { - const { id, ...report } = clientReport; - return report; - }); - await callServerEndpoint( - 'create_reports', - { reports }, - callServerEndpointOptions, - ); + await callSendReports(clientReports); }; const queueReportsActionType = 'QUEUE_REPORTS'; export { sendReportActionTypes, sendReport, sendReportsActionTypes, sendReports, queueReportsActionType, };