simplify load resource options from store

This commit is contained in:
Ivan Atanasov 2024-12-05 17:38:11 +01:00
parent 5640c7bd00
commit 9e8fddcdb6
No known key found for this signature in database

View file

@ -239,47 +239,48 @@ async function initFetching(inlineLoading = false): Promise<void> {
} }
} }
const createRequestParams = (methodName: string) => {
if (!props.node) {
return;
}
const requestParams: DynamicNodeParameters.ResourceMapperFieldsRequest = {
nodeTypeAndVersion: {
name: props.node?.type,
version: props.node?.typeVersion,
},
currentNodeParameters: resolveRequiredParameters(
props.parameter,
props.node.parameters,
) as INodeParameters,
path: props.path,
methodName,
credentials: props.node.credentials,
};
return requestParams;
};
async function loadFieldsToMap(): Promise<void> { async function loadFieldsToMap(): Promise<void> {
if (!props.node) { if (!props.node) {
return; return;
} }
const { resourceMapperMethod = undefined, localResourceMapperMethod = undefined } = const { resourceMapperMethod, localResourceMapperMethod } =
props.parameter.typeOptions?.resourceMapper ?? {}; props.parameter.typeOptions?.resourceMapper ?? {};
let fetchedFields = null; let fetchedFields = null;
if (typeof resourceMapperMethod === 'string') { if (typeof resourceMapperMethod === 'string') {
const requestParams: DynamicNodeParameters.ResourceMapperFieldsRequest = { const requestParams = createRequestParams(
nodeTypeAndVersion: { resourceMapperMethod,
name: props.node?.type, ) as DynamicNodeParameters.ResourceMapperFieldsRequest;
version: props.node.typeVersion,
},
currentNodeParameters: resolveRequiredParameters(
props.parameter,
props.node.parameters,
) as INodeParameters,
path: props.path,
methodName: resourceMapperMethod,
credentials: props.node.credentials,
};
fetchedFields = await nodeTypesStore.getResourceMapperFields(requestParams); fetchedFields = await nodeTypesStore.getResourceMapperFields(requestParams);
} else { } else if (typeof localResourceMapperMethod === 'string') {
if (typeof localResourceMapperMethod === 'string') { const requestParams = createRequestParams(
const requestParams: DynamicNodeParameters.ResourceMapperFieldsRequest = { localResourceMapperMethod,
nodeTypeAndVersion: { ) as DynamicNodeParameters.ResourceMapperFieldsRequest;
name: props.node?.type,
version: props.node.typeVersion, fetchedFields = await nodeTypesStore.getLocalResourceMapperFields(requestParams);
},
currentNodeParameters: resolveRequiredParameters(
props.parameter,
props.node.parameters,
) as INodeParameters,
path: props.path,
methodName: localResourceMapperMethod,
};
fetchedFields = await nodeTypesStore.getLocalResourceMapperFields(requestParams);
}
} }
if (fetchedFields !== null) { if (fetchedFields !== null) {