From b5a521f6251b79687bffc6fc1cc70c6356053871 Mon Sep 17 00:00:00 2001 From: Carlos Valente <34649812+cpvalente@users.noreply.github.com> Date: Wed, 9 Nov 2022 22:19:33 +0100 Subject: [PATCH] refactor: excel import (#250) * refactor: public parsing function --- client/package.json | 2 +- server/package.json | 2 +- server/src/package.json | 2 +- server/src/utils/__tests__/parser.tests.js | 23 +--------------------- server/src/utils/parser.js | 17 ++-------------- 5 files changed, 6 insertions(+), 40 deletions(-) diff --git a/client/package.json b/client/package.json index 3f362754e..b11af3c13 100644 --- a/client/package.json +++ b/client/package.json @@ -1,6 +1,6 @@ { "name": "ontime-ui", - "version": "1.9.4", + "version": "1.9.5", "private": true, "dependencies": { "@chakra-ui/react": "^2.3.2", diff --git a/server/package.json b/server/package.json index 53c6c0fe2..27672985a 100644 --- a/server/package.json +++ b/server/package.json @@ -1,6 +1,6 @@ { "name": "ontime", - "version": "1.9.4", + "version": "1.9.5", "author": "Carlos Valente", "description": "Time keeping for live events", "repository": "https://github.com/cpvalente/ontime", diff --git a/server/src/package.json b/server/src/package.json index a019b0445..880b612d1 100644 --- a/server/src/package.json +++ b/server/src/package.json @@ -1,7 +1,7 @@ { "name": "ontime-server", "type": "module", - "version": "1.4.1", + "version": "1.4.2", "dependencies": { "body-parser": "^1.20.0", "dotenv": "^16.0.1", diff --git a/server/src/utils/__tests__/parser.tests.js b/server/src/utils/__tests__/parser.tests.js index 9db5bea23..a59f04ffb 100644 --- a/server/src/utils/__tests__/parser.tests.js +++ b/server/src/utils/__tests__/parser.tests.js @@ -1,6 +1,6 @@ import jest from 'jest-mock'; import { dbModelv1, dbModelv1 as dbModel } from '../../models/dataModel.js'; -import { isStringEmpty, parseExcel_v1, parseJson_v1, validateEvent_v1 } from '../parser.js'; +import { parseExcel_v1, parseJson_v1, validateEvent_v1 } from '../parser.js'; import { makeString, validateDuration } from '../parserUtils.js'; import { parseAliases_v1, parseUserFields_v1, parseViews_v1 } from '../parserUtils_v1.js'; @@ -876,24 +876,3 @@ describe('test validateDuration()', () => { }); }); }); - -describe('isStringEmpty() function', () => { - describe('returns true with any non empty', () => { - const notEmpty = ['test', 'thisalso', '123', '#']; - for (const testValue of notEmpty) { - it(testValue, () => { - const isEmpty = isStringEmpty(testValue); - expect(isEmpty).toBe(false); - }); - } - }); - describe('returns true empty string or undefined', () => { - const empty = ['', ' ', undefined, null]; - for (const testValue of empty) { - it(`handles ${testValue}`, () => { - const isEmpty = isStringEmpty(testValue); - expect(isEmpty).toBe(true); - }); - } - }); -}); diff --git a/server/src/utils/parser.js b/server/src/utils/parser.js index aebb58f50..d5282aa49 100644 --- a/server/src/utils/parser.js +++ b/server/src/utils/parser.js @@ -19,19 +19,6 @@ import { generateId } from './generate_id.js'; export const EXCEL_MIME = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; export const JSON_MIME = 'application/json'; -/** - * @description Whether a string is considered empty - * @param value - * @return {boolean} - */ -export const isStringEmpty = (value) => { - let v = value; - if (typeof value === 'string') { - v = value.replace(/\s+/g, ''); - } - return v === '' || !v; -}; - /** * @description Excel array parser * @param {array} excelData - array with excel sheet @@ -102,9 +89,9 @@ export const parseExcel_v1 = async (excelData) => { } else if (j === subtitleIndex) { event.subtitle = column; } else if (j === isPublicIndex) { - event.isPublic = isStringEmpty(column); + event.isPublic = Boolean(column); } else if (j === skipIndex) { - event.skip = isStringEmpty(column); + event.skip = Boolean(column); } else if (j === notesIndex) { event.note = column; } else if (j === colourIndex) {