Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
com.akaver.sportmap
SportMap-aurelia
Commits
c4c89202
Commit
c4c89202
authored
May 21, 2020
by
Andres Käver
Browse files
universal query params parsing
parent
9e458b20
Pipeline
#833
passed with stages
in 1 minute and 17 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/services/base-service.ts
View file @
c4c89202
...
...
@@ -2,6 +2,8 @@ import { autoinject } from 'aurelia-framework';
import
{
HttpClient
,
json
}
from
'
aurelia-fetch-client
'
;
import
*
as
environment
from
'
../../config/environment.json
'
;
import
{
IFetchResponse
}
from
'
types/IFetchResponse
'
;
import
{
IQueryParams
}
from
'
types/IQueryParams
'
;
import
{
stringify
}
from
'
querystring
'
;
@
autoinject
export
class
BaseService
<
TEntity
>
{
...
...
@@ -14,10 +16,21 @@ export class BaseService<TEntity> {
constructor
(
protected
apiEndpointUrl
:
string
,
protected
httpClient
:
HttpClient
)
{
}
async
getAll
():
Promise
<
IFetchResponse
<
TEntity
[]
>>
{
async
getAll
(
queryParams
?:
IQueryParams
):
Promise
<
IFetchResponse
<
TEntity
[]
>>
{
let
url
=
this
.
apiEndpointUrl
;
if
(
queryParams
!==
undefined
){
const
params
=
[]
as
string
[];
Object
.
keys
(
queryParams
).
forEach
(
key
=>
{
params
.
push
(
key
+
'
=
'
+
queryParams
[
key
]);
})
if
(
params
.
length
>
0
){
url
=
url
+
'
?
'
+
params
.
join
(
'
&
'
);
}
}
try
{
const
response
=
await
this
.
httpClient
.
fetch
(
this
.
apiEndpointU
rl
,
{
.
fetch
(
u
rl
,
{
cache
:
"
no-store
"
,
headers
:
this
.
authHeaders
});
...
...
src/services/gpssession-service.ts
View file @
c4c89202
...
...
@@ -12,7 +12,7 @@ export class GpsSessionService extends BaseService<IGpsSession> {
}
/*
async getAllSessions(minLocations: number, minDistance: number, minDuration: number): Promise<IFetchResponse<IGpsSession[]>> {
let url = this.apiEndpointUrl;
url = url + '?minLocationsCount=' + minLocations.toString() + '&minDuration=' + minDuration.toString() + '&minDistance=' + minDistance.toString();
...
...
@@ -44,5 +44,5 @@ export class GpsSessionService extends BaseService<IGpsSession> {
}
}
}
*/
}
src/types/IQueryParams.ts
0 → 100644
View file @
c4c89202
export
interface
IQueryParams
{
// indexer - allows to access unknown properties with foo['bar'].
[
param
:
string
]:
any
;
}
src/views/home/index.ts
View file @
c4c89202
...
...
@@ -118,7 +118,7 @@ export class HomeIndex {
L.imageOverlay(imageUrl, imageBounds).bringToFront();
*/
this
.
gpsSessionService
.
getAll
Sessions
(
this
.
minLocations
,
this
.
minDistance
,
this
.
minDuration
).
then
(
this
.
gpsSessionService
.
getAll
({
minLocationsCount
:
this
.
minLocations
,
minDistance
:
this
.
minDistance
,
minDuration
:
this
.
minDuration
}
).
then
(
response
=>
{
if
(
response
.
data
)
{
this
.
gpsSessions
=
response
.
data
;
...
...
@@ -161,7 +161,7 @@ export class HomeIndex {
// ================================= View ===============================
reloadSessions
():
void
{
this
.
gpsSessionService
.
getAll
Sessions
(
this
.
minLocations
,
this
.
minDistance
,
this
.
minDuration
).
then
(
this
.
gpsSessionService
.
getAll
({
minLocationsCount
:
this
.
minLocations
,
minDistance
:
this
.
minDistance
,
minDuration
:
this
.
minDuration
}
).
then
(
response
=>
{
if
(
response
.
data
)
{
this
.
gpsSessions
=
response
.
data
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment