From caa3204d3feab6986ac97336734be02deb481c67 Mon Sep 17 00:00:00 2001 From: Mike Keen Date: Mon, 24 Jan 2022 12:21:56 -0500 Subject: [PATCH] feat: xlsx 1:1 value support for root table --- src/utils/xls.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/utils/xls.js b/src/utils/xls.js index 83c11c20..4ab8ce05 100644 --- a/src/utils/xls.js +++ b/src/utils/xls.js @@ -54,12 +54,22 @@ export const createXlsFromSequelizeResults = (rows, model, hex = false, csv = fa let mainXlsRow = []; // Populate main sheet values - for (const [mainColName, mainCol] of columnsInMainSheet.entries()) { - if (!associations.map(singular => singular + 's').includes(mainColName)) { - if (row[mainCol] === null) { - row[mainCol] = 'null'; + for (const [i, mainColName] of columnsInMainSheet.entries()) { + if (row[mainColName] === null) { + row[mainColName] = 'null'; + } + + if (Object.keys(row).includes(mainColName) && Object.keys(row[mainColName]).includes('id')) { + if (!Object.keys(sheets).includes(mainColName + 's')) { + sheets[mainColName + 's'] = { name: mainColName + 's', data: [Object.keys(row[mainColName]).concat([model.name.split('_').join('') + 'Id'])], }; + } + sheets[mainColName + 's'].data.push(Object.values(row[mainColName]).map(val1 => encodeValue(val1, hex)).concat([encodeValue(row[mainColName].id, hex)])); + } + if (!associations.map(singular => singular + 's').includes(i)) { // Todo: change to colNames[i], but also filter column headings first (for skipping assoc cols) + if (row[mainColName] === null) { + row[mainColName] = 'null'; } - mainXlsRow.push(encodeValue(row[mainCol], hex)); + mainXlsRow.push(encodeValue(row[mainColName], hex)); } }