teambition-sdk-socket
Version:
Front-End SDK for Teambition
87 lines • 3.43 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 Observable_1 = require("rxjs/Observable");
var BaseModel_1 = require("./BaseModel");
var Tag_1 = require("../schemas/Tag");
var index_1 = require("../utils/index");
var Task_1 = require("../schemas/Task");
var Post_1 = require("../schemas/Post");
var Event_1 = require("../schemas/Event");
var File_1 = require("../schemas/File");
var Entry_1 = require("../schemas/Entry");
var TagModel = (function (_super) {
__extends(TagModel, _super);
function TagModel() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this._schemaMap = {
'task': {
schema: Task_1.default,
schemaName: 'Task'
},
'post': {
schema: Post_1.default,
schemaName: 'Post'
},
'event': {
schema: Event_1.default,
schemaName: 'Event'
},
'work': {
schema: File_1.default,
schemaName: 'File'
},
'entry': {
schema: Entry_1.default,
schemaName: 'Entry'
}
};
_this._schemaName = 'Tag';
return _this;
}
TagModel.prototype.addOne = function (tag) {
var result = index_1.dataToSchema(tag, Tag_1.default);
return this._save(result);
};
TagModel.prototype.getOne = function (_id) {
return this._get(_id);
};
TagModel.prototype.addByProjectId = function (projectId, tags) {
var result = index_1.datasToSchemas(tags, Tag_1.default);
return this._saveCollection("project:tags/" + projectId, result, this._schemaName, function (data) {
return data._projectId === projectId && !data.isArchived;
});
};
TagModel.prototype.getByProjectId = function (projectId) {
return this._get("project:tags/" + projectId);
};
TagModel.prototype.addRelated = function (_tagId, objectType, datas) {
var DSchema = this._schemaMap[objectType];
if (!DSchema || !DSchema.schema) {
return Observable_1.Observable.throw(new Error('objectType is invalid'));
}
var result = index_1.datasToSchemas(datas, DSchema.schema);
return this._saveCollection("tags:" + objectType + "/" + _tagId, result, DSchema.schemaName, function (data) {
return data.tagIds.indexOf(_tagId) !== -1 && !data.isArchived;
});
};
TagModel.prototype.getRelated = function (_tagId, objectType) {
return this._get("tags:" + objectType + "/" + _tagId);
};
TagModel.prototype.relatedTag = function (objectId, patch) {
return this.update(objectId, patch);
};
return TagModel;
}(BaseModel_1.default));
exports.TagModel = TagModel;
exports.default = new TagModel;
//# sourceMappingURL=TagModel.js.map