teambition-sdk-socket
Version:
Front-End SDK for Teambition
55 lines • 2.32 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var BaseModel_1 = require("./BaseModel");
var BaseCollection_1 = require("./BaseCollection");
var Activity_1 = require("../schemas/Activity");
var index_1 = require("../utils/index");
var ActivityModel = (function (_super) {
__extends(ActivityModel, _super);
function ActivityModel() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this._schemaName = 'Activity';
return _this;
}
ActivityModel.prototype.addOne = function (activity) {
var result = index_1.dataToSchema(activity, Activity_1.default);
return this._save(result);
};
/**
* 索引为 `activities/${_boundToObjectId}`
*/
ActivityModel.prototype.addToObject = function (_boundToObjectId, activities, page) {
var dbIndex = "activities/" + _boundToObjectId;
var name = dbIndex;
var result = index_1.datasToSchemas(activities, Activity_1.default);
var collection = this._collections.get(name);
if (!collection) {
collection = new BaseCollection_1.default(this._schemaName, function (data) {
return data._boundToObjectId === _boundToObjectId;
}, dbIndex);
this._collections.set(name, collection);
}
return collection.addPage(page, result);
};
ActivityModel.prototype.getActivities = function (_boundToObjectId, page) {
var collection = this._collections.get("activities/" + _boundToObjectId);
if (collection) {
return collection.get(page);
}
return null;
};
return ActivityModel;
}(BaseModel_1.default));
exports.ActivityModel = ActivityModel;
exports.default = new ActivityModel;
//# sourceMappingURL=ActivityModel.js.map