Last active
July 12, 2019 16:41
-
-
Save oreoluwade/5a43e75e5f5bd25e9435be1bc1bcb1a3 to your computer and use it in GitHub Desktop.
Checks the type and number of files we intend to upload and returns a value based on the specific type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = input => { | |
let filePath; | |
let filename; | |
let storage = []; | |
switch (Array.isArray(input)) { | |
case true: | |
input.forEach(element => { | |
filePath = element.path; | |
filename = element.originalname; | |
storage.push({ filePath, filename }); | |
}); | |
break; | |
case false: | |
if (typeof input === 'object' && Object.keys(input).length) { | |
Object.values(input).forEach(element => { | |
filePath = element[0].path; | |
filename = element[0].originalname; | |
storage = { filePath, filename }; | |
}); | |
} | |
break; | |
default: | |
break; | |
} | |
return storage; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment