Answer the question
In order to leave comments, you need to log in
How to create a variable in then and pass it to finally?
How to create a variable in the then block when querying the database and pass it to the finally block?
If you simply declare it in then - and refer to finally, then table is not defined.
directory.findAll({raw: true}) // Запрос ко всей таблице
.then(tables => {
var table = tables.reduce((acc, n) => {
const g = n.subBranch || n.branch;
(acc[g] = acc[g] || []).push(n);
return acc;
},{});
})
.finally(() => {
console.log(table);
});
});
Answer the question
In order to leave comments, you need to log in
If understood correctly
directory.findAll({raw: true}) // Запрос ко всей таблице
.then(tables => {
return tables.reduce((acc, n) => {
const g = n.subBranch || n.branch;
(acc[g] = acc[g] || []).push(n);
return acc;
},{});
})
.finally(table => {
console.log(table);
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question