import { Schema, Document } from 'mongoose' import db from '../service/db' import * as _ from 'lodash' export interface IUScenariofieldconfigModel extends Document { _id: string name: string proTemplateType: string scenariofields: any } const OBJECT_TYPES = ['task', 'event'] // story: 敏捷研发模板里的需求 // bug: 敏捷研发模板里的缺陷 // subtask: 敏捷研发模板里的任务 const PRO_TEMPLATE_CONFIG_TYPES = ['story', 'bug', 'subtask'] const TASK_ICONS = [ 'task', 'requirement', 'bug', 'hr', 'resource', 'order', 'salesLead', 'subtask' ] const EVENT_ICONS = [ 'event', 'lecture', 'training', 'workshop', 'forum', 'seminar', 'personal' ] const ICONS = TASK_ICONS.concat(EVENT_ICONS) const OFFICIAL_EVENT_SCENARIO_FIELD_TYPES = ['content', 'tag', 'location'] const TASK_APPLICATIONS = [ 'worktimes', 'storyPoint', 'taskProgress', 'rating', 'sprint' ] const OFFICIAL_TASK_SCENARIO_FIELD_TYPES = _.union( ['note', 'priority', 'tag'], TASK_APPLICATIONS ) const SUPPORTED_SCENARIO_FIELD_TYPES = _.uniq( _.union( OFFICIAL_EVENT_SCENARIO_FIELD_TYPES, OFFICIAL_TASK_SCENARIO_FIELD_TYPES ) ).concat('customfield') const scenariofieldSchema = new Schema({ _customfieldId: { type: Schema.Types.ObjectId, ref: 'Customfield' }, fieldType: { type: String, enum: SUPPORTED_SCENARIO_FIELD_TYPES }, // 无权限 roleId 列表 _roleIds: { type: Array, default: [] }, displayed: { type: Boolean, default: false }, required: { type: Boolean, default: false } }) const scenariofieldconfig = new Schema({ name: { type: String, maxlength: 100, required: true }, isDefault: { type: Boolean, default: false }, displayed: { type: Boolean, default: true }, _creatorId: { type: Schema.Types.ObjectId, ref: 'User' }, icon: { type: String, enum: ICONS }, objectType: { type: String, enum: OBJECT_TYPES }, _projectId: { type: Schema.Types.ObjectId, ref: 'Project' }, _taskflowId: { type: Schema.Types.ObjectId, ref: 'Taskflow' }, created: { type: Date, default: Date.now }, updated: { type: Date, default: Date.now }, // 高级模板对应的配置类型 proTemplateConfigType: { type: String, enum: PRO_TEMPLATE_CONFIG_TYPES }, scenariofields: [scenariofieldSchema], _boundToObjectId: { type: Schema.Types.ObjectId }, boundToObjectType: { type: String }, _originalId: { type: Schema.Types.ObjectId, ref: 'ScenarioFieldConfig' }, type: { type: String, default: 'normal', enum: ['normal', 'default', 'official'] }, hasChanged: { type: Boolean, default: false } }) export const ScenariofieldconfigModel = db.model('Scenariofieldconfig', scenariofieldconfig)