misc_pterodactyl-panel/resources/scripts/api/admin/users/searchUsers.ts
2021-05-20 16:00:46 -06:00

25 lines
697 B
TypeScript

import http from '@/api/http';
import { User, rawDataToUser } from '@/api/admin/users/getUsers';
interface Filters {
username?: string;
email?: string;
}
export default (filters?: Filters): Promise<User[]> => {
const params = {};
if (filters !== undefined) {
Object.keys(filters).forEach(key => {
// @ts-ignore
params['filter[' + key + ']'] = filters[key];
});
}
return new Promise((resolve, reject) => {
http.get('/api/application/users', { params: { ...params } })
.then(response => resolve(
(response.data.data || []).map(rawDataToUser)
))
.catch(reject);
});
};