Firebase云功能出现问题

时间:2020-10-04 06:09:16

标签: typescript firebase firebase-realtime-database google-cloud-functions

我有一个分为几批的用户(学生)列表。根据批次,我也为这些学生提供各种测试。但是测试并不总是有效的。数据结构如下:

enter image description here

enter image description here

enter image description here

我的想法是,我将通过添加子级ActiveTest =测试ID来将特定的测试设置为在批次中处于活动状态。这会使用云功能自动将测试添加到批处理中的所有用户。

云功能如下:

async function updateStudents(test: string, target: any){
const dataSnap = await target.once('value')
const hpDataBase = admin.database().ref()
const promises: any[] = []
dataSnap.forEach((child: any) => {
    const key = child.key
    if(key!==null){
        console.log(key)
        const p = hpDataBase.child('users').child(key).child('currentTest').set(test)
        promises.push(p)
        return false
    }
    return false
})
return Promise.all(promises)
}

export const updatebatchTest = functions.database.ref('/Batches/{batchId}/ActiveTest').onCreate(async (snapshot, context) => {
const testId = snapshot.val()
const batch = snapshot.ref.parent?.key
const hpDataBase = admin.database().ref()
const snapshot2 = hpDataBase.child('users').orderByChild('Batch').equalTo(batch!)
await updateStudents(testId, snapshot2)
})

但是如果我添加测试,就可以选择。到批次,用户不会更新。请问我的问题在哪里?

0 个答案:

没有答案