Adding ability to update / patch by sku, adding uniqueness constraint violation checks
This commit is contained in:
1 parent
af5343da0c
commit
d8db87c13e
13 files changed
+541
-13
No files matched your search
@@ -33,6 +33,8 @@ async def create_static_connection(
|
||||
db: AsyncSession = Depends(get_db),
|
||||
actor: User = Depends(require_permission("static_connections:write")),
|
||||
):
|
||||
if await static_connection_crud.get_by_od_mm(db, payload.od_mm):
|
||||
raise HTTPException(status_code=409, detail="Static connection already exists")
|
||||
sc = await static_connection_crud.create(
|
||||
db, od_mm=payload.od_mm, od_in=payload.od_in
|
||||
)
|
||||
@@ -72,6 +74,12 @@ async def update_static_connection(
|
||||
if sc is None:
|
||||
raise HTTPException(status_code=404, detail="Static connection not found")
|
||||
changes = payload.model_dump(exclude_unset=True)
|
||||
if "od_mm" in changes:
|
||||
existing = await static_connection_crud.get_by_od_mm(db, changes["od_mm"])
|
||||
if existing is not None and existing.id != sc.id:
|
||||
raise HTTPException(
|
||||
status_code=409, detail="Static connection already exists"
|
||||
)
|
||||
sc = await static_connection_crud.update(db, sc, changes)
|
||||
await audit_crud.log(
|
||||
db,
|
||||
|
||||
Reference in new issue
Block a user