fleetmap-reports 2.0.223 → 2.0.225

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "2.0.223",
3
+ "version": "2.0.225",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -10,6 +10,7 @@ const traccarConfig = {
10
10
  }
11
11
  const axios = require('axios').create({ ...traccarConfig.baseOptions, baseURL: traccarConfig.basePath })
12
12
  process.env.TRACCAR_API_REPORTS = 'https://ltqgfyvcklxzaonv7h4rlmghai0rszop.lambda-url.us-east-1.on.aws/api'
13
+ process.env.SERVER_HOST = 'api.pinme.io'
13
14
  const getReports = async (email, password) => {
14
15
  try {
15
16
  email = email || process.env.email
@@ -22,7 +22,7 @@ const { checkGeofenceIn } = require('./util/geofence')
22
22
  const { parallel } = require('./util/parallel')
23
23
  const { getDataByDay } = require('./util/trips')
24
24
  const axios = require('axios').default
25
- const sliceSize = 5
25
+ const sliceSize = 1
26
26
  const deviceChunk = 5
27
27
  const fileName = 'ZoneReport'
28
28
 
@@ -84,12 +84,26 @@ async function createZoneReport (from, to, userData, traccar) {
84
84
  const sliced = automaticReports.sliceArray(devices, sliceSize)
85
85
 
86
86
  let deviceCount = 0
87
- for (const slice of sliced) {
88
- const url = `https://${process.env.SERVER_HOST}/pinmeapi/reports/zone-report-processing`
89
- const processed = await traccar.axios.post(url, { from, to, userData, slice, deviceCount, devices, reportRangeDays }).then(d => d.data)
87
+ const url = `https://${process.env.SERVER_HOST}/pinmeapi/reports/zone-report-processing`
88
+
89
+ const promises = sliced.map(slice =>
90
+ traccar.axios.post(url, {
91
+ from,
92
+ to,
93
+ userData,
94
+ slice,
95
+ deviceCount: deviceCount++,
96
+ devices,
97
+ reportRangeDays
98
+ }).then(response => {
99
+ console.log(url, 'done')
100
+ return response.data
101
+ }).catch(e => console.error(e.message, e.response?.data))
102
+ )
103
+ const results = await Promise.all(promises)
104
+ results.forEach(processed => {
90
105
  allData.devices.push(...processed)
91
- deviceCount = deviceCount + slice.length
92
- }
106
+ })
93
107
 
94
108
  reportData.push(allData)
95
109