@@ -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