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
@@ -27,6 +27,8 @@ async def create_part_colour(
|
||||
db: AsyncSession = Depends(get_db),
|
||||
actor: User = Depends(require_permission("part_colours:write")),
|
||||
):
|
||||
if await part_colour_crud.get_by_name(db, payload.name):
|
||||
raise HTTPException(status_code=409, detail="Part colour already exists")
|
||||
pc = await part_colour_crud.create(db, name=payload.name)
|
||||
await audit_crud.log(
|
||||
db,
|
||||
@@ -62,6 +64,10 @@ async def update_part_colour(
|
||||
if pc is None:
|
||||
raise HTTPException(status_code=404, detail="Part colour not found")
|
||||
changes = payload.model_dump(exclude_unset=True)
|
||||
if "name" in changes:
|
||||
existing = await part_colour_crud.get_by_name(db, changes["name"])
|
||||
if existing is not None and existing.id != pc.id:
|
||||
raise HTTPException(status_code=409, detail="Part colour already exists")
|
||||
pc = await part_colour_crud.update(db, pc, changes)
|
||||
await audit_crud.log(
|
||||
db,
|
||||
|
||||
Reference in new issue
Block a user