From 4a0fbb83d1d3e8ddbcf9b22e4892b6627c44e500 Mon Sep 17 00:00:00 2001 From: Alexandra Dumitru Date: Fri, 15 Apr 2022 14:44:09 +0300 Subject: [PATCH] fix: removing a label from the unit deletes it from the data layer --- src/models/units/units.model.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/models/units/units.model.js b/src/models/units/units.model.js index acd3f0d2..69074b13 100644 --- a/src/models/units/units.model.js +++ b/src/models/units/units.model.js @@ -344,6 +344,28 @@ class Unit extends Model { toStructuredCsv: true, }); + if (deleteXslsSheets.labels?.data.length > 1) { + const warehouseProjectIdIndex = + deleteXslsSheets.labels.data[0].indexOf('warehouseProjectId'); + if (warehouseProjectIdIndex >= 0) { + for ( + let index = deleteXslsSheets.labels.data.length - 1; + index > 0; + --index + ) { + if ( + deleteXslsSheets.labels.data[index][warehouseProjectIdIndex] != null + ) { + deleteXslsSheets.labels.data.splice(index, 1); + } + } + } + + if (deleteXslsSheets.labels.data.length === 1) { + delete deleteXslsSheets.labels; + } + } + const insertChangeList = await transformFullXslsToChangeList( insertXslsSheets, 'insert',