Skip to content

Commit 4ac035a

Browse files
committed
fix this
1 parent d1f3a68 commit 4ac035a

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

src/resources/Customer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,8 @@ class Customer extends Resource {
532532
* @returns {Detour} Detour resource
533533
*/
534534
detours() {
535-
return this.resource(Detour, Detour.makeHref(this.code));
535+
const href = Detour.makeHref(this.code);
536+
return this.resource(Detour, {code: this.code, ...href});
536537
}
537538

538539
/**

src/resources/Detour.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ class Detour extends Resource {
1010
*/
1111
constructor(client, ...rest) {
1212
super(client);
13-
const { code, ...newProperties } = rest;
14-
this.customerCode = code;
13+
const newProperties = Object.assign({}, ...rest);
1514
const hydrated = !Object.keys(newProperties).every(k => k === 'href' || k === 'code');
1615

17-
Object.assign(this, newProperties, {
18-
hydrated,
19-
});
16+
Object.assign(this, newProperties, { hydrated });
2017
}
2118

19+
2220
/**
2321
* Fetches historical detours for a given customer (active during specified timeframe).
2422
* @param {Date} [from] - Optional timeframe in which to search for detours
@@ -28,11 +26,12 @@ class Detour extends Resource {
2826
* @param {number} [count] - Optional number of detours to return. Null or zero will return all applicable detours
2927
* @returns {Promise<Array<Detour>>} A promise that resolves to an array of historical detours.
3028
*/
31-
async getHistoricalDetours(from, until, includeDeactivated, expandDetails,count) {
32-
const { customerCode, client } = this;
29+
async getHistoricalDetours(from, until, includeDeactivated, expandDetails, count) {
30+
const { code, client } = this;
3331

34-
let endpoint = `/2/${customerCode}/serviceadjustments/detours/historical`;
32+
let endpoint = `/2/${code}/serviceadjustments/detours/historical`;
3533
const params = [];
34+
3635
if (from instanceof Date) {
3736
params.push(`from=${encodeURIComponent(from.toISOString())}`);
3837
}
@@ -45,18 +44,20 @@ class Detour extends Resource {
4544
if (expandDetails) {
4645
params.push('expandDetails=true');
4746
}
48-
if(count && count > 0){
47+
if (typeof count === 'number' && count > 0) {
4948
params.push(`count=${count}`);
5049
}
50+
5151
if (params.length > 0) {
5252
endpoint += `?${params.join('&')}`;
5353
}
5454

55-
return client.get(endpoint)
56-
.then(response => response.json())
57-
.then(detours => detours.map(detour => new Detour(client, detour)));
55+
const response = await client.get(endpoint);
56+
const detours = await response.json();
57+
return detours.map(detour => new Detour(client, detour));
5858
}
5959

60+
6061
/**
6162
* Makes a href for a given customer code and detour id
6263
* @param {string} customerCode Customer code
@@ -89,7 +90,7 @@ class Detour extends Resource {
8990
* @param {boolean} data.shouldMatchScheduledStops - Indicates whether the detour should match scheduled stops.
9091
* @param {Date} data.startDateTime - The start date and time of the detour.
9192
* @param {Date} data.endDateTime - The end date and time of the detour.
92-
*
93+
*
9394
* @returns {Promise<Detour>} A promise that resolves to a hydrated instance of the Detour class, representing all active detours including the newly created detour.
9495
*/
9596
async create(data) {
@@ -103,7 +104,7 @@ class Detour extends Resource {
103104

104105
/**
105106
* Update an existing detour for a customer via the client.
106-
*
107+
*
107108
* @param {number} detourId - The ID of the detour to update.
108109
* @returns {Promise<Detour>} A promise that resolves to a hydrated instance of the Detour class, representing active detours.
109110
*/

src/resources/RiderAppConfiguration.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ class RiderAppConfiguration extends Resource {
1212
*/
1313
constructor(client, ...rest) {
1414
super(client);
15-
1615
const newProperties = Object.assign({}, ...rest);
1716
const hydrated = !Object.keys(newProperties).every(k => k === 'href' || k === 'code');
1817

0 commit comments

Comments
 (0)