Skip to content

Commit

Permalink
fix: replace the old XLS generation with the new one
Browse files Browse the repository at this point in the history
  • Loading branch information
Marius authored and MariusDec committed Mar 3, 2022
1 parent 0075aad commit df859d5
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 30 deletions.
2 changes: 0 additions & 2 deletions src/controllers/project.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,8 @@ export const findAll = async (req, res) => {
createXlsFromSequelizeResults({
rows: response,
model: Project,
hex: false,
toStructuredCsv: false,
excludeOrgUid: true,
isUserFriendlyFormat: true,
}),
res,
);
Expand Down
2 changes: 0 additions & 2 deletions src/controllers/units.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,8 @@ export const findAll = async (req, res) => {
createXlsFromSequelizeResults({
rows: response,
model: Unit,
hex: false,
toStructuredCsv: false,
excludeOrgUid: true,
isUserFriendlyFormat: true,
}),
res,
);
Expand Down
6 changes: 0 additions & 6 deletions src/models/projects/projects.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 0 additions & 6 deletions src/models/units/units.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
18 changes: 4 additions & 14 deletions src/utils/xls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -285,24 +287,14 @@ function buildObjectXlsData({
return aggregatedData;
}

export const createXlsFromSequelizeResults = ({
export const createXlsFromSequelizeResults_old = ({
rows,
model,
hex = false,
toStructuredCsv = false,
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 = [];
Expand Down Expand Up @@ -466,8 +458,6 @@ export const createXlsFromSequelizeResults = ({
} else {
return xlsData;
}

/* eslint-enable no-unreachable */
};

export const tableDataFromXlsx = (xlsx, model) => {
Expand Down

0 comments on commit df859d5

Please sign in to comment.