teambition-sdk-socket
Version:
Front-End SDK for Teambition
77 lines • 3.25 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 File_1 = require("../schemas/File");
var index_1 = require("../utils/index");
var BaseCollection_1 = require("./BaseCollection");
var FileModel = (function (_super) {
__extends(FileModel, _super);
function FileModel() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this._schemaName = 'File';
return _this;
}
FileModel.prototype.addOne = function (file) {
var result = index_1.dataToSchema(file, File_1.default);
return this._save(result);
};
FileModel.prototype.getOne = function (fileId) {
return this._get(fileId);
};
FileModel.prototype.addFiles = function (projectId, parentId, files, page) {
var dbIndex = "project:folder:files/" + projectId + "/" + parentId;
var result = index_1.datasToSchemas(files, File_1.default);
var collection = this._collections.get(dbIndex);
if (!collection) {
collection = new BaseCollection_1.default(this._schemaName, function (data) {
return data._projectId === projectId &&
data._parentId === parentId &&
!data.isArchived;
}, dbIndex);
this._collections.set(dbIndex, collection);
}
return collection.addPage(page, result);
};
FileModel.prototype.getFiles = function (projectId, parentId, page) {
var dbIndex = "project:folder:files/" + projectId + "/" + parentId;
var collection = this._collections.get(dbIndex);
if (collection) {
return collection.get(page);
}
return null;
};
FileModel.prototype.addByTagId = function (tagId, files, page) {
var dbIndex = "tag:files/" + tagId;
var result = index_1.datasToSchemas(files, File_1.default);
var collection = this._collections.get(dbIndex);
if (!collection) {
collection = new BaseCollection_1.default(this._schemaName, function (data) {
return !data.isArchived && data.tagIds && data.tagIds.indexOf(tagId) !== -1;
}, dbIndex);
this._collections.set(dbIndex, collection);
}
return collection.addPage(page, result);
};
FileModel.prototype.getByTagId = function (tagId, page) {
var dbIndex = "tag:files/" + tagId;
var collection = this._collections.get(dbIndex);
if (collection) {
return collection.get(page);
}
return null;
};
return FileModel;
}(BaseModel_1.default));
exports.FileModel = FileModel;
exports.default = new FileModel;
//# sourceMappingURL=FileModel.js.map