Skip to content
Snippets Groups Projects
Commit 0564a338 authored by paultranvan's avatar paultranvan
Browse files

Merge branch 'release-1.1.0'

parents 5eb606ba ef1e76b4
Branches
No related tags found
No related merge requests found
const BASE_URL = 'https://trace.grfmap.com:8081' const BASE_URL = 'https://trace.grfmap.com:8081'
const { requestFactory } = require('cozy-konnector-libs') const { log, errors, requestFactory } = require('cozy-konnector-libs')
const request = requestFactory({ const request = requestFactory({
cheerio: false, cheerio: false,
...@@ -18,7 +18,10 @@ const getFirstAndLastTripTimestamp = async function(token) { ...@@ -18,7 +18,10 @@ const getFirstAndLastTripTimestamp = async function(token) {
const body = { const body = {
user: token user: token
} }
return request(path, { method: 'POST', body }) return request(path, { method: 'POST', body }).catch(err => {
log('info', err && err.message)
throw new Error(errors.VENDOR_DOWN)
})
} }
/** /**
...@@ -36,17 +39,23 @@ const getServerCollectionFromDate = async function( ...@@ -36,17 +39,23 @@ const getServerCollectionFromDate = async function(
collection, collection,
{ excludeFirst = true } = {} { excludeFirst = true } = {}
) { ) {
// Note the expected timestamp is in seconds let results
const startTime = new Date(startDate).getTime() / 1000 try {
const endTime = Date.now() / 1000 // Note the expected timestamp is in seconds
const body = { const startTime = new Date(startDate).getTime() / 1000
user: token, const endTime = Date.now() / 1000
start_time: startTime, const body = {
end_time: endTime, user: token,
key_list: [collection] start_time: startTime,
end_time: endTime,
key_list: [collection]
}
const path = `${BASE_URL}/datastreams/find_entries/timestamp`
results = await request(path, { method: 'POST', body })
} catch (err) {
log('info', err && err.message)
throw new Error(errors.VENDOR_DOWN)
} }
const path = `${BASE_URL}/datastreams/find_entries/timestamp`
const results = await request(path, { method: 'POST', body })
return excludeFirst ? results.phone_data.slice(1) : results.phone_data return excludeFirst ? results.phone_data.slice(1) : results.phone_data
} }
...@@ -58,11 +67,17 @@ const getServerCollectionFromDate = async function( ...@@ -58,11 +67,17 @@ const getServerCollectionFromDate = async function(
* @returns {object} - The full trips for this day * @returns {object} - The full trips for this day
*/ */
const getTripsForDay = async function(token, day) { const getTripsForDay = async function(token, day) {
const path = `${BASE_URL}/timeline/getTrips/${day}` let trips
const body = { try {
user: token const path = `${BASE_URL}/timeline/getTrips/${day}`
const body = {
user: token
}
trips = await request(path, { method: 'POST', body })
} catch (err) {
log('info', err && err.message)
throw new Error(errors.VENDOR_DOWN)
} }
const trips = await request(path, { method: 'POST', body })
return trips.timeline return trips.timeline
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment