misc_pterodactyl-panel/resources/scripts/api/getServers.ts
2022-02-27 11:40:51 -05:00

24 lines
729 B
TypeScript

import http, { getPaginationSet, PaginatedResult } from '@/api/http';
import { Transformers, Server } from '@definitions/user';
interface QueryParams {
query?: string;
page?: number;
type?: string;
}
export default ({ query, ...params }: QueryParams): Promise<PaginatedResult<Server>> => {
return new Promise((resolve, reject) => {
http.get('/api/client', {
params: {
'filter[*]': query,
...params,
},
})
.then(({ data }) => resolve({
items: (data.data || []).map(Transformers.toServer),
pagination: getPaginationSet(data.meta.pagination),
}))
.catch(reject);
});
};