]>
Commit | Line | Data |
---|---|---|
df98563e | 1 | import { Injectable } from '@angular/core' |
d592e0a9 | 2 | import { HttpParams } from '@angular/common/http' |
3523b64a | 3 | import { SortMeta } from 'primeng/components/common/sortmeta' |
de59c48f | 4 | |
df98563e | 5 | import { RestPagination } from './rest-pagination' |
de59c48f C |
6 | |
7 | @Injectable() | |
8 | export class RestService { | |
9 | ||
d592e0a9 C |
10 | addRestGetParams (params: HttpParams, pagination?: RestPagination, sort?: SortMeta | string) { |
11 | let newParams = params | |
de59c48f | 12 | |
d592e0a9 C |
13 | if (pagination !== undefined) { |
14 | newParams = newParams.set('start', pagination.start.toString()) | |
15 | .set('count', pagination.count.toString()) | |
de59c48f C |
16 | } |
17 | ||
d592e0a9 C |
18 | if (sort !== undefined) { |
19 | let sortString = '' | |
20 | ||
21 | if (typeof sort === 'string') { | |
22 | sortString = sort | |
23 | } else { | |
24 | const sortPrefix = sort.order === 1 ? '' : '-' | |
25 | sortString = sortPrefix + sort.field | |
26 | } | |
27 | ||
28 | newParams = newParams.set('sort', sortString) | |
de59c48f C |
29 | } |
30 | ||
d592e0a9 | 31 | return newParams |
de59c48f C |
32 | } |
33 | ||
34 | } |