@awhere/api
Version:
The awesome aWhere API for JavaScript.
166 lines • 6.21 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 interfaces_1 = require("@awhere/interfaces");
var PrototypeBase_1 = __importDefault(require("../PrototypeBase"));
var User_1 = __importDefault(require("../User"));
var Member_1 = __importDefault(require("./Member"));
function instanceOfIMember(object) {
return '_id' in object && 'role' in object;
}
function instanceOfIMembers(object) {
var objects = object;
return objects.every(function (obj) { return instanceOfIMember(obj); });
}
function instanceOfStrings(object) {
var objects = object;
return objects.every(function (obj) { return typeof obj === 'string'; });
}
var Group = /** @class */ (function (_super) {
__extends(Group, _super);
function Group(props) {
if (props === void 0) { props = {}; }
var _this = _super.call(this, props) || this;
_this._members = [];
_this._id = props._id || Group.generateId();
_this.name = props.name;
if (typeof props.owner === 'object') {
_this.owner = new User_1.default(props.owner);
}
else {
_this.owner = props.owner;
}
_this.thumbnail = props.thumbnail;
if (props.members && instanceOfIMembers(props.members)) {
_this.members = props.members.map(function (member) { return new Member_1.default(member); });
}
else {
_this.members = [];
}
return _this;
}
Group.generateId = function () {
return _super.generateId.call(this, 'awhere.core.group');
};
Group.fromId = function (id) {
return this.request.get("".concat(this.basePath, "/").concat(id)).then(function (res) { return new Group(res.data); });
};
Group.explore = function (paramters) {
return this.request.get("".concat(this.basePath, "/explore"), { params: paramters }).then(function (res) { return res.data; });
};
Group.create = function (data) {
if (!data || typeof data === 'string') {
throw new Error('invalid data');
}
return this.request.put("".concat(this.basePath), data).then(function (res) { return res.data; });
};
Group.update = function (id, data) {
return this.request.put("".concat(this.basePath, "/").concat(id), data).then(function (res) { return res.data; });
};
Group.delete = function (id) {
return this.request.put("".concat(this.basePath, "/delete/"), { ids: [id] }).then(function (res) { return res.data; });
};
// public static restore(id: string) {
// return this.request.put(`${this.basePath}/${id}/restore`);
// }
Group.prototype.save = function () {
if (this._id) {
return this.request.put("".concat(Group.basePath, "/").concat(this._id), this).then(function (res) { return res.data; });
}
else {
return this.request.put("".concat(Group.basePath), this).then(function (res) { return res.data; });
}
};
Group.prototype.delete = function () {
return this.request.put("".concat(Group.basePath, "/delete"), { ids: [this._id] }).then(function (res) { return res.data; });
};
Object.defineProperty(Group.prototype, "name", {
get: function () {
return this._name;
},
set: function (value) {
this._name = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Group.prototype, "owner", {
get: function () {
return this._owner;
},
set: function (value) {
this._owner = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Group.prototype, "thumbnail", {
get: function () {
return this._thumbnail;
},
set: function (value) {
this._thumbnail = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Group.prototype, "members", {
get: function () {
return this._members;
},
set: function (value) {
this._members = value;
},
enumerable: false,
configurable: true
});
Group.prototype.getMemberAtIndex = function (index) {
return this.members[index];
};
Group.prototype.addMember = function (user, role) {
if (!this.members) {
this.members = [];
}
var member = new Member_1.default({
member: user,
role: role,
status: interfaces_1.MemberStatus.accepted,
});
this.members.push(member);
return member;
};
Group.basePath = '/group';
return Group;
}(PrototypeBase_1.default));
exports.default = Group;
var SortWithoutKeyword;
(function (SortWithoutKeyword) {
SortWithoutKeyword["name"] = "name";
})(SortWithoutKeyword || (SortWithoutKeyword = {}));
var SortWithKeyword;
(function (SortWithKeyword) {
SortWithKeyword["relavent"] = "relevant";
})(SortWithKeyword || (SortWithKeyword = {}));
var SortOrder;
(function (SortOrder) {
SortOrder["ascending"] = "ascending";
SortOrder["descending"] = "descending";
})(SortOrder || (SortOrder = {}));
//# sourceMappingURL=Group.js.map