Guard valve
This commit is contained in:
@@ -21,7 +21,9 @@ def get_valve_schema(name: str) -> dict[str, dict[str, Any]]:
|
||||
|
||||
|
||||
def get_valve(name: str, id: str) -> dict[str, Any]:
|
||||
p = read(name, f"select * from valves where id = '{id}'")
|
||||
p = try_read(name, f"select * from valves where id = '{id}'")
|
||||
if p == None:
|
||||
return {}
|
||||
d = {}
|
||||
d['id'] = str(p['id'])
|
||||
d['node1'] = str(p['node1'])
|
||||
@@ -81,6 +83,10 @@ def set_valve_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
|
||||
|
||||
def set_valve(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
if 'id' not in cs.operations[0]:
|
||||
return ChangeSet()
|
||||
if get_valve(name, cs.operations[0]['id']) == {}:
|
||||
return ChangeSet()
|
||||
return execute_command(name, set_valve_cmd(name, cs))
|
||||
|
||||
|
||||
@@ -100,6 +106,10 @@ def add_valve_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
|
||||
|
||||
def add_valve(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
if 'id' not in cs.operations[0]:
|
||||
return ChangeSet()
|
||||
if get_valve(name, cs.operations[0]['id']) != {}:
|
||||
return ChangeSet()
|
||||
return execute_command(name, add_valve_cmd(name, cs))
|
||||
|
||||
|
||||
@@ -119,6 +129,10 @@ def delete_valve_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
|
||||
|
||||
def delete_valve(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
if 'id' not in cs.operations[0]:
|
||||
return ChangeSet()
|
||||
if get_valve(name, cs.operations[0]['id']) == {}:
|
||||
return ChangeSet()
|
||||
return execute_command(name, delete_valve_cmd(name, cs))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user