Guard tank
This commit is contained in:
@@ -23,7 +23,9 @@ def get_tank_schema(name: str) -> dict[str, dict[str, Any]]:
|
||||
|
||||
|
||||
def get_tank(name: str, id: str) -> dict[str, Any]:
|
||||
t = read(name, f"select * from tanks where id = '{id}'")
|
||||
t = try_read(name, f"select * from tanks where id = '{id}'")
|
||||
if t == None:
|
||||
return {}
|
||||
xy = get_node_coord(name, id)
|
||||
d = {}
|
||||
d['id'] = str(t['id'])
|
||||
@@ -99,6 +101,10 @@ def set_tank_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
|
||||
|
||||
def set_tank(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
if 'id' not in cs.operations[0]:
|
||||
return ChangeSet()
|
||||
if get_tank(name, cs.operations[0]['id']) == {}:
|
||||
return ChangeSet()
|
||||
return execute_command(name, set_tank_cmd(name, cs))
|
||||
|
||||
|
||||
@@ -120,6 +126,10 @@ def add_tank_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
|
||||
|
||||
def add_tank(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
if 'id' not in cs.operations[0]:
|
||||
return ChangeSet()
|
||||
if get_tank(name, cs.operations[0]['id']) != {}:
|
||||
return ChangeSet()
|
||||
return execute_command(name, add_tank_cmd(name, cs))
|
||||
|
||||
|
||||
@@ -141,6 +151,10 @@ def delete_tank_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
|
||||
|
||||
def delete_tank(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
if 'id' not in cs.operations[0]:
|
||||
return ChangeSet()
|
||||
if get_tank(name, cs.operations[0]['id']) == {}:
|
||||
return ChangeSet()
|
||||
return execute_command(name, delete_tank_cmd(name, cs))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user