Skip to content

Commit

Permalink
[INT-1312][node-onfleet] Fix PR comments & add support for startDate,…
Browse files Browse the repository at this point in the history
… endDate
  • Loading branch information
Lisandro Bigi authored and Lisandro Bigi committed May 22, 2024
1 parent 0f81f20 commit 9b72f70
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 21 deletions.
17 changes: 15 additions & 2 deletions README.es.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Estas son las operaciones disponibles para cada endpoint:
| [Tasks](https://docs.onfleet.com/reference/tasks) | get(query)<br />get(id)<br />get(shortId, 'shortId') | create(obj)<br />clone(id)<br />clone(id, obj)<br />forceComplete(id, obj)<br />batchCreate(obj)<br />batchCreateAsync(obj)<br />getBatch(id)<br />autoAssign(obj)<br />matchMetadata(obj) | update(id, obj) | deleteOne(id) |
| [Teams](https://docs.onfleet.com/reference/teams) | get()<br />get(id)<br />getWorkerEta(id, obj)<br />getTasks(id) | create(obj)<br />autoDispatch(id, obj) | update(id, obj) | deleteOne(id) |
| [Webhooks](https://docs.onfleet.com/reference/webhooks) | get() | create(obj) | x | deleteOne(id) |
| [Workers](https://docs.onfleet.com/reference/workers) | get()<br />get(query)<br />get(id)<br />getByLocation(obj)<br />getSchedule(id)<br />getTasks(id) | create(obj)<br />setSchedule(id, obj)<br />matchMetadata(obj)<br />getDeliveryManifest(hubId, workerId, googleAPIKey) | update(id, obj)<br />insertTask(id, obj) | deleteOne(id) |
| [Workers](https://docs.onfleet.com/reference/workers) | get()<br />get(query)<br />get(id)<br />getByLocation(obj)<br />getSchedule(id)<br />getTasks(id) | create(obj)<br />setSchedule(id, obj)<br />matchMetadata(obj)<br />getDeliveryManifest(obj) | update(id, obj)<br />insertTask(id, obj) | deleteOne(id) |

#### Peticiones GET
Para obtener todos los elementos disponibles en un recurso, éstas llamadas retornan un `Promise` con el arreglo de los resultados:
Expand Down Expand Up @@ -213,6 +213,19 @@ const data = {
onfleetApi.workers.create(data);
```
##### Ejemplos de `getDeliveryManifest()`
```js
const data = {
hubId: "<hubId>", // Required
workerId: "<workerId", // Required
googleApiKey: "<google_direction_api_key>", // Optional
startDate: "<startDate>", // Optional
endDate: "<endDate>" // Optional
};

onfleetApi.workers.getDeliveryManifest(data);
```
Otras peticiones POST incluyen `clone`, `forceComplete`, `batchCreate`,`batchCreateAsync`, `autoAssign` en el recurso *Tasks*; `setSchedule` en el recurso *Workers*; `autoDispatch` en el recurso *Teams*; y `matchMetadata` en todos los recursos que lo soportan. Por ejemplo:
```js
Expand All @@ -223,7 +236,7 @@ onfleetApi.tasks.batchCreateAsync({ data });
onfleetApi.tasks.autoAssign({ data });

onfleetApi.workers.setSchedule('<24_digit_ID>', { data });
onfleetAPI.workers.getDeliveryManifest('hubId', 'workerId', 'googleAPIKey')
onfleetAPI.workers.getDeliveryManifest({ data })

onfleetApi.teams.autoDispatch('<24_digit_ID>', { data });

Expand Down
17 changes: 15 additions & 2 deletions README.fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Voici les opérations CRUD prises en charge pour chaque ordinateur d'extrémité
| [Tasks](https://docs.onfleet.com/reference#tasks) | get(query)<br />get(id)<br />get(shortId, 'shortId') | create(obj)<br />clone(id)<br />clone(id, obj)<br />forceComplete(id, obj)<br />batchCreate(obj)<br />batchCreateAsync(obj)<br />getBatch(id)<br />autoAssign(obj)<br />matchMetadata(obj) | update(id, obj) | deleteOne(id) |
| [Teams](https://docs.onfleet.com/reference#teams) | get()<br />get(id)<br />getWorkerEta(id, obj)<br />getTasks(id) | create(obj)<br />autoDispatch(id, obj) | update(id, obj) | deleteOne(id) |
| [Webhooks](https://docs.onfleet.com/reference#webhooks) | get() | create(obj) | x | deleteOne(id) |
| [Workers](https://docs.onfleet.com/reference#workers) | get()<br />get(query)<br />get(id)<br />getByLocation(obj)<br />getSchedule(id)<br />getTasks(id) | create(obj)<br />setSchedule(id, obj)<br />matchMetadata(obj)<br />getDeliveryManifest(hubId, workerId, googleAPIKey) | update(id, obj)<br />insertTask(id, obj) | deleteOne(id) |
| [Workers](https://docs.onfleet.com/reference#workers) | get()<br />get(query)<br />get(id)<br />getByLocation(obj)<br />getSchedule(id)<br />getTasks(id) | create(obj)<br />setSchedule(id, obj)<br />matchMetadata(obj)<br />getDeliveryManifest(obj) | update(id, obj)<br />insertTask(id, obj) | deleteOne(id) |

#### Demandes GET
Pour obtenir tous les documents d'un noeud final, cela renvoie une `Promise` contenant un tableau de résultats:
Expand Down Expand Up @@ -215,6 +215,19 @@ const data = {
onfleetApi.workers.create(data);
```
##### Exemples de `getDeliveryManifest()`
```js
const data = {
hubId: "<hubId>", // Required
workerId: "<workerId", // Required
googleApiKey: "<google_direction_api_key>", // Optional
startDate: "<startDate>", // Optional
endDate: "<endDate>" // Optional
};

onfleetApi.workers.getDeliveryManifest(data);
```
Les requêtes POST étendues incluent `clone`,` forceComplete`, `batchCreate`,`batchCreateAsync`,` autoAssign`, `setSchedule`, `autoDispatch`:
```js
Expand All @@ -225,7 +238,7 @@ onfleetApi.tasks.batchCreateAsync({ data });
onfleetApi.tasks.autoAssign({ data });

onfleetApi.workers.setSchedule('<24_digit_ID>', { data });
onfleetAPI.workers.getDeliveryManifest('hubId', 'workerId', 'googleAPIKey');
onfleetAPI.workers.getDeliveryManifest({ data });

onfleetApi.teams.autoDispatch('<24_digit_ID>', { data });

Expand Down
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Here are the operations available for each entity:
| [Tasks](https://docs.onfleet.com/reference#tasks) | get(query)<br />get(id)<br />get(shortId, 'shortId') | create(obj)<br />clone(id)<br />clone(id, obj)<br />forceComplete(id, obj)<br />batchCreate(obj)<br />batchCreateAsync(obj)<br />getBatch(id)<br />autoAssign(obj)<br />matchMetadata(obj) | update(id, obj) | deleteOne(id) |
| [Teams](https://docs.onfleet.com/reference#teams) | get()<br />get(id)<br />getWorkerEta(id, obj)<br />getTasks(id) | create(obj)<br />autoDispatch(id, obj) | update(id, obj) | deleteOne(id) |
| [Webhooks](https://docs.onfleet.com/reference#webhooks) | get() | create(obj) | x | deleteOne(id) |
| [Workers](https://docs.onfleet.com/reference#workers) | get()<br />get(query)<br />get(id)<br />getByLocation(obj)<br />getSchedule(id)<br />getTasks(id) | create(obj)<br />setSchedule(id, obj)<br />matchMetadata(obj)<br />getDeliveryManifest(hubId, workerId, googleAPIKey) | update(id, obj)<br />insertTask(id, obj) | deleteOne(id) |
| [Workers](https://docs.onfleet.com/reference#workers) | get()<br />get(query)<br />get(id)<br />getByLocation(obj)<br />getSchedule(id)<br />getTasks(id) | create(obj)<br />setSchedule(id, obj)<br />matchMetadata(obj)<br />getDeliveryManifest(obj) | update(id, obj)<br />insertTask(id, obj) | deleteOne(id) |

#### GET Requests
To get all the documents within an endpoint, this returns a `Promise` containing an array of results:
Expand Down Expand Up @@ -214,6 +214,19 @@ const data = {
onfleetApi.workers.create(data);
```
##### Examples of `getDeliveryManifest()`
```js
const data = {
hubId: "<hubId>", // Required
workerId: "<workerId", // Required
googleApiKey: "<google_direction_api_key>", // Optional
startDate: "<startDate>", // Optional
endDate: "<endDate>" // Optional
};

onfleetApi.workers.getDeliveryManifest(data);
```
Extended POST requests include `clone`, `forceComplete`, `batchCreate`,`batchCreateAsync`, `autoAssign` on the *Tasks* endpoint; `setSchedule` on the *Workers* endpoint; `autoDispatch` on the *Teams* endpoint; and `matchMetadata` on all supported entities. For instance:
```js
Expand All @@ -224,7 +237,7 @@ onfleetApi.tasks.batchCreateAsync({ data });
onfleetApi.tasks.autoAssign({ data });

onfleetApi.workers.setSchedule('<24_digit_ID>', { data });
onfleetAPI.workers.getDeliveryManifest('hubId', 'workerId', 'googleAPIKey');
onfleetAPI.workers.getDeliveryManifest({ data });

onfleetApi.teams.autoDispatch('<24_digit_ID>', { data });

Expand Down
17 changes: 15 additions & 2 deletions README.zh-tw.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ onfleetApi.verifyKey(); // Returns a boolean
| [Tasks](https://docs.onfleet.com/reference/tasks) | get(query)<br />get(id)<br />get(shortId, 'shortId') | create(obj)<br />clone(id)<br />clone(id, obj)<br />forceComplete(id, obj)<br />batchCreate(obj)<br />batchCreateAsync(obj)<br />getBatch(id)<br />autoAssign(obj)<br />matchMetadata(obj) | update(id, obj) | deleteOne(id) |
| [Teams](https://docs.onfleet.com/reference/teams) | get()<br />get(id)<br />getWorkerEta(id, obj)<br />getTasks(id) | create(obj)<br />autoDispatch(id, obj) | update(id, obj) | deleteOne(id) |
| [Webhooks](https://docs.onfleet.com/reference/webhooks) | get() | create(obj) | x | deleteOne(id) |
| [Workers](https://docs.onfleet.com/reference/workers) | get()<br />get(query)<br />get(id)<br />getByLocation(obj)<br />getSchedule(id)<br />getTasks(id) | create(obj)<br />setSchedule(id, obj)<br />matchMetadata(obj)<br />getDeliveryManifest(hubId, workerId, googleAPIKey) | update(id, obj)<br />insertTask(id, obj) | deleteOne(id) |
| [Workers](https://docs.onfleet.com/reference/workers) | get()<br />get(query)<br />get(id)<br />getByLocation(obj)<br />getSchedule(id)<br />getTasks(id) | create(obj)<br />setSchedule(id, obj)<br />matchMetadata(obj)<br />getDeliveryManifest(obj) | update(id, obj)<br />insertTask(id, obj) | deleteOne(id) |

#### GET 請求
展示所有資源的指令如下,回應的主體為包含一陣列的[`Promise`物件](https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/Promise):
Expand Down Expand Up @@ -214,6 +214,19 @@ const data = {
onfleetApi.workers.create(data);
```
##### 使用`getDeliveryManifest`提交指定資源的範例
```js
const data = {
hubId: "<hubId>", // Required
workerId: "<workerId", // Required
googleApiKey: "<google_direction_api_key>", // Optional
startDate: "<startDate>", // Optional
endDate: "<endDate>" // Optional
};

onfleetApi.workers.getDeliveryManifest(data);
```
其他延伸的POST請求包含了*Tasks*節點上的`clone`, `forceComplete`, `batchCreate`,`batchCreateAsync`, `autoAssign`,*Workers*節點上的`setSchedule`,*Teams*節點上的`autoDispatch`,以及所有支持節點上的`matchMetadata`
```js
Expand All @@ -224,7 +237,7 @@ onfleetApi.tasks.batchCreateAsync({ data });
onfleetApi.tasks.autoAssign({ data });

onfleetApi.workers.setSchedule('<24_digit_ID>', { data });
onfleetAPI.workers.getDeliveryManifest('hubId', 'workerId', 'googleAPIKey');
onfleetAPI.workers.getDeliveryManifest({ data });

onfleetApi.teams.autoDispatch('<24_digit_ID>', { data });

Expand Down
30 changes: 21 additions & 9 deletions lib/Methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const Methods = (key, api, ...args) => {
altPath,
method,
queryParams,
deliveryManifestObject,
timeoutInMilliseconds,
} = key;
const operations = { method }['method']; // eslint-disable-line
Expand Down Expand Up @@ -111,15 +112,26 @@ const Methods = (key, api, ...args) => {
}
}
// Reference https://docs.onfleet.com/reference/delivery-manifest
if (path.includes("integrations")) {
body = {
path: `providers/manifest/generate?hubId=${args[0]}&workerId=${args[1]}`,
method: "GET",
};
if (args[2]) {
api.api.headers["X-API-Key"] = 'Google ' + args[2];
}
hasBody = true;
if (deliveryManifestObject && args && args.length > 0) {
let hasBody = false;
args.forEach((item) => {
if (item.hubId && item.workerId) {
body = {
path: `providers/manifest/generate?hubId=${item.hubId}&workerId=${item.workerId}`,
method: "GET",
};
hasBody = true;
}
if (item.googleApiKey) {
api.api.headers["X-API-Key"] = "Google " + item.googleApiKey;
}
if (item.startDate || item.endDate) {
const queryParams = {};
if (item.startDate) queryParams.startDate = item.startDate;
if (item.endDate) queryParams.endDate = item.endDate;
url = util.appendQueryParameters(url, queryParams);
}
});
}

// Send the HTTP request through the rate limiter
Expand Down
3 changes: 1 addition & 2 deletions lib/resources/Workers.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ class Workers extends Resource {
},
getDeliveryManifest: {
path: '/integrations/marketplace',
altPath: '/integrations/marketplace',
method: 'POST',
queryParams: true,
deliveryManifestObject: true,
},
matchMetadata: {
path: '/workers/metadata',
Expand Down
21 changes: 20 additions & 1 deletion test/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,26 @@ module.exports = {
timeLastModified: 1692746334342,
},
hubAddress: "1111 South Figueroa Street, Los Angeles, California 90015",
turnByTurn: [],
turnByTurn: [
{
start_address: "1403 W Pico Blvd, Los Angeles, CA 90015, USA",
end_address: "2695 E Katella Ave, Anaheim, CA 92806, USA",
eta: 1692992466000,
driving_distance: "30.6 mi",
steps: [
"Head southeast on 12th St E toward S Figueroa StPartial restricted usage road",
"Turn right onto Flower St",
"Turn left onto the Interstate 10 E ramp to 18th St",
"Merge onto I-10 E",
"Take the exit onto I-5 S toward Santa Ana",
"Take exit 109A for Katella Ave",
"Turn right onto E Katella AvePass by Comerica Bank (on the right in 1.3 mi)",
"Turn left onto S Douglass Rd",
"Turn right onto Stanley Cup Wy",
"Turn right"
]
}
],
totalDistance: null
},
};
11 changes: 10 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ const updateDetail = {
phone: '+18883133131',
};

const deliveryManifestObject = {
hubId: 'kyfYe*wyVbqfomP2HTn5dAe1~*O',
workerId: 'kBUZAb7pREtRn*8wIUCpjnPu',
googleApiKey: '<google_direction_api_key>',
startDate: '1455072025000',
endDate: '1455072025000'
};

chai.should();
chai.use(chaiAsPromised);

Expand Down Expand Up @@ -261,10 +269,11 @@ describe('HTTP Request testing', () => {
});
});
it('Get compliance information from tasks assigned to Onfleet drivers', () => {
return onfleet.workers.getDeliveryManifest('kyfYe*wyVbqfomP2HTn5dAe1~*O', 'kBUZAb7pREtRn*8wIUCpjnPu')
return onfleet.workers.getDeliveryManifest(deliveryManifestObject)
.then((res) => {
expect(typeof res).to.equal('object');
assert.equal(res.manifestDate, 1694199600000);
assert.equal(res.turnByTurn.length, 1);
});
});
});

0 comments on commit 9b72f70

Please sign in to comment.