redash/client/app/services/user.js
2016-11-26 11:35:21 +02:00

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);
}