schleife für alarmdaten in loop_done geändert

This commit is contained in:
Robert Richter 2019-12-28 11:41:27 +01:00
parent 2bd6db348e
commit 787cbadbaf

View File

@ -64,7 +64,35 @@ module.exports = function(db, async, app_cfg) {
if (err == null) { if (err == null) {
// Einsatzmittel zum Einsatz speichern // Einsatzmittel zum Einsatz speichern
var id = this.lastID; var id = this.lastID;
async.forEach(content.alarmdaten, function(item, done) {
function loop_done(waip_id) {
callback && callback(waip_id);
//console.log('all done');
}
var itemsProcessed = 0;
content.alarmdaten.forEach(function (item, index, array) {
db.run(`INSERT OR REPLACE INTO waip_einsatzmittel (id, waip_einsaetze_ID, waip_wachen_ID, wachenname, einsatzmittel, zeitstempel)
VALUES (
(select ID from waip_einsatzmittel where einsatzmittel like \'` + item.einsatzmittel + `\'),
\'` + id + `\',
(select id from waip_wachen where name_wache like \'` + item.wachenname + `\'),
\'` + item.wachenname + `\',
\'` + item.einsatzmittel + `\',
\'` + item.zeit_a + `\')`,
function(err) {
if (err == null) {
itemsProcessed++;
if (itemsProcessed === array.length) {
loop_done(id);
};
} else {
callback && callback(err);
};
});
});
/*async.concat(content.alarmdaten, function(item, done) {
db.run(`INSERT OR REPLACE INTO waip_einsatzmittel (id, waip_einsaetze_ID, waip_wachen_ID, wachenname, einsatzmittel, zeitstempel) db.run(`INSERT OR REPLACE INTO waip_einsatzmittel (id, waip_einsaetze_ID, waip_wachen_ID, wachenname, einsatzmittel, zeitstempel)
VALUES ( VALUES (
(select ID from waip_einsatzmittel where einsatzmittel like \'` + item.einsatzmittel + `\'), (select ID from waip_einsatzmittel where einsatzmittel like \'` + item.einsatzmittel + `\'),
@ -75,9 +103,12 @@ module.exports = function(db, async, app_cfg) {
\'` + item.zeit_a + `\')`); \'` + item.zeit_a + `\')`);
done(); done();
}, function(err_) { }, function(err_) {
if (err_) console.error(err_.message); if (err_) {
console.error(err_.message);
} else {
callback && callback(id); callback && callback(id);
}); }
});*/
} else { } else {
callback && callback(err); callback && callback(err);
}; };
@ -185,9 +216,9 @@ module.exports = function(db, async, app_cfg) {
function(err, rows) { function(err, rows) {
if (err == null && rows.length > 0) { if (err == null && rows.length > 0) {
// falls einsätze vorhanden, auch die null hinzufuegen // falls einsätze vorhanden, auch die null hinzufuegen
rows.push({ //rows.push({
"room": 0 //"room": 0
}); //});
callback && callback(rows); callback && callback(rows);
} else { } else {
callback && callback(null); callback && callback(null);