@awhere/api
Version:
The awesome aWhere API for JavaScript.
234 lines • 8.1 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 Role_1 = __importDefault(require("../Role"));
var Watcher_1 = require("../Watcher");
var User = /** @class */ (function (_super) {
__extends(User, _super);
function User(props) {
if (props === void 0) { props = {}; }
var _this = _super.call(this, props) || this;
_this._provider = 'default';
_this._role = new Role_1.default();
_this._groups = [];
_this._id = props._id || User.generateId();
_this._username = props.username;
_this._firstName = props.firstName;
_this._lastName = props.lastName;
_this._middleName = props.middleName;
_this._displayName = props.displayName;
_this._email = props.email;
_this._password = props.password;
_this._picture = props.picture;
if (props.provider !== undefined) {
_this._provider = props.provider;
}
if (typeof props.role === 'object') {
_this._role = new Role_1.default(props.role);
}
else if (typeof props.role === 'string') {
_this._role = props.role;
}
if (props.groups !== undefined) {
_this._groups = props.groups;
}
return _this;
}
User.generateId = function () {
return _super.generateId.call(this, 'awhere.core.user');
};
User.watch = function () {
var _this = this;
return new Promise(function (resolve, reject) {
var namespace = '/user';
_this.socket.open();
_this.socket.emit('call', "sub:".concat(namespace), function (err) {
err ? reject(err) : resolve(new Watcher_1.Watcher(_this.socket, namespace));
});
});
};
User.fromId = function (id) {
return this.request.get("".concat(this.basePath, "/").concat(id)).then(function (res) { return new User(res.data); });
};
User.find = function (findOptions) {
if (typeof findOptions === 'string') {
throw new Error('invalid findOptions');
}
return this.request.post("".concat(this.basePath), findOptions);
};
User.create = function (data) {
if (!data || typeof data === 'string') {
throw new Error('invalid data');
}
return this.request.put("".concat(this.basePath), data);
};
User.update = function (id, data) {
return this.request.put("".concat(this.basePath, "/").concat(id), data);
};
User.delete = function (id) {
return this.request.delete("".concat(this.basePath, "/").concat(id));
};
User.restore = function (id) {
return this.request.put("".concat(this.basePath, "/").concat(id, "/restore"));
};
User.prototype.save = function () {
if (this._id) {
return this.request.put("".concat(User.basePath, "/").concat(this._id), this).then(function (res) { return res.data; });
}
else {
return this.request.put("".concat(User.basePath), this).then(function (res) { return res.data; });
}
};
User.prototype.delete = function () {
return this.request.delete("".concat(User.basePath, "/").concat(this._id)).then(function (res) { return res.data; });
};
User.prototype.restore = function () {
return this.request.put("".concat(User.basePath, "/").concat(this._id, "/restore")).then(function (res) { return res.data; });
};
Object.defineProperty(User.prototype, "username", {
get: function () {
return this._username;
},
set: function (value) {
this._username = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(User.prototype, "firstName", {
get: function () {
return this._firstName;
},
set: function (value) {
this._firstName = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(User.prototype, "lastName", {
get: function () {
return this._lastName;
},
set: function (value) {
this._lastName = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(User.prototype, "middleName", {
get: function () {
return this._middleName;
},
set: function (value) {
this._middleName = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(User.prototype, "displayName", {
get: function () {
return this._displayName;
},
set: function (v) {
this._displayName = v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(User.prototype, "email", {
get: function () {
return this._email;
},
set: function (value) {
this._email = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(User.prototype, "password", {
get: function () {
return this._password;
},
set: function (value) {
this._password = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(User.prototype, "picture", {
get: function () {
return this._picture;
},
set: function (value) {
this._picture = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(User.prototype, "provider", {
get: function () {
return this._provider;
},
set: function (value) {
this._provider = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(User.prototype, "role", {
get: function () {
return this._role;
},
set: function (value) {
this._role = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(User.prototype, "groups", {
get: function () {
return this._groups;
},
set: function (value) {
this._groups = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(User.prototype, "pictureUrl", {
get: function () {
return this._picture ? "".concat(this.baseUrl, "image/profile/").concat(this._picture) : undefined;
},
enumerable: false,
configurable: true
});
Object.defineProperty(User.prototype, "fullName", {
get: function () {
return [this._firstName, this._middleName, this._lastName].filter(function (s) { return !!s; }).join(' ');
},
enumerable: false,
configurable: true
});
User.basePath = '/admin/user';
return User;
}(PrototypeBase_1.default));
exports.default = User;
//# sourceMappingURL=User.js.map