fleetmap-reports 2.0.6 → 2.0.8

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.6",
3
+ "version": "2.0.8",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -14,15 +14,15 @@
14
14
  "@turf/distance": "^6.5.0",
15
15
  "@turf/helpers": "^6.5.0",
16
16
  "@turf/point-to-line-distance": "^6.5.0",
17
- "axios": "0.27.2",
17
+ "axios": "1.6.7",
18
18
  "country-reverse-geocoding": "^0.2.2",
19
19
  "docx": "^7.3.0",
20
20
  "file-saver": "^2.0.5",
21
21
  "fleetmap-partners": "^1.0.160",
22
- "json-as-xlsx": "^1.2.1",
22
+ "json-as-xlsx": "2.5.6",
23
23
  "jspdf": "^2.5.1",
24
24
  "jspdf-autotable": "3.6.0",
25
- "moment": "^2.29.4",
25
+ "moment": "2.30.1",
26
26
  "traccar-api": "^1.0.5",
27
27
  "wkt": "^0.1.1"
28
28
  },
@@ -134,7 +134,9 @@ function processDevices (from, to, devices, data) {
134
134
  rain: p.attributes.rain,
135
135
  ignition: p.attributes.ignition,
136
136
  alarm: p.attributes.alarm,
137
- input: p.attributes.input
137
+ input: p.attributes.input,
138
+ di2: p.attributes.di2,
139
+ di3: p.attributes.di3
138
140
  }
139
141
  }
140
142
  })
@@ -313,8 +315,8 @@ function getDigitalPort1Label (row, translations, dAttributes) {
313
315
  return (dAttributes && dAttributes.sensor1) || (row.attributes && row.attributes.sensor1) || translations.report.digital_ports1
314
316
  }
315
317
 
316
- function getDigitalPort2Label (row, translations) {
317
- return row.attributes.door2 || translations.report.digital_ports2
318
+ function getDigitalPort2Label (row, translations, dAttributes) {
319
+ return (dAttributes && dAttributes.sensor2) || (row.attributes && row.attributes.sensor2) || translations.report.digital_ports2
318
320
  }
319
321
 
320
322
  function getDigitalPortValue (row, index, translations, dAttributes) {
@@ -335,6 +337,11 @@ function getDigitalPortValue (row, index, translations, dAttributes) {
335
337
  }
336
338
  break
337
339
  case 2:
340
+ if (row.attributes && row.attributes[dAttributes.sensor2Attribute] !== undefined) {
341
+ return row.attributes[dAttributes.sensor2Attribute]
342
+ ? dAttributes.sensor2on || row.attributes.sensor
343
+ : dAttributes.sensor2off || row.attributes.sensor
344
+ }
338
345
  if (row.attributes && row.attributes.door2) {
339
346
  return translations.report[row.attributes.door2]
340
347
  }
@@ -1,4 +1,3 @@
1
- const { SessionApi } = require('traccar-api')
2
1
  const Index = require('../index')
3
2
  const { isClientSide } = require('../util/utils')
4
3
  const { newDomains } = require('fleetmap-partners')
@@ -14,7 +13,9 @@ const axios = require('axios').create({ ...traccarConfig.baseOptions, baseURL: t
14
13
  const getReports = async (email, password) => {
15
14
  try {
16
15
  console.log('email / pass', process.env.email || email, process.env.password || password)
17
- await new SessionApi(traccarConfig, null, axios).sessionPost(email || process.env.email, password || process.env.password)
16
+ const formData = `email=${encodeURIComponent(email)}&password=${encodeURIComponent(password)}`
17
+ const [cookie] = (await axios.post('/session', formData)).headers['set-cookie']
18
+ axios.defaults.headers.common.cookie = cookie
18
19
  return new Index(traccarConfig, axios)
19
20
  } catch (e) {
20
21
  console.error(e)
@@ -1,5 +1,6 @@
1
1
  const { getReports } = require('./index')
2
2
  const assert = require('assert')
3
+ const xlsx = require('json-as-xlsx')
3
4
  // eslint-disable-next-line no-undef
4
5
  describe('test positions', function () {
5
6
  // eslint-disable-next-line no-undef
@@ -40,17 +41,21 @@ describe('test positions', function () {
40
41
  const report = await getReports(process.env.USER_ARCESE, process.env.PASS_ARCESE)
41
42
  const userData = await report.getUserData()
42
43
  userData.devices = userData.devices.filter(d => d.id === deviceId)
43
- const data = await report.locationReport(
44
- new Date(Date.UTC(2024, 1, 1, 0, 0, 0, 0)),
45
- new Date(Date.UTC(2024, 1, 2, 23, 59, 59, 0)),
46
- userData)
47
- assert.equal(data.length, 1)
48
- console.log('data', data)
49
- const device = data[0].devices.find(d => d.device.id === deviceId)
50
- assert.equal(device.positions.length, 2414) // Total Positions
51
44
  userData.includeDigitalPorts = true
52
- const pdf = await report.loca(userData, data[0])
53
- pdf.save('report.pdf')
45
+ const [data] = await report.locationReport(
46
+ new Date(Date.UTC(2024, 0, 23, 22, 0, 0, 0)),
47
+ new Date(Date.UTC(2024, 0, 24, 23, 59, 59, 0)),
48
+ userData)
49
+ const device = data.devices.find(d => d.device.id === deviceId)
50
+ assert.equal(device.positions.length, 3599) // Total Positions
51
+ const pdf = await report.locationReportToPDF(userData, data)
52
+ pdf.save()
53
+ const excel = report.locationReportToExcel(userData, data)
54
+ xlsx([{
55
+ sheet: 'Sheet1',
56
+ columns: excel.headers,
57
+ content: excel.data
58
+ }], excel.settings)
54
59
  }, 30000)
55
60
  // eslint-disable-next-line no-undef
56
61
  })