update Mo 9. Mär 20:01:01 CET 2020

This commit is contained in:
Robert Richter 2020-03-09 20:01:01 +01:00
parent 4839432a4a
commit d0cfa84b02
3 changed files with 28 additions and 9 deletions

View File

@ -78,7 +78,7 @@ module.exports = function(app, app_cfg, db, async, bcrypt, passport, io) {
passport.deserializeUser(function(id, done) {
db.get(`SELECT id, user, permissions,
(select reset_counter from waip_configs where user_id = ?) reset_counter
(select reset_counter from waip_user_config where user_id = ?) reset_counter
FROM waip_users WHERE id = ?`, [id, id], function(err, row) {
if (!row) {
return done(null, false);

View File

@ -98,7 +98,8 @@ module.exports = function (fs, bcrypt, app_cfg) {
arrival_time DATETIME,
wache_id INTEGER,
wache_nr INTEGER,
wache_name TEXT)`);
wache_name TEXT,
FOREIGN KEY (waip_uuid) REFERENCES waip_einsaetze(uuid) ON DELETE CASCADE ON UPDATE CASCADE)`);
// Benutzer-Tabelle erstellen
db.run(`CREATE TABLE waip_users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
@ -107,15 +108,33 @@ module.exports = function (fs, bcrypt, app_cfg) {
permissions TEXT,
ip_address TEXT)`);
// Einstellungs-Tabelle für Benutzer erstellen
db.run(`CREATE TABLE waip_configs (
db.run(`CREATE TABLE waip_user_config (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER,
reset_counter INTEGER)`);
reset_counter INTEGER,
FOREIGN KEY(user_id) REFERENCES waip_users(id))`);
// Ersetzungs-Tabelle fuer Einsatzmittelnamen erstellen
db.run(`CREATE TABLE waip_ttsreplace (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
einsatzmittel_typ TEXT,
einsatzmittel_rufname TEXT)`);
// Twitter-Account-Tabelle erstellen
db.run(`CREATE TABLE waip_twitter_accounts (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
tw_screen_name TEXT,
tw_consumer_key TEXT,
tw_consumer_secret TEXT,
tw_access_token_key TEXT,
tw_access_token_secret TEXT)`);
// Twitter-Listen-Tabelle erstellen
db.run(`CREATE TABLE waip_twitter_wachen (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
waip_wachen_id INTEGER,
tw_account_id INTEGER,
tw_account_list TEXT,
FOREIGN KEY(waip_wachen_id) REFERENCES waip_wachen(id),
FOREIGN KEY(tw_account_id) REFERENCES waip_twitter_accounts(id))`);
// Log erstellen
db.run(`CREATE TABLE waip_log (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
log_time DATETIME DEFAULT CURRENT_TIMESTAMP,

View File

@ -14,7 +14,7 @@ module.exports = function(db, uuidv4, app_cfg) {
} else {
// wenn user_id vorhanden, aber keine config, dann dts COALESCE(MAX(reset_counter), xxx)
select_reset_counter = `(SELECT COALESCE(MAX(reset_counter), ` + dts + `)
reset_counter FROM waip_configs WHERE user_id = ` + user_id + `)`;
reset_counter FROM waip_user_config WHERE user_id = ` + user_id + `)`;
};
// Einsätze für die gewählte Wachen_ID ermittel, und Ablaufzeit beachten
db.all(`SELECT waip_einsaetze_ID FROM
@ -318,7 +318,7 @@ module.exports = function(db, uuidv4, app_cfg) {
e.id,
DATETIME(e.zeitstempel, 'localtime') zeitstempel,
DATETIME(e.zeitstempel, '+' || (
SELECT COALESCE(MAX(reset_counter), ?) reset_counter FROM waip_configs WHERE user_id = ?
SELECT COALESCE(MAX(reset_counter), ?) reset_counter FROM waip_user_config WHERE user_id = ?
) || ' minutes', 'localtime') ablaufzeit,
e.EINSATZART, e.STICHWORT, e.SONDERSIGNAL, e.OBJEKT, e.ORT,e.ORTSTEIL, e.STRASSE,
e.BESONDERHEITEN, e.wgs84_x, e.wgs84_y, em1.EM_ALARMIERT, em0.EM_WEITERE
@ -521,7 +521,7 @@ module.exports = function(db, uuidv4, app_cfg) {
};
function db_get_userconfig(user_id, callback) {
db.get(`SELECT reset_counter FROM waip_configs
db.get(`SELECT reset_counter FROM waip_user_config
WHERE user_id = ?`, [user_id], function(err, row) {
if (err == null && row) {
callback && callback(row.reset_counter);
@ -536,10 +536,10 @@ module.exports = function(db, uuidv4, app_cfg) {
if (!(reset_counter >= 1 && reset_counter <= app_cfg.global.time_to_delete_waip)) {
reset_counter = app_cfg.global.default_time_for_standby;
};
db.run((`INSERT OR REPLACE INTO waip_configs
db.run((`INSERT OR REPLACE INTO waip_user_config
(id, user_id, reset_counter)
VALUES (
(select ID from waip_configs where user_id like \'` + user_id + `\'),
(select ID from waip_user_config where user_id like \'` + user_id + `\'),
\'` + user_id + `\',
\'` + reset_counter + `\')`), function(err) {
if (err == null) {