Skip to content

Commit

Permalink
refactor: reduce complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
Seli0303 committed Jun 6, 2024
1 parent eb878d3 commit 0bc7826
Showing 1 changed file with 12 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,6 @@ export default {
this.$emit('failedToImportFile')
}
},
/**
* Parse csv file
* @param fileContent
* @returns {{newJobs: *[], newVehicles: *[]}}
*/
parseCsvFile(fileContent) {
let newJobs = []
let newVehicles = []
Expand Down Expand Up @@ -171,21 +166,9 @@ export default {
let newSkills = []

if (this.expectedData === 'jobs') {
for (const j of parsedJson) {
try {
newJobs.push(Job.fromObject(j))
} catch {
this.showError(this.$t('optimizationImport.notValid') + this.$t('optimization.jobs'),)
}
}
newJobs = this.parseJsonObjects(parsedJson, newJobs, Job, 'jobs')
} else if (this.expectedData === 'vehicles') {
for (const v of parsedJson) {
try {
newVehicles.push(Vehicle.fromObject(v))
} catch {
this.showError(this.$t('optimizationImport.notValid') + this.$t('optimization.vehicles'),)
}
}
newVehicles = this.parseJsonObjects(parsedJson, newVehicles, Vehicle, 'vehicles')
} else if (this.expectedData === 'skills') {
for (const s of parsedJson) {
try {
Expand All @@ -197,7 +180,16 @@ export default {
}
return {newJobs, newVehicles, newSkills}
},

parseJsonObjects(parsedJson, newObjects, ObjectClass, item) {
for (const j of parsedJson) {
try {
newObjects.push(ObjectClass.fromObject(j))
} catch {
this.showError(this.$t('optimizationImport.notValid') + this.$t(`optimization.${item}`),)
}
}
return newObjects
},
// save jobs from pasted JSON and return error if not a valid JSON
savePastedJson() {
try {
Expand Down

0 comments on commit 0bc7826

Please sign in to comment.