Adding ability to update / patch by sku, adding uniqueness constraint violation checks

This commit is contained in:
Ian Roddis committed 2026-09-21 10:43:36 -03:00
1 parent af5343da0c
commit d8db87c13e
13 files changed
+541 -13

No files matched your search

+29 -2
View File
@@ -1047,6 +1047,9 @@ async def update_part_type(
pt = await part_type_crud.get(db, part_type_id)
if pt is None:
raise HTTPException(status_code=404, detail="Part type not found")
existing = await part_type_crud.get_by_name(db, name)
if existing is not None and existing.id != pt.id:
raise HTTPException(status_code=409, detail="Part type already exists")
changes = {"name": name}
await part_type_crud.update(db, pt, changes)
await audit_crud.log(
@@ -1174,6 +1177,11 @@ async def update_sub_part_type(
spt = await sub_part_type_crud.get(db, sub_part_type_id)
if spt is None:
raise HTTPException(status_code=404, detail="Sub part type not found")
existing = await sub_part_type_crud.get_by_name_and_part_type(
db, name, part_type_id
)
if existing is not None and existing.id != spt.id:
raise HTTPException(status_code=409, detail="Sub part type already exists")
changes = {"name": name, "part_type_id": part_type_id}
await sub_part_type_crud.update(db, spt, changes)
await audit_crud.log(
@@ -1724,9 +1732,12 @@ async def create_augmented_part(
db: AsyncSession = Depends(get_db),
actor: User = Depends(web_require("augmented_parts:write")),
):
clean_sku = sku.strip() or None
if clean_sku and await augmented_part_crud.get_by_sku(db, clean_sku):
raise HTTPException(status_code=409, detail="SKU already in use")
created = await augmented_part_crud.create(
db,
sku=sku.strip() or None,
sku=clean_sku,
description=description,
colour_id=colour_id,
manufacturer_id=manufacturer_id,
@@ -2180,8 +2191,13 @@ async def update_augmented_part(
ap = await augmented_part_crud.get(db, augmented_part_id)
if ap is None:
raise HTTPException(status_code=404, detail="Augmented part not found")
clean_sku = sku.strip() or None
if clean_sku:
existing = await augmented_part_crud.get_by_sku(db, clean_sku)
if existing is not None and existing.id != ap.id:
raise HTTPException(status_code=409, detail="SKU already in use")
changes = {
"sku": sku.strip() or None,
"sku": clean_sku,
"description": description,
"colour_id": colour_id,
"manufacturer_id": manufacturer_id,
@@ -3065,6 +3081,9 @@ async def update_part_colour(
pc = await part_colour_crud.get(db, part_colour_id)
if pc is None:
raise HTTPException(status_code=404, detail="Part colour not found")
existing = await part_colour_crud.get_by_name(db, name)
if existing is not None and existing.id != pc.id:
raise HTTPException(status_code=409, detail="Part colour already exists")
changes = {"name": name}
await part_colour_crud.update(db, pc, changes)
await audit_crud.log(
@@ -3184,6 +3203,11 @@ async def update_attachment_point_name(
apn = await apn_crud.get(db, apn_id)
if apn is None:
raise HTTPException(status_code=404, detail="Attachment point name not found")
existing = await apn_crud.get_by_name(db, name)
if existing is not None and existing.id != apn.id:
raise HTTPException(
status_code=409, detail="Attachment point name already exists"
)
changes = {"name": name}
await apn_crud.update(db, apn, changes)
await audit_crud.log(
@@ -3521,6 +3545,9 @@ async def update_static_connection(
sc = await static_connection_crud.get(db, static_connection_id)
if sc is None:
raise HTTPException(status_code=404, detail="Static connection not found")
existing = await static_connection_crud.get_by_od_mm(db, od_mm)
if existing is not None and existing.id != sc.id:
raise HTTPException(status_code=409, detail="Static connection already exists")
changes = {"od_mm": od_mm, "od_in": od_in}
await static_connection_crud.update(db, sc, changes)
await audit_crud.log(