У меня есть 3 функции:
const getCategories = async () => {
const categories = await db
.collection('config/estate/categories')
.get()
.then(res => {
const cats = []
res.forEach(cat => {
cats.push({
id: cat.id,
name: cat.data().label
})
})
return cats
})
return categories
}
const getCategorySubTypes = async category => {
const subTypes = await db
.collection(`config/estate/categories/${category}/types`)
.get()
.then(res => {
const cats = []
res.forEach(cat => cats.push({ id: cat.id, name: cat.data().label }))
return cats
})
return subTypes
}
exports.estateGetCategoriesWithSubTypes = functions.https.onRequest(async (req, res) => {
const categories = await getCategories()
const promises = categories.map(category => {
getCategorySubTypes(category.id)
})
const subTypes = await Promise.all(promises)
console.log(subTypes)
res.status(200).send(subTypes)
})
В функции estateGetCategoriesWithSubTypes
я хочу получить массив подтипов для всех категорий. У меня есть некоторые проблемы с обещаниями. Теперь у меня есть массив [undefined, undefined, undefined]. Помогите мне, пожалуйста, правильно организовать код!