@luka-cat-mimi/n8n-nodes-feishu-project
Version:
飞书项目 N8N 集成插件,支持附件管理等功能
120 lines • 5.95 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const RequestUtils_1 = __importDefault(require("../../../help/utils/RequestUtils"));
const sharedOptions_1 = require("../../../help/utils/sharedOptions");
const description_1 = require("../../../help/description");
const WorkItemInstanceUpdateOperate = {
name: '更新工作项',
value: 'work_item_instance:update',
order: 40,
options: [
description_1.DESCRIPTIONS.PROJECT_KEY,
{
displayName: '工作项类型 Name or ID',
name: 'work_item_type_key',
type: 'options',
default: '',
required: true,
description: '空间下工作项类型,需要先选择空间,详见:<a href="https://project.feishu.cn/b/helpcenter/2.0.0/1p8d7djs/3pjp854w">获取空间下工作项类型</a>. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
typeOptions: {
loadOptionsMethod: 'loadWorkItemTypes',
},
},
{
displayName: '工作项ID',
name: 'work_item_id',
type: 'string',
required: true,
default: '',
description: '工作项实例 ID,在工作项实例详情中,展开右上角 ··· > ID 获取。',
},
{
displayName: '字段动态赋值',
name: 'update_fields',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
placeholder: '添加字段',
default: {},
description: '需要更新的字段列表。可参考<a href="https://project.feishu.cn/b/helpcenter/1p8d7djs/1tj6ggll">字段与属性解析格式</a>',
options: [
{
displayName: '字段',
name: 'fields',
values: [
{
displayName: '字段名称 Name or ID',
name: 'field_key',
type: 'options',
default: '',
required: true,
description: '选择要更新的字段。需要先选择空间和工作项类型。字段定义可以通过调用 工作项配置 - 获取字段信息 查看字段定义列表. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
typeOptions: {
loadOptionsMethod: 'loadWorkItemFieldsForWrite',
},
},
{
displayName: '字段值',
name: 'field_value',
type: 'string',
default: '',
description: '字段值,支持任意类型。对于复杂类型(如数组、对象),请输入 JSON 格式字符串。' +
'<br/><br/>传值示例:' +
'<br/><b>text</b>: 直接输入字符串即可' +
'<br/><b>multi_text</b>: [{"type":"paragraph","content":[{"type":"text","text":"文本","attrs":{"fontColor":"blue","italic":"true","underline":"true"}}]}]' +
'<br/><b>select</b>: {"label":"选项1","value":"8lheuaepp"}(value 为选项ID,必填;label 可选)' +
'<br/><b>multi_select</b>: [{"label":"选项1","value":"b0gzgge5o"},{"label":"选项4","value":"et15_j7yl"}](value 为选项ID,必填;label 可选)' +
'<br/><b>user</b>: 735679528XXXXX(用户 user_key)' +
'<br/><b>multi_user</b>: ["735679528XXXXX","731189198XXXXX"](用户 user_key 数组)',
},
],
},
],
},
sharedOptions_1.commonOptions,
],
async call(index) {
const project_key = this.getNodeParameter('project_key', index, '', {
extractValue: true,
});
const work_item_type_key = this.getNodeParameter('work_item_type_key', index);
const work_item_id = this.getNodeParameter('work_item_id', index);
const updateFieldsCollection = this.getNodeParameter('update_fields', index, {});
const fieldsArray = updateFieldsCollection.fields || [];
const update_fields = fieldsArray.map((item) => {
let fieldValue = item.field_value;
if (typeof fieldValue === 'string' && fieldValue.trim()) {
try {
if ((fieldValue.trim().startsWith('[') && fieldValue.trim().endsWith(']')) ||
(fieldValue.trim().startsWith('{') && fieldValue.trim().endsWith('}'))) {
fieldValue = JSON.parse(fieldValue);
}
}
catch {
}
}
return {
field_key: item.field_key,
field_value: fieldValue,
};
});
const options = this.getNodeParameter('options', index, {});
await RequestUtils_1.default.request.call(this, {
method: 'PUT',
url: `/open_api/${project_key}/work_item/${work_item_type_key}/${work_item_id}`,
body: {
update_fields,
},
timeout: options.timeout,
});
return {
update_fields
};
}
};
exports.default = WorkItemInstanceUpdateOperate;
//# sourceMappingURL=WorkItemInstanceUpdateOperate.js.map