Skip to content

Commit 0b1a52f

Browse files
committed
clean this up
1 parent 12ba3a4 commit 0b1a52f

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/resources/Detour.js

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

1717
Object.assign(this, newProperties, {
@@ -20,7 +20,7 @@ class Detour extends Resource {
2020
}
2121

2222
/**
23-
* Fetches historical detours for a given customer.
23+
* Fetches historical detours for a given customer (active during specified timeframe).
2424
* @param {Date} [from] - Optional timeframe in which to search for detours
2525
* @param {Date} [until] - Optional timeframe in which to search for detours
2626
* @param {boolean} [includeDeactivated=false] - Optional flag to include deactivated detours in the response
@@ -29,9 +29,9 @@ class Detour extends Resource {
2929
* @returns {Promise<Array<Detour>>} A promise that resolves to an array of historical detours.
3030
*/
3131
async getHistoricalDetours(from, until, includeDeactivated, expandDetails,count) {
32-
const customerCode = this.href.split('/')[2]; // Extract customer code from href
32+
const { customerCode, client } = this;
33+
3334
let endpoint = `/2/${customerCode}/serviceadjustments/detours/historical`;
34-
3535
const params = [];
3636
if (from instanceof Date) {
3737
params.push(`from=${encodeURIComponent(from.toISOString())}`);
@@ -52,7 +52,6 @@ class Detour extends Resource {
5252
endpoint += `?${params.join('&')}`;
5353
}
5454

55-
const { client } = this;
5655
return client.get(endpoint)
5756
.then(response => response.json())
5857
.then(detours => detours.map(detour => new Detour(client, detour)));

0 commit comments

Comments
 (0)