fleetmap-reports 2.0.18 → 2.0.20

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.18",
3
+ "version": "2.0.20",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/kms-report.js CHANGED
@@ -45,7 +45,7 @@ async function createKmsReportByDevice (from, to, userData, traccarInstance) {
45
45
 
46
46
  if (isClientSide() && (allDevices.length > 50 || ((new Date(to).getTime() - new Date(from).getTime()) > (1000 * 60 * 60 * 24 * 15))) && userData.groupByDay) {
47
47
  const sliced = automaticReports.sliceArray(allDevices, 1)
48
- await executeServerSide('kms-report', allData, sliced, from, to, userData, allDevices.length)
48
+ await executeServerSide('kms-report', allData, sliced, from, to, userData, allDevices.length, traccarInstance)
49
49
  } else {
50
50
  if (userData.allWeek && userData.groupByDay) {
51
51
  const dates = getDates(from, to, userData.user.attributes.timezone || getUserPartner(userData.user).timezone)
@@ -89,11 +89,7 @@ async function createSpeedingReportByDevice (from, to, userData, traccarInstance
89
89
  let deviceCount = 0
90
90
  for (const sliced of _sliced) {
91
91
  await Promise.all(sliced.map(async slice => {
92
- const { routes, events } = await getEvents(traccarInstance, from, to, slice, userData, deviceCount, devices.length, slice.length)
93
- if (events.length > 0) {
94
- const devicesProcessed = processDevices(from, to, slice, events, routes, userData)
95
- allData.devices.push(...devicesProcessed)
96
- }
92
+ allData.devices = allData.devices.concat(await getEvents(traccarInstance, from, to, slice, userData, deviceCount, devices.length, slice.length, slice))
97
93
  deviceCount = deviceCount + slice.length
98
94
  if (processServerSide()) {
99
95
  console.log('LOADING_MESSAGE:' + slice[0].name)
@@ -125,7 +121,7 @@ async function createSpeedingReportByDriver (from, to, userData, traccarInstance
125
121
  return { drivers: _drivers }
126
122
  }
127
123
 
128
- async function getEvents (traccarInstance, from, to, devices, userData, deviceCount, totalDevices, sliceSize) {
124
+ async function getEvents (traccarInstance, from, to, devices, userData, deviceCount, totalDevices, sliceSize, slice) {
129
125
  if (processServerSide()) {
130
126
  const url = `https://${process.env.SERVER_HOST}/reports/speeding-report/getEvents`
131
127
  return axios.post(url, { from, to, devices, userData, deviceCount, totalDevices, sliceSize }, { withCredentials: true }).then(d => d.data)
@@ -153,7 +149,10 @@ async function getEvents (traccarInstance, from, to, devices, userData, deviceCo
153
149
  events.push(...traccarEvents)
154
150
  }
155
151
  }
156
- return { routes, events }
152
+ if (events.length > 0) {
153
+ return processDevices(from, to, slice, events, routes, userData)
154
+ }
155
+ return []
157
156
  }
158
157
  }
159
158
 
package/src/util/utils.js CHANGED
@@ -1,4 +1,3 @@
1
- import axios from 'axios'
2
1
  const turf = require('@turf/helpers')
3
2
  const { getUserPartner } = require('fleetmap-partners')
4
3
  const messages = require('../../lang')
@@ -128,7 +127,7 @@ function getDates (startDate, endDate, timezone) {
128
127
  }
129
128
 
130
129
  function getImage (url) {
131
- return axios.get(url, { responseType: 'arraybuffer' }).then(d => d.data)
130
+ return require('axios').get(url, { responseType: 'arraybuffer' }).then(d => d.data)
132
131
  }
133
132
 
134
133
  async function getImageBase64 (url) {
@@ -228,7 +227,7 @@ function weekDaySelected (date, weekDays) {
228
227
  (date.getDay() === 6 && weekDays.saturday))
229
228
  }
230
229
 
231
- async function executeServerSide (type, allData, sliced, from, to, userData, totalDevices) {
230
+ async function executeServerSide (type, allData, sliced, from, to, userData, totalDevices, { axios }) {
232
231
  let deviceCount = 0
233
232
  console.log('PROGRESS_PERC:1')
234
233
  const maxRequests = 10