Skip to content

Commit

Permalink
[5.0] MSCO-16: Fix issue where the device family and model are incorr…
Browse files Browse the repository at this point in the history
…ectly … (#44)

* MSCO-16: Fix issue where the device family and model are incorrectly imported

* Refactor code to make it more efficient

* Do not mutate the original 'record' and use lodash#identity to return the first argument it receives
  • Loading branch information
pcandia authored Mar 17, 2021
1 parent 89428c8 commit 498c58f
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,6 @@ define(function(require) {
self.renderResults(_.merge({}, _.pick(args, ['container', 'parent']), {
data: tmpData
}));

});
},

Expand Down Expand Up @@ -943,44 +942,39 @@ define(function(require) {
prepareReviewData: function(data) {
var self = this,
expected = _.get(data, 'columns.expected', []),
modifiersPerProp = {
brand: _.toLower,
family: _.toLower,
model: _.toLower
},
formattedData = {
data: {
fileName: data.fileName,
totalRecords: data.records.length,
columns: {
actual: data.columns.actual,
expected: expected
expected: expected,
others: []
},
recordsToReview: data.records.slice(0, 5),
recordsToReview: data.isDevices ? _.map(data.records, function(record) {
return _.chain({})
.merge(record, _.reduce(record, function(acc, value, prop) {
var modifier = _.get(modifiersPerProp, prop, _.identity);
return _.set(acc, prop, modifier(value));
}, {}))
.omit(['__parsed_extra'])
.value();
}) : data.records,
numMatches: 0,
totalMandatory: data.columns.expected.mandatory.length,
numString: ''
}
};

if (data.isDevices) {
// remove extra data not parsed properly .. Only Check this field for devices if they exist
_.each(formattedData.data.recordsToReview, function(record) {
if (record.brand) {
record.brand = _.lowerCase(record.brand);
}
if (record.family) {
record.family = _.lowerCase(record.family);
}
if (record.model) {
record.model = _.lowerCase(record.model);
}

delete record.__parsed_extra;
});
}

formattedData.data.columns.others = [];

var occurences;

// for each column in the csv, we check if it's one of the column mandatory or optional in that job.
// If not, then we add it to the list of 'Others' columns to choose from
// If not, then we add it to the list of 'others' columns to choose from
// This was added so users can submit their extra column they need to keep in the database, such as billing ids etc...
_.each(data.columns.actual, function(actualColumnName) {
occurences = 0;
Expand Down

0 comments on commit 498c58f

Please sign in to comment.