mirror of
https://github.com/valitydev/redash.git
synced 2024-11-08 09:53:59 +00:00
37 lines
843 B
JavaScript
37 lines
843 B
JavaScript
import { isArray } from 'underscore';
|
|
|
|
function transformSingle(user) {
|
|
if (user.groups !== undefined) {
|
|
user.admin = user.groups.indexOf('admin') !== -1;
|
|
}
|
|
}
|
|
|
|
function transform(data) {
|
|
if (isArray(data)) {
|
|
data.forEach(transformSingle);
|
|
} else {
|
|
transformSingle(data);
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
function User($resource, $http) {
|
|
const transformResponse = $http.defaults.transformResponse.concat(transform);
|
|
|
|
const actions = {
|
|
get: { method: 'GET', transformResponse },
|
|
save: { method: 'POST', transformResponse },
|
|
query: { method: 'GET', isArray: true, transformResponse },
|
|
delete: { method: 'DELETE', transformResponse },
|
|
};
|
|
|
|
const UserResource = $resource('api/users/:id', { id: '@id' }, actions);
|
|
|
|
return UserResource;
|
|
}
|
|
|
|
export default function (ngModule) {
|
|
ngModule.factory('User', User);
|
|
}
|