skydiet-lib-node
Advanced tools
Comparing version 1.0.33 to 1.0.34
@@ -83,12 +83,12 @@ "use strict"; | ||
let formulaToEnable = item.formulaToEnable; | ||
formulaToEnable = (0, exports.buildFormula)(questionsAnswereds, formulaToEnable); | ||
//TENTAR EXECUTAR A FORMULA | ||
let enable = false; | ||
enable = (0, exports.execFormula)(false, formulaToEnable); | ||
if (!enable) { | ||
items.splice(index, 1); | ||
if (formulaToEnable) { | ||
formulaToEnable = (0, exports.buildFormula)(questionsAnswereds, formulaToEnable); | ||
//TENTAR EXECUTAR A FORMULA | ||
let enable = false; | ||
enable = (0, exports.execFormula)(false, formulaToEnable); | ||
if (!enable) { | ||
items.splice(index, 1); | ||
} | ||
} | ||
}); | ||
// const result = generateIdentifiers(items, fieldsToGroup); | ||
// console.log(result) | ||
const groupeds2 = items.reduce((acc, currentValue, currentIndex, array) => { | ||
@@ -95,0 +95,0 @@ let itemAux = {}; |
{ | ||
"name": "skydiet-lib-node", | ||
"version": "1.0.33", | ||
"version": "1.0.34", | ||
"description": "Biblioteca para funções skydiet", | ||
@@ -5,0 +5,0 @@ "author": "Daniel Cabral <cabralconsultoriaemsoftware@gmail.com>", |
@@ -60,35 +60,35 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ | ||
array.forEach(item => { | ||
// Gera combinações dinâmicas para os campos | ||
const combinations = fields.map(field => { | ||
if (Array.isArray(item[field])) { | ||
return item[field] ?? ""; | ||
} else if (item[field] !== undefined) { | ||
return [item[field]]; | ||
} | ||
return []; | ||
array.forEach(item => { | ||
// Gera combinações dinâmicas para os campos | ||
const combinations = fields.map(field => { | ||
if (Array.isArray(item[field])) { | ||
return item[field] ?? ""; | ||
} else if (item[field] !== undefined) { | ||
return [item[field]]; | ||
} | ||
return []; | ||
}); | ||
// Combina todas as variações entre os campos | ||
const allCombinations = combinations.reduce((acc, values, index) => { | ||
if (acc.length === 0) return values.map((value: any) => ({ [fields[index]]: value })); | ||
const newCombinations: any[] = []; | ||
acc.forEach((accCombination: any) => { | ||
values.forEach((value: any) => { | ||
newCombinations.push({ ...accCombination, [fields[acc.length]]: value }); | ||
}); | ||
}); | ||
return newCombinations; | ||
}, []); | ||
// Combina todas as variações entre os campos | ||
const allCombinations = combinations.reduce((acc, values, index) => { | ||
if (acc.length === 0) return values.map((value: any) => ({ [fields[index]]: value })); | ||
const newCombinations: any[] = []; | ||
acc.forEach((accCombination: any) => { | ||
values.forEach((value: any) => { | ||
newCombinations.push({ ...accCombination, [fields[acc.length]]: value }); | ||
}); | ||
}); | ||
return newCombinations; | ||
}, []); | ||
// Adiciona ao Map somente combinações únicas com o ID gerado | ||
allCombinations.forEach((combination: any) => { | ||
const id = fields.map(field => combination[field]).join("_"); | ||
if (!result.has(id)) { | ||
result.set(id, { id, ...combination }); | ||
} | ||
}); | ||
// Adiciona ao Map somente combinações únicas com o ID gerado | ||
allCombinations.forEach((combination: any) => { | ||
const id = fields.map(field => combination[field]).join("_"); | ||
if (!result.has(id)) { | ||
result.set(id, { id, ...combination }); | ||
} | ||
}); | ||
}); | ||
return Array.from(result.values()); // Converte o Map em um array de objetos | ||
return Array.from(result.values()); // Converte o Map em um array de objetos | ||
@@ -106,20 +106,18 @@ } | ||
items.forEach((item: any, index: number) => { | ||
items.forEach((item: any, index: number) => { | ||
//MONTAGEM DA FORMULA COM OS VALORES | ||
let formulaToEnable: string = item.formulaToEnable | ||
//MONTAGEM DA FORMULA COM OS VALORES | ||
let formulaToEnable: string = item.formulaToEnable | ||
if (formulaToEnable) { | ||
formulaToEnable = buildFormula(questionsAnswereds, formulaToEnable) | ||
//TENTAR EXECUTAR A FORMULA | ||
let enable: boolean = false | ||
enable = execFormula(false, formulaToEnable) | ||
if (!enable) { | ||
items.splice(index, 1) | ||
} | ||
}) | ||
} | ||
}) | ||
// const result = generateIdentifiers(items, fieldsToGroup); | ||
// console.log(result) | ||
const groupeds2 = items.reduce((acc: any, currentValue: any, currentIndex: number, array: any[]) => { | ||
@@ -142,10 +140,10 @@ let itemAux = {} as { [key: string]: any, id: any, items: any[] } | ||
for (const chave of chavesOfItem) { | ||
const existingGrouped = acc.find((i: any) => i.id === chave.id) | ||
if (!existingGrouped) { | ||
// itemAux.id = chave | ||
itemAux = { ...itemAux, ...chave} | ||
itemAux = { ...itemAux, ...chave } | ||
itemAux.items = [] | ||
@@ -152,0 +150,0 @@ itemAux.items.push(currentValue) |
75000