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