(feat) update non default values

This commit is contained in:
ishaan-jaff 2024-02-20 18:55:20 -08:00
parent a4365926a1
commit 476f401b74
2 changed files with 30 additions and 3 deletions

View file

@ -3307,7 +3307,15 @@ async def update_key_fn(request: Request, data: UpdateKeyRequest):
if prisma_client is None:
raise Exception("Not connected to DB!")
non_default_values = {k: v for k, v in data_json.items() if v is not None}
# get non default values for key
non_default_values = {}
for k, v in data_json.items():
if v is not None and v not in (
[],
{},
0,
): # models default to [], spend defaults to 0, we should not reset these values
non_default_values[k] = v
response = await prisma_client.update_data(
token=key, data={**non_default_values, "token": key}
)
@ -4116,7 +4124,16 @@ async def user_update(data: UpdateUserRequest):
if prisma_client is None:
raise Exception("Not connected to DB!")
non_default_values = {k: v for k, v in data_json.items() if v is not None}
# get non default values for key
non_default_values = {}
for k, v in data_json.items():
if v is not None and v not in (
[],
{},
0,
): # models default to [], spend defaults to 0, we should not reset these values
non_default_values[k] = v
response = await prisma_client.update_data(
user_id=data_json["user_id"],
data=non_default_values,