let categories,products,seasons,sizes
categoryModel.find({}).then(a=>{
categories=a
productModel.find({}).then(b=>{
products=b
seasonModel.find({}).then(c=>{
seasons=c
sizeModel.find({}).then(d=>{
sizes=d
res.render("admin",{categories,products,seasons,sizes})
})
})
})
})
// имитирует ассинхронный запрос
function find(val){
return new Promise(resolve => setTimeout(
() => resolve(val),
Math.round(Math.random() * 5000)
));
};
// main - функция для примера, вставляйте код в свою ассинхронную функцию
async function main() {
const [categories, products, seasons, sizes] = await Promise.all([
find('categories'),
find('products'),
find('seasons'),
find('sizes')
]);
console.log(categories, products, seasons, sizes);
}
main()
async (req, res) => {
try {
const categories = await categoryModel.find({});
const products = await productModel.find({});
const seasons = await seasonModel.find({});
const sizes = await sizeModel.find({});
return res.render("admin", { categories, products, seasons, sizes });
} catch (error) {
console.log(error);
return res.render('error');
};
}
async (req, res) => {
try {
const [categories, products, seasons, sizes] = await Promise.all([
categoryModel.find({}),
productModel.find({}),
seasonModel.find({}),
sizeModel.find({})
])
return res.render("admin", { categories, products, seasons, sizes });
} catch (error) {
console.log(error);
return res.render('error');
};
}