我正在使用Firebase为我的应用程序创建用户点系统,目前正在处理项目的后端部分。我想通过firebase函数每天/每月更新用户点,现在我正在弄清楚如何更新点。
我尝试使用下面的代码,但是我的数据库中没有任何实际变化。
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
admin.initializeApp;
export const onPointsEdit = functions.database
.ref('/Users/{userId}/points')
.onWrite((change, context)=>{
// Only edit data when it is first created.
if (change.before.exists()) {
return null;
}
// Exit when the data is deleted.
if (!change.after.exists()) {
return null;
}
// Grab the current value of what was written to the Realtime Database.
const original = change.after.val();
console.log('PointsChanging', context.params.pushId, original)
const newPoints = parseInt(original)/100*10 + parseInt(original)
const newPoint = newPoints.toString
return change.after.ref.set(newPoint);
})