diff --git a/lib/actions/report-actions.js b/lib/actions/report-actions.js --- a/lib/actions/report-actions.js +++ b/lib/actions/report-actions.js @@ -4,28 +4,26 @@ 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({ @@ -34,21 +32,11 @@ 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';