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,
|
|
|
|
});
|
|
|
|
|
2021-01-15 16:41:15 +00:00
|
|
|
export default (include: string[] = []): Promise<Role[]> => {
|
2020-10-04 20:25:58 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
2021-01-15 16:41:15 +00:00
|
|
|
http.get('/api/application/roles', { params: { include: include.join(',') } })
|
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);
|
|
|
|
});
|
|
|
|
};
|