2019-08-17 23:03:10 +00:00
|
|
|
import http, { getPaginationSet, PaginatedResult } from '@/api/http';
|
2022-02-27 16:40:51 +00:00
|
|
|
import { Transformers, Server } from '@definitions/user';
|
2019-08-17 23:03:10 +00:00
|
|
|
|
2020-07-15 03:48:41 +00:00
|
|
|
interface QueryParams {
|
|
|
|
query?: string;
|
|
|
|
page?: number;
|
2020-10-16 04:21:38 +00:00
|
|
|
type?: string;
|
2020-07-15 03:48:41 +00:00
|
|
|
}
|
|
|
|
|
2020-10-16 04:21:38 +00:00
|
|
|
export default ({ query, ...params }: QueryParams): Promise<PaginatedResult<Server>> => {
|
2019-08-17 23:03:10 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
2020-07-05 01:30:50 +00:00
|
|
|
http.get('/api/client', {
|
2020-04-26 00:52:32 +00:00
|
|
|
params: {
|
2020-10-16 04:21:38 +00:00
|
|
|
'filter[*]': query,
|
|
|
|
...params,
|
2020-04-26 00:52:32 +00:00
|
|
|
},
|
|
|
|
})
|
2019-08-17 23:03:10 +00:00
|
|
|
.then(({ data }) => resolve({
|
2022-02-27 16:40:51 +00:00
|
|
|
items: (data.data || []).map(Transformers.toServer),
|
2019-08-17 23:03:10 +00:00
|
|
|
pagination: getPaginationSet(data.meta.pagination),
|
|
|
|
}))
|
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
};
|