Guard mixing
This commit is contained in:
@@ -13,7 +13,9 @@ def get_mixing_schema(name: str) -> dict[str, dict[str, Any]]:
|
||||
|
||||
|
||||
def get_mixing(name: str, tank: str) -> dict[str, Any]:
|
||||
m = read(name, f"select * from mixing where tank = '{tank}'")
|
||||
m = try_read(name, f"select * from mixing where tank = '{tank}'")
|
||||
if m == None:
|
||||
return {}
|
||||
d = {}
|
||||
d['tank'] = str(m['tank'])
|
||||
d['model'] = str(m['model'])
|
||||
@@ -61,6 +63,10 @@ def set_mixing_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
|
||||
|
||||
def set_mixing(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
if 'tank' not in cs.operations[0]:
|
||||
return ChangeSet()
|
||||
if get_mixing(name, cs.operations[0]['tank']) == {}:
|
||||
return ChangeSet()
|
||||
return execute_command(name, set_mixing_cmd(name, cs))
|
||||
|
||||
|
||||
@@ -77,6 +83,10 @@ def add_mixing_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
|
||||
|
||||
def add_mixing(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
if 'tank' not in cs.operations[0]:
|
||||
return ChangeSet()
|
||||
if get_mixing(name, cs.operations[0]['tank']) != {}:
|
||||
return ChangeSet()
|
||||
return execute_command(name, add_mixing_cmd(name, cs))
|
||||
|
||||
|
||||
@@ -93,6 +103,10 @@ def delete_mixing_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
|
||||
|
||||
def delete_mixing(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
if 'tank' not in cs.operations[0]:
|
||||
return ChangeSet()
|
||||
if get_mixing(name, cs.operations[0]['tank']) == {}:
|
||||
return ChangeSet()
|
||||
return execute_command(name, delete_mixing_cmd(name, cs))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user