@luka-cat-mimi/n8n-nodes-feishu-project
Version:
飞书项目 N8N 集成插件,支持附件管理等功能
163 lines • 6.59 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 description_1 = require("../../../help/description");
const WorkItemInstanceRelationSearchOperate = {
name: '获取指定的关联工作项列表(单空间)',
value: 'work_item_instance_search:relation',
description: '该接口用于获取与指定工作项实例存在工作项关联的工作项实例列表。更多详见<a href="https://project.feishu.cn/b/helpcenter/1p8d7djs/39dcbh1d">帮助文档</a>',
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: 'Relation Work Item Type Key',
name: 'relation_work_item_type_key',
type: 'string',
required: true,
default: '',
description: '关联的工作项类型',
},
{
displayName: 'Relation Key',
name: 'relation_key',
type: 'string',
required: true,
default: '',
description: '关联关系 key。两个工作项之间通过某个关联字段绑定,填入该字段 key 或对接标识即可。',
},
{
displayName: 'Relation Type',
name: 'relation_type',
type: 'options',
default: 0,
options: [
{
name: '关联字段 ID',
value: 0,
},
{
name: '关联字段对接标识',
value: 1,
},
],
description: '关联关系的类型,用于指定关联字段的标识方式。默认值为 0。',
},
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
default: false,
description: 'Whether to return all results or only up to a given limit',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
default: 50,
typeOptions: {
minValue: 1,
},
displayOptions: {
show: {
returnAll: [false],
},
},
description: 'Max number of results to return',
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add option',
default: {},
options: [
{
displayName: 'Timeout',
name: 'timeout',
type: 'number',
default: 10000,
description: '请求超时时间(毫秒)',
},
],
},
],
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 relation_work_item_type_key = this.getNodeParameter('relation_work_item_type_key', index);
const relation_key = this.getNodeParameter('relation_key', index);
const relation_type = this.getNodeParameter('relation_type', index);
const returnAll = this.getNodeParameter('returnAll', index, false);
const limit = this.getNodeParameter('limit', index, 50);
const options = this.getNodeParameter('options', index, {});
const fetchPage = async (pageNum, pageSize) => {
var _a;
const body = {
relation_work_item_type_key,
relation_key,
relation_type,
page_num: pageNum,
page_size: pageSize,
};
const response = await RequestUtils_1.default.request.call(this, {
method: 'POST',
url: `/open_api/${project_key}/work_item/${work_item_type_key}/${work_item_id}/search_by_relation`,
body: body,
timeout: options.timeout,
});
return {
data: (response === null || response === void 0 ? void 0 : response.data) || [],
total: ((_a = response === null || response === void 0 ? void 0 : response.pagination) === null || _a === void 0 ? void 0 : _a.total) || 0,
};
};
if (returnAll) {
let allResults = [];
let pageNum = 1;
const pageSize = 50;
while (true) {
const { data, total } = await fetchPage(pageNum, pageSize);
allResults = allResults.concat(data);
if (allResults.length >= total || data.length === 0 || pageNum >= 1000) {
if (pageNum >= 1000) {
this.logger.warn('已达到最大分页数限制(1000页),停止获取');
}
break;
}
pageNum++;
}
return allResults;
}
else {
const pageSize = Math.min(limit, 50);
const { data } = await fetchPage(1, pageSize);
return data.slice(0, limit);
}
}
};
exports.default = WorkItemInstanceRelationSearchOperate;
//# sourceMappingURL=WorkItemInstanceRelationSearchOperate.js.map