UNPKG

teambition-sdk-socket

Version:
390 lines 17.3 kB
'use strict'; 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 MaxIdCollection_1 = require("./tasks/MaxIdCollection"); var Task_1 = require("../schemas/Task"); var index_1 = require("../utils/index"); var TaskModel = (function (_super) { __extends(TaskModel, _super); function TaskModel() { var _this = _super !== null && _super.apply(this, arguments) || this; _this._schemaName = 'Task'; return _this; } /** * 不分页不用 Collection */ TaskModel.prototype.addTasklistTasksUndone = function (_tasklistId, tasks) { var result = index_1.datasToSchemas(tasks, Task_1.default); return this._saveCollection("tasklist:tasks:undone/" + _tasklistId, result, this._schemaName, function (data) { return data._tasklistId === _tasklistId && !data.isDone && !data.isArchived; }); }; TaskModel.prototype.getTasklistTasksUndone = function (_tasklistId) { return this._get("tasklist:tasks:undone/" + _tasklistId); }; /** * _collections 的索引是 '_tasklistId' */ TaskModel.prototype.addTasklistTasksDone = function (_tasklistId, tasks, page) { var result = index_1.datasToSchemas(tasks, Task_1.default); var dbIndex = "tasklist:tasks:done/" + _tasklistId; var collection = this._collections.get(dbIndex); if (!collection) { collection = new BaseCollection_1.default(this._schemaName, function (data) { return data._tasklistId === _tasklistId && data.isDone && !data.isArchived; }, dbIndex); this._collections.set(dbIndex, collection); } return collection.addPage(page, result); }; TaskModel.prototype.getTasklistTasksDone = function (_tasklistId, page) { var collection = this._collections.get("tasklist:tasks:done/" + _tasklistId); if (collection) { return collection.get(page); } return null; }; TaskModel.prototype.addMyTasksWithInbox = function (userId, tasks) { var result = index_1.datasToSchemas(tasks, Task_1.default); var dbIndex = "tasks:me/withInbox"; return this._saveCollection(dbIndex, result, this._schemaName, function (data) { return data._executorId === userId && !data.isDone && !data.isArchived; }); }; TaskModel.prototype.getMyTasksWithInbox = function () { var dbIndex = "tasks:me/withInbox"; return this._get(dbIndex); }; TaskModel.prototype.addSubtasks = function (_taskId, subtasks) { var result = index_1.datasToSchemas(subtasks, Task_1.default); return this._saveCollection("task:subtasks/" + _taskId, result, this._schemaName, function (data) { return data.ancestorIds[0] === _taskId; }); }; TaskModel.prototype.getSubtasks = function (_taskId) { return this._get("task:subtasks/" + _taskId); }; TaskModel.prototype.addMyDoneTasksWithInbox = function (userId, tasks) { var result = index_1.datasToSchemas(tasks, Task_1.default); var dbIndex = "tasks:me:done/withInbox"; return this._saveCollection(dbIndex, result, this._schemaName, function (data) { return data._executorId === userId && data.isDone && !data.isArchived; }); }; TaskModel.prototype.getMyDoneTasksWithInbox = function () { var dbIndex = "tasks:me:done/withInbox"; return this._get(dbIndex); }; TaskModel.prototype.addMyCreatedTasksWithInbox = function (userId, tasks) { var result = index_1.datasToSchemas(tasks, Task_1.default); var dbIndex = "tasks:me/createdAndWithInbox"; return this._saveCollection(dbIndex, result, this._schemaName, function (data) { return data._creatorId === userId && !data.isArchived; }); }; TaskModel.prototype.getMyCreatedTasksWithInbox = function () { var dbIndex = "tasks:me/createdAndWithInbox"; return this._get(dbIndex); }; TaskModel.prototype.addMyInvolvedTasksWithInbox = function (userId, tasks) { var result = index_1.datasToSchemas(tasks, Task_1.default); var dbIndex = "tasks:me/involvedAndWithInbox"; return this._saveCollection(dbIndex, result, this._schemaName, function (data) { return data.involveMembers && data.involveMembers.indexOf(userId) !== -1 && !data.isArchived; }); }; TaskModel.prototype.getMyInvolvedTasksWithInbox = function () { var dbIndex = "tasks:me/involvedAndWithInbox"; return this._get(dbIndex); }; TaskModel.prototype.addMyDueTasks = function (userId, tasks) { var result = index_1.datasToSchemas(tasks, Task_1.default); var dbIndex = "tasks:me/hasdueDate"; return this._saveCollection(dbIndex, result, this._schemaName, function (data) { return data._executorId === userId && Boolean(data.dueDate) && !data.isDone && !data.isArchived; }); }; TaskModel.prototype.getMyDueTasks = function () { var dbIndex = "tasks:me/hasdueDate"; return this._get(dbIndex); }; TaskModel.prototype.addMyTasks = function (userId, tasks) { var result = index_1.datasToSchemas(tasks, Task_1.default); var dbIndex = "tasks:me/noDueDate"; return this._saveCollection(dbIndex, result, this._schemaName, function (data) { return data._executorId === userId && !data.dueDate && !data.isDone && !data.isArchived; }); }; TaskModel.prototype.getMyTasks = function () { var dbIndex = "tasks:me/noDueDate"; return this._get(dbIndex); }; /** * _collections 的索引是 `organization:tasks:due/${organization._id}` */ TaskModel.prototype.addOrganizationMyDueTasks = function (userId, organization, tasks, page) { var dbIndex = "organization:tasks:due/" + organization._id; var result = index_1.datasToSchemas(tasks, Task_1.default); var collection = this._collections.get(dbIndex); if (!collection) { collection = new BaseCollection_1.default(this._schemaName, function (data) { return organization.projectIds instanceof Array && organization.projectIds.indexOf(data._projectId) !== -1 && !!data.dueDate && data._executorId === userId && !data.isDone; }, dbIndex); this._collections.set(dbIndex, collection); } return collection.addPage(page, result); }; TaskModel.prototype.getOrganizationMyDueTasks = function (organizationId, page) { var collection = this._collections.get("organization:tasks:due/" + organizationId); if (collection) { return collection.get(page); } return null; }; TaskModel.prototype.addStageTasks = function (stageId, tasks) { var dbIndex = "stage:tasks:undone/" + stageId; var result = index_1.datasToSchemas(tasks, Task_1.default); return this._saveCollection(dbIndex, result, this._schemaName, function (data) { return data._stageId === stageId && !data.isDone && !data.isArchived; }); }; TaskModel.prototype.addStageDoneTasks = function (stageId, tasks, page) { var dbIndex = "stage:tasks:done/" + stageId; var result = index_1.datasToSchemas(tasks, Task_1.default); var collection = this._collections.get(dbIndex); if (!collection) { collection = new BaseCollection_1.default(this._schemaName, function (data) { return data._stageId === stageId && data.isDone && !data.isArchived; }, dbIndex); this._collections.set(dbIndex, collection); } return collection.addPage(page, result); }; TaskModel.prototype.getStageTasks = function (stageId) { return this._get("stage:tasks:undone/" + stageId); }; TaskModel.prototype.getStageDoneTasks = function (stageId, page) { var dbIndex = "stage:tasks:done/" + stageId; var collection = this._collections.get(dbIndex); return collection ? collection.get(page) : null; }; /** * _collections 的索引是 `organization:tasks/${organization._id}` */ TaskModel.prototype.addOrganizationMyTasks = function (userId, organization, tasks, page) { var result = index_1.datasToSchemas(tasks, Task_1.default); var dbIndex = "organization:tasks/" + organization._id; var collection = this._collections.get(dbIndex); if (!collection) { collection = new BaseCollection_1.default(this._schemaName, function (data) { return organization.projectIds instanceof Array && organization.projectIds.indexOf(data._projectId) !== -1 && !data.dueDate && data._executorId === userId && !data.isDone; }, dbIndex); this._collections.set(dbIndex, collection); } return collection.addPage(page, result); }; TaskModel.prototype.getOrganizationMyTasks = function (organizationId, page) { var collection = this._collections.get("organization:tasks/" + organizationId); if (collection) { return collection.get(page); } return null; }; /** * _collections 的索引是 `organization:tasks:done/${organization._id}` */ TaskModel.prototype.addOrganizationMyDoneTasks = function (userId, organization, tasks, page) { var result = index_1.datasToSchemas(tasks, Task_1.default); var dbIndex = "organization:tasks:done/" + organization._id; var collection = this._collections.get(dbIndex); if (!collection) { collection = new BaseCollection_1.default(this._schemaName, function (data) { return organization.projectIds instanceof Array && organization.projectIds.indexOf(data._projectId) !== -1 && data.isDone && data._executorId === userId; }, dbIndex); this._collections.set(dbIndex, collection); } return collection.addPage(page, result); }; TaskModel.prototype.getOrganizationMyDoneTasks = function (organizationId, page) { var collection = this._collections.get("organization:tasks:done/" + organizationId); if (collection) { return collection.get(page); } return null; }; /** * _collections 的索引是 `organization:tasks:created/${organization._id}` */ TaskModel.prototype.addOrganizationMyCreatedTasks = function (userId, organization, tasks, page) { var result = index_1.datasToSchemas(tasks, Task_1.default); var dbIndex = "organization:tasks:created/" + organization._id; var collection = this._collections.get(dbIndex); if (!collection) { collection = new MaxIdCollection_1.default(this._schemaName, function (data) { return data._creatorId === userId && !data.isArchived; }, dbIndex); this._collections.set(dbIndex, collection); } return collection.maxAddPage(page, result); }; TaskModel.prototype.getOrganizationMyCreatedTasks = function (organizationId, page) { var collection = this._collections.get("organization:tasks:created/" + organizationId); if (collection) { return collection.get(page); } return null; }; TaskModel.prototype.getOrgMyCreatedMaxId = function (organizationId) { var collection = this._collections.get("organization:tasks:created/" + organizationId); if (collection) { return collection.maxId; } return void 0; }; /** * _collections 的索引是 `organization:tasks:involves/${organization._id}` */ TaskModel.prototype.addOrgMyInvolvesTasks = function (userId, organization, tasks, page) { var result = index_1.datasToSchemas(tasks, Task_1.default); var dbIndex = "organization:tasks:involves/" + organization._id; var collection = this._collections.get(dbIndex); if (!collection) { collection = new MaxIdCollection_1.default(this._schemaName, function (data) { return data.involveMembers && data.involveMembers.indexOf(userId) !== -1 && !data.isArchived; }, dbIndex); this._collections.set(dbIndex, collection); } return collection.maxAddPage(page, result); }; TaskModel.prototype.getOrgInvolvesTasks = function (organizationId, page) { var collection = this._collections.get("organization:tasks:involves/" + organizationId); if (collection) { return collection.get(page); } return null; }; TaskModel.prototype.getOrgMyInvolvesMaxId = function (organizationId) { var collection = this._collections.get("organization:tasks:involves/" + organizationId); if (collection) { return collection.maxId; } return void 0; }; /** * _collections 索引为 `project:tasks/${_projectId}` */ TaskModel.prototype.addProjectTasks = function (_projectId, tasks, page) { var dbIndex = "project:tasks/" + _projectId; var result = index_1.datasToSchemas(tasks, Task_1.default); var collection = this._collections.get(dbIndex); if (!collection) { collection = new BaseCollection_1.default(this._schemaName, function (data) { return data._projectId === _projectId && !data.isArchived && !data.isDone; }, dbIndex); this._collections.set(dbIndex, collection); } return collection.addPage(page, result); }; /** * _collections 索引为 `project:tasks:done/${_projectId}` */ TaskModel.prototype.addProjectDoneTasks = function (_projectId, tasks, page) { var dbIndex = "project:tasks:done/" + _projectId; var result = index_1.datasToSchemas(tasks, Task_1.default); var collection = this._collections.get(dbIndex); if (!collection) { collection = new BaseCollection_1.default(this._schemaName, function (data) { return data._projectId === _projectId && !data.isArchived && data.isDone; }, dbIndex); this._collections.set(dbIndex, collection); } return collection.addPage(page, result); }; TaskModel.prototype.getProjectTasks = function (_projectId, page) { var collection = this._collections.get("project:tasks/" + _projectId); if (collection) { return collection.get(page); } return null; }; TaskModel.prototype.getProjectDoneTasks = function (_projectId, page) { var collection = this._collections.get("project:tasks:done/" + _projectId); if (collection) { return collection.get(page); } return null; }; TaskModel.prototype.addByTagId = function (tagId, tasks, page) { var dbIndex = "tag:tasks/" + tagId; var result = index_1.datasToSchemas(tasks, Task_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); }; TaskModel.prototype.getByTagId = function (tagId, page) { var dbIndex = "tag:tasks/" + tagId; var collection = this._collections.get(dbIndex); if (collection) { return collection.get(page); } return null; }; TaskModel.prototype.addOne = function (task) { var result = index_1.dataToSchema(task, Task_1.default); return this._save(result); }; TaskModel.prototype.getOne = function (_id) { return this._get(_id); }; return TaskModel; }(BaseModel_1.default)); exports.TaskModel = TaskModel; exports.default = new TaskModel; //# sourceMappingURL=TaskModel.js.map