Basically I have an object dataToSend, if the value I am uploading is a scale ( //scales ), it will add this scale to the createValues array. However I have a condition after (under //file), basically my scale is stuck in the foreach, although it is not going into the condition. I would like the scales to leave the foreach if it does not go into the condition, therefore it has nothing to do in it. I want the scales to go straight to :
console.log('dataToSend', dataToSend);
return dataToSend;
export const convertBeforeSync = (el, lang, projectId) => {
const dataToSend = {
projectId,
gridId: el.TableId,
createValues,
links: {
compositions: [],
traceability: [],
reverseCompositions: [],
externalDocuments: [],
},
};
//scales
if (values?.Scales) {
const output = values?.Scales.map((value) => {
return {
field: value.ScaleId,
value: value.Id,
};
});
dataToSend.createValues = [...dataToSend.createValues, ...output];
console.log('he', dataToSend);
}
//File
dataToSend.createValues.forEach(function (item) {
if (item.field.startsWith('FLD_STR_') && typeof item.value === 'object') {
const newCreateValue = {
field: item.field,
fileName: item.value.fileName,
value: item.value.value,
};
dataToSend.createFileValue = newCreateValue;
dataToSend.createValues = dataToSend.createValues.filter(
(el) => typeof el.value !== 'object'
);
}
});
console.log('dataToSend', dataToSend);
return dataToSend;
};