f0ac0725b6
Cleaned up the API endpoint by simplifying the logic and adds test case to cover this bug. If you ever need to list _all_ of the servers on the system you should be using the application API endpoint for the servers most likely.
25 lines
843 B
TypeScript
25 lines
843 B
TypeScript
import { rawDataToServerObject, Server } from '@/api/server/getServer';
|
|
import http, { getPaginationSet, PaginatedResult } from '@/api/http';
|
|
|
|
interface QueryParams {
|
|
query?: string;
|
|
page?: number;
|
|
onlyAdmin?: boolean;
|
|
}
|
|
|
|
export default ({ query, page = 1, onlyAdmin = false }: QueryParams): Promise<PaginatedResult<Server>> => {
|
|
return new Promise((resolve, reject) => {
|
|
http.get('/api/client', {
|
|
params: {
|
|
type: onlyAdmin ? 'admin' : undefined,
|
|
'filter[name]': query,
|
|
page,
|
|
},
|
|
})
|
|
.then(({ data }) => resolve({
|
|
items: (data.data || []).map((datum: any) => rawDataToServerObject(datum)),
|
|
pagination: getPaginationSet(data.meta.pagination),
|
|
}))
|
|
.catch(reject);
|
|
});
|
|
};
|