@awhere/api
Version:
The awesome aWhere API for JavaScript.
141 lines • 5.51 kB
JavaScript
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var PrototypeBase_1 = __importDefault(require("../PrototypeBase"));
var AdminPermission_1 = __importDefault(require("./AdminPermission"));
var UserPermission_1 = __importDefault(require("./UserPermission"));
var Watcher_1 = require("../Watcher");
var Role = /** @class */ (function (_super) {
__extends(Role, _super);
function Role(props) {
if (props === void 0) { props = {}; }
var _this = _super.call(this, props) || this;
_this._administration = new AdminPermission_1.default();
_this._permission = new UserPermission_1.default();
_this._deletable = true;
_this._id = props._id || Role.generateId();
if (props.administration !== undefined) {
_this.administration = new AdminPermission_1.default(props.administration);
}
if (props.permission !== undefined) {
_this.permission = new UserPermission_1.default(props.permission);
}
_this.name = props.name;
if (props.deletable !== undefined) {
_this.deletable = props.deletable;
}
return _this;
}
Role.generateId = function () {
return _super.generateId.call(this, 'awhere.core.role');
};
Role.watch = function () {
var _this = this;
return new Promise(function (resolve, reject) {
var namespace = '/role';
_this.socket.open();
_this.socket.emit('call', "sub:".concat(namespace), function (err) {
err ? reject(err) : resolve(new Watcher_1.Watcher(_this.socket, namespace));
});
});
};
Role.fromId = function (id) {
return this.request.get("".concat(this.basePath, "/").concat(id)).then(function (res) { return new Role(res.data); });
};
Role.find = function (findOptions) {
if (typeof findOptions === 'string') {
throw new Error('invalid findOptions');
}
return this.request.post("".concat(this.basePath), findOptions);
};
Role.create = function (data) {
if (!data || typeof data === 'string') {
throw new Error('invalid data');
}
return this.request.put("".concat(this.basePath), data);
};
Role.update = function (id, data) {
return this.request.put("".concat(this.basePath, "/").concat(id), data);
};
Role.delete = function (id) {
return this.request.delete("".concat(this.basePath, "/").concat(id));
};
Role.restore = function (id) {
return this.request.put("".concat(this.basePath, "/").concat(id, "/restore"));
};
Role.prototype.save = function () {
if (this._id) {
return this.request.put("".concat(Role.basePath, "/").concat(this._id), this).then(function (res) { return res.data; });
}
else {
return this.request.put("".concat(Role.basePath), this).then(function (res) { return res.data; });
}
};
Role.prototype.delete = function () {
return this.request.delete("".concat(Role.basePath, "/").concat(this._id)).then(function (res) { return res.data; });
};
Role.prototype.restore = function () {
return this.request.put("".concat(Role.basePath, "/").concat(this._id, "/restore")).then(function (res) { return res.data; });
};
Object.defineProperty(Role.prototype, "name", {
get: function () {
return this._name;
},
set: function (value) {
this._name = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Role.prototype, "administration", {
get: function () {
return this._administration;
},
set: function (value) {
this._administration = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Role.prototype, "permission", {
get: function () {
return this._permission;
},
set: function (value) {
this._permission = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Role.prototype, "deletable", {
get: function () {
return this._deletable;
},
set: function (value) {
this._deletable = value;
},
enumerable: false,
configurable: true
});
Role.basePath = '/admin/role';
return Role;
}(PrototypeBase_1.default));
exports.default = Role;
//# sourceMappingURL=Role.js.map