Я пытался получить результат, используя базу данных ms sql, используя ms sql npm и pu sh в массив. Кажется, что ответ вернет пустой массив вне функции карты, ваша помощь будет высоко оценена, спасибо.
module.exports = {
someRouteHandler: async function(req, res, next) {
const fileStream = await readFileFromS3(req.body.filename); //a function to read file from AWS S3
if (req.body.productName === "Nike" && type === "Male") {
const result = await getBrandInformation(req.body, fileStream); //this function will parse data from the file and return object result
const { brandInformation, brandItems } = result;
const noneDuplicateArrayContainer = [];
const duplicateArrayContainer = [];
for ( const { itemNumber } of brandItems ) {
let items = await getMatchingList(itemNumber); // will query to database if itemNumber has duplicate or none
if (items.length > 1) {
items.map(async({ identifier }) => {
//if identifier not null query cost
if (identifier) {
let cost = await queryCostToDb(identifier); //will query cost from database
duplicateArrayContainer.push({
brandItems, identifier, cost
})
//if identifier is null no cost to save
} else {
duplicateArrayContainer.push({
brandItems, identifier
})
}
});
//if items length is not greater than 1 meaning no duplicate
} else {
items.map(({ identifier }) => {
let cost = await queryCostToDb(identifier); //will query cost from database
noneDuplicateArrayContainer.push({
brandItems, identifier, cost
});
})
}
}
// when sending response noneDuplicateArrayContainer and duplicateArrayContainer is [ ]
// in the console, it has data, but response is delay
return res.status(200).json({ brandInformation, noneDuplicateArrayContainer, duplicateArrayContainer })
}
}
}