函数validateBusinessId导致无效变量businessExists.我试图根据业务是否存在于数据库中或上传的文件是否是主文件来分配不同的数据库路径。函数validateBusiness产生无效结果。不知道该怎么解决。我哪里出错了?
async function validateBusinessId(businessId: string) {
db.collection('business').doc(businessId).get()
.then((docSnapshot) => {
if (docSnapshot.exists) {
return true
} else {
return false
}
})
}
async function getDatabase(fileName: string, businessId: string) {
const businessExists = await validateBusinessId(businessId)
if ((fileName) && (fileName?.includes('masterFile'))) {
console.log('A new Master database file has been detected.')
return db.collection('products')
} else if ((businessId) && (businessExists)) {
// If the business exists, return business path
console.log('A new database file has been detected for business: ' + businessId)
return db.collection('business').doc(businessId).collection('products')
} else {
return null
}
}我们非常感谢你的帮助!
发布于 2020-10-06 05:52:35
好的,所以我发现我不正确地处理了查询结果的承诺。这是对我有用的密码。
async function validateBusinessId(businessId: string) {
const databaseDocumentSnapshot = await db.collection('business').doc(businessId).get()
if (databaseDocumentSnapshot.exists) {
return true
} else {
return false
}
}
async function getDatabase(fileName: string, businessId: string) {
const businessExists = await validateBusinessId(businessId)
if ((fileName) && (fileName?.includes('masterFile'))) {
console.log('A new Master database file has been detected.')
return db.collection('products')
} else if ((businessId) && (businessExists)) {
return db.collection('business').doc(businessId).collection('products')
} else {
console.log('No business with such ID exists: ' + businessId);
return null
}
}https://stackoverflow.com/questions/64219924
复制相似问题