Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support OrderV5 and field 'order_uuid' in OrderV4. #100

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion book/en/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@

* [AddressBookV5](code/AddressBookV5.md)
* [AutomaticTerritories](code/AutomaticTerritories.md)
* [Schedules](code/Schedules.md)
* [OrdersV5](code/OrdersV5.md)
* [PodWorkflow](code/PodWorkflow.md)
* [Schedules](code/Schedules.md)
* [TeamManagement](code/TeamManagement.md)
* [VehiclesV5](code/VehiclesV5.md)

Expand Down
24 changes: 12 additions & 12 deletions book/en/code/Orders.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,56 +79,56 @@ Create an Order

### orders.get(id, [callback])

Get an Order Details
Get an Order Details by ID or by UUID

**See**: [https://route4me.io/docs/#get-an-order-details](https://route4me.io/docs/#get-an-order-details)
**Since**: 0.1.11
**Since**: 1.1.0

| Param | Type | Description |
| --- | --- | --- |
| id | <code>number</code> | Order ID |
| id | <code>number</code> \| <code>string</code> | Order ID as number or order UUID as HEX-string |
| [callback] | <code>module:route4me-node~RequestCallback.&lt;jsonschema:Orders.Order&gt;</code> | |

<a id="Orders+list" name="Orders+list"></a>

### orders.list([ids], [callback])

Get all the orders created under the specific Route4Me account
Get all the orders created under the specific Route4Me account by IDs or by UUIDs

**See**: [https://route4me.io/docs/#get-orders-with-details](https://route4me.io/docs/#get-orders-with-details)
**Since**: 0.1.11
**Since**: 1.1.0

| Param | Type | Description |
| --- | --- | --- |
| [ids] | <code>number</code> \| <code>string</code> \| <code>Array.&lt;number&gt;</code> \| <code>Array.&lt;string&gt;</code> | Order IDs in one of the following form: * CSV-string * one ID as string * one ID as number * array of strings * array of numbers If you want to load all Orders: * **Don't pass** this parameter * **OR** pass `ids=undefined` * **OR** pass `ids=false` |
| [ids] | <code>number</code> \| <code>string</code> \| <code>Array.&lt;number&gt;</code> \| <code>Array.&lt;string&gt;</code> | Order IDs or order UUIDs in one of the following form: * one UUID as HEX-string * UUIDs as CSV-HEX-string * UUIDs as array of HEX-strings * one ID as number * IDs as array of numbers If you want to load all Orders: * **Don't pass** this parameter * **OR** pass `ids=undefined` * **OR** pass `ids=false` |
| [callback] | <code>module:route4me-node~RequestCallback.&lt;jsonschema:Orders.Orders&gt;</code> | [callback] |

<a id="Orders+remove" name="Orders+remove"></a>

### orders.remove(ids, [callback])

Remove an Order
Remove Orders by ID or by UUID

**See**: [https://route4me.io/docs/#remove-an-order](https://route4me.io/docs/#remove-an-order)
**Since**: 0.1.11
**Since**: 1.1.0

| Param | Type | Description |
| --- | --- | --- |
| ids | <code>number</code> \| <code>string</code> \| <code>Array.&lt;number&gt;</code> \| <code>Array.&lt;string&gt;</code> | Order ID/IDs to remove in one of the following form: * CSV-string * one ID as string * one ID as number * array of strings * array of numbers |
| ids | <code>number</code> \| <code>string</code> \| <code>Array.&lt;number&gt;</code> \| <code>Array.&lt;string&gt;</code> | Order IDs or order UUIDs in one of the following form: * one UUID as HEX-string * UUIDs as CSV-HEX-string * UUIDs as array of HEX-strings * one ID as number * IDs as array of numbers |
| [callback] | <code>module:route4me-node~RequestCallback</code> | |

<a id="Orders+update" name="Orders+update"></a>

### orders.update(id, data, [callback])

Update an Order
Update an Order by ID or by UUID

**See**: [https://route4me.io/docs/#update-an-order](https://route4me.io/docs/#update-an-order)
**Since**: 0.1.11
**Since**: 1.1.0

| Param | Type | Description |
| --- | --- | --- |
| id | <code>number</code> | Order ID |
| id | <code>number</code> \| <code>string</code> | Order ID as number or order UUID as HEX-string |
| data | <code>jsonschema:Orders.Order</code> | Order data |
| [callback] | <code>module:route4me-node~RequestCallback.&lt;jsonschema:Orders.Order&gt;</code> | |

Expand Down
402 changes: 402 additions & 0 deletions book/en/code/OrdersV5.md

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions book/en/code/Route4Me.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ Main members of the instanse of `Route4Me` class:
* [Notes ](Notes)
* [Optimizations ](Optimizations)
* [Orders ](Orders)
* [OrdersV5 ](OrdersV5)
* [OrderCustomFields ](OrderCustomFields)
* [PodWorkflow ](PodWorkflow)
* [Routes ](Routes)
Expand Down Expand Up @@ -140,6 +141,7 @@ For most use cases it is necessary:
* [.Notes](#Route4Me+Notes) : <code>Notes</code>
* [.Optimizations](#Route4Me+Optimizations) : <code>Optimizations</code>
* [.Orders](#Route4Me+Orders) : <code>Orders</code>
* [.OrdersV5](#Route4Me+OrdersV5) : <code>OrdersV5</code>
* [.PodWorkflow](#Route4Me+PodWorkflow) : <code>PodWorkflow</code>
* [.Routes](#Route4Me+Routes) : <code>Routes</code>
* [.Schedules](#Route4Me+Schedules) : <code>Schedules</code>
Expand Down Expand Up @@ -248,6 +250,13 @@ Create new API client
**Orders** related API calls

**Since**: 0.1.11
<a id="Route4Me+OrdersV5" name="Route4Me+OrdersV5"></a>

### route4Me.OrdersV5 : <code>OrdersV5</code>

**OrdersV5** related API calls

**Since**: 1.1.0
<a id="Route4Me+PodWorkflow" name="Route4Me+PodWorkflow"></a>

### route4Me.PodWorkflow : <code>PodWorkflow</code>
Expand Down
88 changes: 88 additions & 0 deletions examples/Orders/get-order-by-uuid-promise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
"use strict"

const path = require("path")
const chai = require("chai")
const debug = require("debug")("route4me-node:examples")
require("../init-examples-suite")
const helper = require("../../test/helper")

helper.describeIntegration(helper.toSuiteName(__filename), function T() {
this.timeout(5000)
this.slow(3000)
it(path.basename(__filename), (done) => {
const expect = chai.expect
const apiKey = "11111111111111111111111111111111"

// To use the Promise style instead of the Callback style send promise=true as an option.
const route4me = new Route4Me(apiKey, { promise: true })

const data = {
address_1: "1358 E Luzerne St, Philadelphia, PA 19124, US",
address_alias: "Auto test address",
address_city: "Philadelphia",
EXT_FIELD_first_name: "John",
EXT_FIELD_last_name: "Doe",
EXT_FIELD_email: "[email protected]",
EXT_FIELD_phone: "380380380380"
};

let order_uuid = undefined;
let order_by_id = undefined;

// create Order
route4me.Orders.create(data)
.then(data => {
expect(data).exist

const order_id = data.order_id;
order_uuid = data.order_uuid;
console.log(`Create Order with id='${order_id}' and uuid='${order_uuid}'`);

// get Order by ID
return route4me.Orders.get(order_id)
}).then(data => {
order_by_id = data;
console.log(`Read Order by id, id='${order_by_id.order_id}' and uuid='${order_by_id.order_uuid}`);

// get Order by UUID
return route4me.Orders.get(order_uuid)
}).then(order_by_uuid => {
console.log(`Read Order by uuid, id='${order_by_uuid.order_id}' and uuid='${order_by_uuid.order_uuid}`);

// compare Orders
if(JSON.stringify(order_by_id) == JSON.stringify(order_by_uuid)) {
console.log("The Orders are equal.");
} else {
console.log("The Orders are not equal.");
}

// delete Order by UUID
return route4me.Orders.remove(order_uuid)
}).then(data => {
if(data) {
console.log(`Order with uuid=${order_uuid} was deleted successful.`);
} else {
console.log(`Order with uuid=${order_uuid} was not deleted.`);
}
}).catch(err => {
expect(err).exist
// console.log("Error ", err);

if(order_uuid) {
route4me.Orders.remove(order_uuid)
.then(data => {
if(data) {
console.log(`Order with uuid=${order_uuid} was cleaned up successful.`);
} else {
console.log(`Order with uuid=${order_uuid} was not cleaned up.`);
}
}).catch(err => {
console.log("Error: cleanup, " + err);
});
}
});

// TODO: remove `done` call from examples
done()
})
})
85 changes: 85 additions & 0 deletions examples/Orders/get-order-by-uuid-sync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
"use strict"

const path = require("path")
const chai = require("chai")
const debug = require("debug")("route4me-node:examples")
require("../init-examples-suite")
const helper = require("../../test/helper")

helper.describeIntegration(helper.toSuiteName(__filename), function T() {
this.timeout(5000)
this.slow(3000)
it(path.basename(__filename), (done) => {
const expect = chai.expect
const apiKey = "11111111111111111111111111111111"

// To use the Promise style instead of the Callback style send promise=true as an option.
const route4me = new Route4Me(apiKey, { promise: true });

(async () => {
const data = {
address_1: "1358 E Luzerne St, Philadelphia, PA 19124, US",
address_alias: "Auto test address",
address_city: "Philadelphia",
EXT_FIELD_first_name: "John",
EXT_FIELD_last_name: "Doe",
EXT_FIELD_email: "[email protected]",
EXT_FIELD_phone: "380380380380"
};

let order_uuid = undefined;

try {
// create Order
const order = await route4me.Orders.create(data);
expect(order).exist

const order_id = order.order_id;
order_uuid = order.order_uuid;
console.log(`Create Order with id='${order_id}' and uuid='${order_uuid}'`);

// get Order by ID
const order_by_id = await route4me.Orders.get(order_id);
console.log(`Read Order by id, id='${order_by_id.order_id}' and uuid='${order_by_id.order_uuid}`);

// get Order by UUID
const order_by_uuid = await route4me.Orders.get(order_uuid);
console.log(`Read Order by uuid, id='${order_by_uuid.order_id}' and uuid='${order_by_uuid.order_uuid}`);

// compare Orders
if(JSON.stringify(order_by_id) == JSON.stringify(order_by_uuid)) {
console.log("The Orders are equal.");
} else {
console.log("The Orders are not equal.");
}

// delete Order by UUID
if(await route4me.Orders.remove(order_uuid)) {
console.log(`Order with uuid=${order_uuid} was deleted successful.`);
} else {
console.log(`Order with uuid=${order_uuid} was not deleted.`);
}
}
catch(err) {
expect(err).exist
// console.log("Error ", err);

if(order_uuid) {
try {
if(await route4me.Orders.remove(order_uuid)) {
console.log(`Order with uuid=${order_uuid} was cleaned up successful.`);
} else {
console.log(`Order with uuid=${order_uuid} was not cleaned up.`);
}
}
catch(err) {
console.log("Error: cleanup, " + err);
}
}
}
})();

// TODO: remove `done` call from examples
done()
})
})
103 changes: 103 additions & 0 deletions examples/Orders/get-order-by-uuid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
"use strict"

const path = require("path")
const chai = require("chai")
const debug = require("debug")("route4me-node:examples")
require("../init-examples-suite")
const helper = require("../../test/helper")

helper.describeIntegration(helper.toSuiteName(__filename), function T() {
this.timeout(5000)
this.slow(3000)
it(path.basename(__filename), (done) => {
const expect = chai.expect
const apiKey = "11111111111111111111111111111111"
const route4me = new Route4Me(apiKey)

function cleanup(err, cleanup_uuid) {
debug("error ", err)
expect(err).exist

if(cleanup_uuid) {
route4me.Orders.remove(cleanup_uuid, (err, data) => {
if(err) {
console.log("Error: cleanup, " + err);
return;
}
if(data) {
console.log(`Order with uuid=${cleanup_uuid} was cleaned up successful.`);
} else {
console.log(`Order with uuid=${cleanup_uuid} was not cleaned up.`);
}
});
}
}

const data = {
address_1: "1358 E Luzerne St, Philadelphia, PA 19124, US",
address_alias: "Auto test address",
address_city: "Philadelphia",
EXT_FIELD_first_name: "John",
EXT_FIELD_last_name: "Doe",
EXT_FIELD_email: "[email protected]",
EXT_FIELD_phone: "380380380380"
};

// create order
route4me.Orders.create(data, (err, data) => {
debug("error ", err)
expect(err).is.null
expect(res).exist

if(err) {
cleanup(err);
return;
}

const order_id = data.order_id;
const order_uuid = data.order_uuid;
console.log(`Create Order with id='${order_id}' and uuid='${order_uuid}'`);

// get Order by ID
route4me.Orders.get(order_id, (err, order_by_id) => {
if(err) {
cleanup(err, order_by_id.order_id);
return;
}
console.log(`Read Order by id, id='${order_by_id.order_id}' and uuid='${order_by_id.order_uuid}`);

// get Order by UUID
route4me.Orders.get(order_uuid, (err, order_by_uuid) => {
if(err) {
cleanup(err, order_by_uuid.order_id);
return;
}
console.log(`Read Order by uuid, id='${order_by_uuid.order_id}' and uuid='${order_by_uuid.order_uuid}`);

// compare Orders
if(JSON.stringify(order_by_id) == JSON.stringify(order_by_uuid)) {
console.log("The Orders are equal.");
} else {
console.log("The Orders are not equal.");
}

// delete Order by UUID
route4me.Orders.remove(order_uuid, (err, data) => {
if(err) {
cleanup(err);
return;
}
if(data) {
console.log(`Order with uuid=${order_uuid} was deleted successful.`);
} else {
console.log(`Order with uuid=${order_uuid} was not deleted.`);
}
});
});
});
});

// TODO: remove `done` call from examples
done()
})
})
Loading