misc_pterodactyl-panel/resources/scripts/api/admin/roles/getRoles.ts

22 lines
632 B
TypeScript
Raw Normal View History

import http, { FractalResponseData } from '@/api/http';
2020-10-04 20:25:58 +00:00
export interface Role {
id: number;
name: string;
description?: string;
2020-10-04 20:25:58 +00:00
}
export const rawDataToRole = ({ attributes }: FractalResponseData): Role => ({
id: attributes.id,
name: attributes.name,
description: attributes.description,
});
export default (include: string[] = []): Promise<Role[]> => {
2020-10-04 20:25:58 +00:00
return new Promise((resolve, reject) => {
http.get('/api/application/roles', { params: { include: include.join(',') } })
.then(({ data }) => resolve((data.data || []).map(rawDataToRole)))
2020-10-04 20:25:58 +00:00
.catch(reject);
});
};