2019-08-17 23:03:10 +00:00
|
|
|
import { rawDataToServerObject, Server } from '@/api/server/getServer';
|
|
|
|
import http, { getPaginationSet, PaginatedResult } from '@/api/http';
|
|
|
|
|
2020-07-15 03:48:41 +00:00
|
|
|
interface QueryParams {
|
|
|
|
query?: string;
|
|
|
|
page?: number;
|
2020-07-26 17:43:46 +00:00
|
|
|
onlyAdmin?: boolean;
|
2020-07-15 03:48:41 +00:00
|
|
|
}
|
|
|
|
|
2020-07-26 17:43:46 +00:00
|
|
|
export default ({ query, page = 1, onlyAdmin = false }: 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-07-26 17:43:46 +00:00
|
|
|
type: onlyAdmin ? 'admin' : undefined,
|
2020-07-07 04:25:00 +00:00
|
|
|
'filter[name]': query,
|
2020-07-15 03:48:41 +00:00
|
|
|
page,
|
2020-04-26 00:52:32 +00:00
|
|
|
},
|
|
|
|
})
|
2019-08-17 23:03:10 +00:00
|
|
|
.then(({ data }) => resolve({
|
2020-07-10 04:00:03 +00:00
|
|
|
items: (data.data || []).map((datum: any) => rawDataToServerObject(datum)),
|
2019-08-17 23:03:10 +00:00
|
|
|
pagination: getPaginationSet(data.meta.pagination),
|
|
|
|
}))
|
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
};
|