From df859d5d6eab5e5bdb17010c3351cbff2b4b4979 Mon Sep 17 00:00:00 2001 From: Marius Date: Thu, 3 Mar 2022 12:44:19 +0200 Subject: [PATCH] fix: replace the old XLS generation with the new one --- src/controllers/project.controller.js | 2 -- src/controllers/units.controller.js | 2 -- src/models/projects/projects.model.js | 6 ------ src/models/units/units.model.js | 6 ------ src/utils/xls.js | 18 ++++-------------- 5 files changed, 4 insertions(+), 30 deletions(-) diff --git a/src/controllers/project.controller.js b/src/controllers/project.controller.js index db8b371c..5655b983 100644 --- a/src/controllers/project.controller.js +++ b/src/controllers/project.controller.js @@ -179,10 +179,8 @@ export const findAll = async (req, res) => { createXlsFromSequelizeResults({ rows: response, model: Project, - hex: false, toStructuredCsv: false, excludeOrgUid: true, - isUserFriendlyFormat: true, }), res, ); diff --git a/src/controllers/units.controller.js b/src/controllers/units.controller.js index 79244471..34b163ce 100644 --- a/src/controllers/units.controller.js +++ b/src/controllers/units.controller.js @@ -188,10 +188,8 @@ export const findAll = async (req, res) => { createXlsFromSequelizeResults({ rows: response, model: Unit, - hex: false, toStructuredCsv: false, excludeOrgUid: true, - isUserFriendlyFormat: true, }), res, ); diff --git a/src/models/projects/projects.model.js b/src/models/projects/projects.model.js index 8fc0a2a8..ffa1ec13 100644 --- a/src/models/projects/projects.model.js +++ b/src/models/projects/projects.model.js @@ -293,28 +293,22 @@ class Project extends Model { const insertXslsSheets = createXlsFromSequelizeResults({ rows: insertRecords, model: Project, - hex: false, toStructuredCsv: true, excludeOrgUid: false, - isUserFriendlyFormat: false, }); const updateXslsSheets = createXlsFromSequelizeResults({ rows: updateRecords, model: Project, - hex: false, toStructuredCsv: true, excludeOrgUid: false, - isUserFriendlyFormat: false, }); const deleteXslsSheets = createXlsFromSequelizeResults({ rows: deletedRecords, model: Project, - hex: false, toStructuredCsv: true, excludeOrgUid: false, - isUserFriendlyFormat: false, }); const insertChangeList = await transformFullXslsToChangeList( diff --git a/src/models/units/units.model.js b/src/models/units/units.model.js index 29e14f69..dec8b8cd 100644 --- a/src/models/units/units.model.js +++ b/src/models/units/units.model.js @@ -307,28 +307,22 @@ class Unit extends Model { const insertXslsSheets = createXlsFromSequelizeResults({ rows: insertRecords, model: Unit, - hex: false, toStructuredCsv: true, excludeOrgUid: false, - isUserFriendlyFormat: false, }); const updateXslsSheets = createXlsFromSequelizeResults({ rows: updateRecords, model: Unit, - hex: false, toStructuredCsv: true, excludeOrgUid: false, - isUserFriendlyFormat: false, }); const deleteXslsSheets = createXlsFromSequelizeResults({ rows: deletedRecords, model: Unit, - hex: false, toStructuredCsv: true, excludeOrgUid: false, - isUserFriendlyFormat: false, }); const insertChangeList = await transformFullXslsToChangeList( diff --git a/src/utils/xls.js b/src/utils/xls.js index 58768ebf..2df9995b 100644 --- a/src/utils/xls.js +++ b/src/utils/xls.js @@ -54,12 +54,14 @@ export const encodeValue = (value, hex = false) => { * @param toStructuredCsv {Boolean} - Whether to generate an XLS/CSV * @param excludeOrgUid {Boolean} - Whether to exclude the organization id from the result */ -export function createXlsFromResults({ +export function createXlsFromSequelizeResults({ rows, model, toStructuredCsv = false, excludeOrgUid = false, }) { + // TODO MariusD: Test with null values + // Unsure if this is need, therefore just left the semi-deep-clone here. The assumption is that it wants to remove all functions from the prototypes. const rowsClone = JSON.parse(JSON.stringify(rows)); // Sadly this is the best way to simplify sequelize's return shape @@ -285,7 +287,7 @@ function buildObjectXlsData({ return aggregatedData; } -export const createXlsFromSequelizeResults = ({ +export const createXlsFromSequelizeResults_old = ({ rows, model, hex = false, @@ -293,16 +295,6 @@ export const createXlsFromSequelizeResults = ({ excludeOrgUid = false, isUserFriendlyFormat = true, }) => { - return createXlsFromResults({ - rows, - model, - toStructuredCsv, - excludeOrgUid, - }); - // TODO MariusD: Test with null values - - /* eslint-disable no-unreachable */ - rows = JSON.parse(JSON.stringify(rows)); // Sadly this is the best way to simplify sequelize's return shape let columnsInResults = []; @@ -466,8 +458,6 @@ export const createXlsFromSequelizeResults = ({ } else { return xlsData; } - - /* eslint-enable no-unreachable */ }; export const tableDataFromXlsx = (xlsx, model) => {