2021-01-05 16:17:44 +00:00
|
|
|
import http, { FractalResponseData } from '@/api/http';
|
2020-10-04 20:25:58 +00:00
|
|
|
|
|
|
|
export interface Role {
|
2020-12-28 17:08:08 +00:00
|
|
|
id: number;
|
|
|
|
name: string;
|
2021-01-08 22:34:55 +00:00
|
|
|
description?: string;
|
2020-10-04 20:25:58 +00:00
|
|
|
}
|
|
|
|
|
2021-01-05 16:17:44 +00:00
|
|
|
export const rawDataToRole = ({ attributes }: FractalResponseData): Role => ({
|
|
|
|
id: attributes.id,
|
|
|
|
name: attributes.name,
|
|
|
|
description: attributes.description,
|
|
|
|
});
|
|
|
|
|
2020-10-04 20:25:58 +00:00
|
|
|
export default (): Promise<Role[]> => {
|
|
|
|
return new Promise((resolve, reject) => {
|
2020-12-28 04:57:31 +00:00
|
|
|
http.get('/api/application/roles')
|
2021-01-05 16:17:44 +00:00
|
|
|
.then(({ data }) => resolve((data.data || []).map(rawDataToRole)))
|
2020-10-04 20:25:58 +00:00
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
};
|