From 8a6ded2813fe5c795b58244efef6c8033cae8e7e Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Wed, 14 Feb 2024 15:41:21 +0100 Subject: [PATCH] fixes for errors reported in server log --- src/server/BreCal/impl/shipcalls.py | 9 +++++---- src/server/BreCal/schemas/model.py | 4 ++++ src/server/BreCal/services/schedule_routines.py | 2 +- src/server/BreCal/stubs/shipcall.py | 4 ++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/server/BreCal/impl/shipcalls.py b/src/server/BreCal/impl/shipcalls.py index fd222a7..82ff2a0 100644 --- a/src/server/BreCal/impl/shipcalls.py +++ b/src/server/BreCal/impl/shipcalls.py @@ -113,10 +113,11 @@ def PostShipcalls(schemaModel): commands.execute(query, schemaModel) new_id = commands.execute_scalar("select last_insert_id()") - # add participant assignments - pquery = "INSERT INTO shipcall_participant_map (shipcall_id, participant_id, type) VALUES (?shipcall_id?, ?participant_id?, ?type?)" - for participant_assignment in schemaModel["participants"]: - commands.execute(pquery, param={"shipcall_id" : new_id, "participant_id" : participant_assignment["participant_id"], "type" : participant_assignment["type"]}) + # add participant assignments if we have a list of participants + if 'participants' in schemaModel: + pquery = "INSERT INTO shipcall_participant_map (shipcall_id, participant_id, type) VALUES (?shipcall_id?, ?participant_id?, ?type?)" + for participant_assignment in schemaModel["participants"]: + commands.execute(pquery, param={"shipcall_id" : new_id, "participant_id" : participant_assignment["participant_id"], "type" : participant_assignment["type"]}) # apply 'Traffic Light' evaluation to obtain 'GREEN', 'YELLOW' or 'RED' evaluation state. The function internally updates the mysql database # evaluate_shipcall_state(mysql_connector_instance=pooledConnection, shipcall_id=new_id) # new_id (last insert id) refers to the shipcall id diff --git a/src/server/BreCal/schemas/model.py b/src/server/BreCal/schemas/model.py index cc2976b..b462e39 100644 --- a/src/server/BreCal/schemas/model.py +++ b/src/server/BreCal/schemas/model.py @@ -256,6 +256,10 @@ class User: user_phone: str password_hash: str api_key: str + notify_email: bool + notify_whatsapp: bool + notify_signal: bool + notify_popup: bool created: datetime modified: datetime diff --git a/src/server/BreCal/services/schedule_routines.py b/src/server/BreCal/services/schedule_routines.py index 77470fb..f83b631 100644 --- a/src/server/BreCal/services/schedule_routines.py +++ b/src/server/BreCal/services/schedule_routines.py @@ -27,7 +27,7 @@ def UpdateShipcalls(options:dict = {'past_days':2}): commands = pydapper.using(pooledConnection) query = ("SELECT id, ship_id, type, eta, voyage, etd, arrival_berth_id, departure_berth_id, tug_required, pilot_required, " "flags, pier_side, bunkering, replenishing_terminal, replenishing_lock, draft, tidal_window_from, tidal_window_to, rain_sensitive_cargo, recommended_tugs, " - "anchored, moored_lock, canceled, evaluation, evaluation_message, evaluation_message_sent, evaluation_time, created, modified FROM shipcall WHERE ((type = 1 OR type = 3) AND eta >= DATE(NOW() - INTERVAL %d DAY)" + "anchored, moored_lock, canceled, evaluation, evaluation_message, evaluation_notifications_sent, evaluation_time, created, modified FROM shipcall WHERE ((type = 1 OR type = 3) AND eta >= DATE(NOW() - INTERVAL %d DAY)" "OR (type = 2 AND etd >= DATE(NOW() - INTERVAL %d DAY))) " "ORDER BY eta") % (options["past_days"], options["past_days"]) diff --git a/src/server/BreCal/stubs/shipcall.py b/src/server/BreCal/stubs/shipcall.py index 9a166e1..e86d379 100644 --- a/src/server/BreCal/stubs/shipcall.py +++ b/src/server/BreCal/stubs/shipcall.py @@ -42,7 +42,7 @@ def get_shipcall_simple(): evaluation = None evaluation_message = "" evaluation_time = None - evaluation_message_sent = False + evaluation_notifications_sent = False created = datetime.datetime.now() modified = created+datetime.timedelta(seconds=10) @@ -75,7 +75,7 @@ def get_shipcall_simple(): evaluation, evaluation_message, evaluation_time, - evaluation_message_sent, + evaluation_notifications_sent, created, modified, participants,