Skip to content

Commit 9c19bdc

Browse files
committed
PR changes
1 parent 8cd7563 commit 9c19bdc

File tree

2 files changed

+12
-25
lines changed

2 files changed

+12
-25
lines changed

src/examples/create_pattern_for_sync_route_editor.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ describe('When getting a pattern for use in the Sync route editor', () => {
2020
fetchMock.get('/1/SYNC/patterns/editor/1', {
2121
status: 200,
2222
});
23-
23+
const patternId = 1;
2424
const getPatternForSyncRouteEditorPromise = api.customer('SYNC').patterns()
25-
.getPatternForSyncRouteEditor(1)
25+
.getPatternForSyncRouteEditor(patternId)
2626
.then(getPatternResponse => {
2727
getPatternResponse.should.be.an('object');
2828
});

src/resources/Detour.js

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,35 +29,22 @@ class Detour extends Resource {
2929
async getHistoricalDetours(from, until, includeDeactivated, expandDetails, count) {
3030
const { code, client } = this;
3131

32-
let endpoint = `/2/${code}/serviceadjustments/detours/historical`;
33-
const params = [];
32+
const endpoint = `/2/${code}/serviceadjustments/detours/historical`;
33+
const params = new URLSearchParams();
3434

35-
if (from instanceof Date) {
36-
params.push(`from=${encodeURIComponent(from.toISOString())}`);
37-
}
38-
if (until instanceof Date) {
39-
params.push(`until=${encodeURIComponent(until.toISOString())}`);
40-
}
41-
if (includeDeactivated) {
42-
params.push('includeDeactivated=true');
43-
}
44-
if (expandDetails) {
45-
params.push('expandDetails=true');
46-
}
47-
if (typeof count === 'number' && count > 0) {
48-
params.push(`count=${count}`);
49-
}
35+
if (from instanceof Date) params.set("from", from.toISOString());
36+
if (until instanceof Date) params.set("until", until.toISOString());
37+
if (includeDeactivated) params.set("includeDeactivated", "true");
38+
if (expandDetails) params.set("expandDetails", "true");
39+
if (typeof count === "number" && count > 0) params.set("count", count);
5040

51-
if (params.length > 0) {
52-
endpoint += `?${params.join('&')}`;
53-
}
54-
55-
const response = await client.get(endpoint);
41+
const url = params.toString() ? `${endpoint}?${params.toString()}` : endpoint;
42+
const response = await client.get(url);
5643
const detours = await response.json();
44+
5745
return detours.map(detour => new Detour(client, detour));
5846
}
5947

60-
6148
/**
6249
* Makes a href for a given customer code and detour id
6350
* @param {string} customerCode Customer code

0 commit comments

Comments
 (0)