我正在nodejs
中通过网络推送forEach
发送Chrome通知,我正在更新回调中的日志表。但是,最后一条记录只会更新所有记录。如何控制这个。这是代码
records.forEach(function (record) {
var msgD = queueRecords[nc].Message.split('####');
var payloadMessage = "";
if (arrSubscribeDetails[bc].Source == "Desktop") { // for Desktop
payloadMessage = msgD[0] + '####' + msgD[2] + '####' + msgD[3] + '####' + msgD[4];
appType = 10;
} else { // for WAP
payloadMessage = msgD[1] + '####' + msgD[2] + '####' + msgD[3] + '####' + msgD[4];
appType = 1
}
notiType = msgD[5];
webPush.sendNotification(arrSubscribeDetails[bc].EndPoint, {
TTL: 345600,
payload: payloadMessage,
userPublicKey: arrSubscribeDetails[bc].PublicKey,
userAuth: arrSubscribeDetails[bc].AuthenticationKey,
}, function (subsDet) {
var vartimeStamp = objcommon.mongoTime();
var objectlogtable = new global.logtable();
objectlogtable.MatriId = queueRecords[nc].MatriId;
objectlogtable.DateUpdated = vartimeStamp;
objectlogtable.AppType = appType;
objectlogtable.notiType = notiType;
objectlogtable.Status = JSONObject["responsecode"];
insertLogTable(objectlogtable);
if (objectlogtable.Status != 201) {
var fieldName = 'SubscribeDetails.' + bc + '.Status';
var fieldValue = 1;
var queryUpdate = {};
queryUpdate[fieldName] = fieldValue;
updateBrowserNotificationTable(queueRecords[nc].MatriId, JSON.parse(JSON.stringify(queryUpdate)));
}
bc++;
callback(splitBrowsers(function (notificationDet) {}, arrSubscribeDetails, queueRecords, nc, bc));
});
});