Refactor contact handling across backend and frontend

Replaced usage of "ContactPerson" with "Contact" for consistency across the codebase. Updated related component props, state variables, API calls, and database queries to align with the new model. Also enhanced backend functionality with stricter validations and added support for handling active pgroups in contact management.
This commit is contained in:
GotthardG
2025-01-22 16:31:08 +01:00
parent 6cde57f783
commit 382b1eaba8
24 changed files with 627 additions and 373 deletions

View File

@ -7,7 +7,7 @@ import json
from app.models import (
Shipment as ShipmentModel,
ContactPerson as ContactPersonModel,
Contact as ContactModel,
Address as AddressModel,
Proposal as ProposalModel,
Dewar as DewarModel,
@ -19,7 +19,7 @@ from app.schemas import (
ShipmentCreate,
UpdateShipmentComments,
Shipment as ShipmentSchema,
ContactPerson as ContactPersonSchema,
Contact as ContactSchema,
Sample as SampleSchema,
DewarSchema,
)
@ -71,10 +71,8 @@ async def get_dewars_by_shipment_id(shipment_id: int, db: Session = Depends(get_
@router.post("", response_model=ShipmentSchema, status_code=status.HTTP_201_CREATED)
async def create_shipment(shipment: ShipmentCreate, db: Session = Depends(get_db)):
contact_person = (
db.query(ContactPersonModel)
.filter(ContactPersonModel.id == shipment.contact_person_id)
.first()
contact = (
db.query(ContactModel).filter(ContactModel.id == shipment.contact_id).first()
)
return_address = (
db.query(AddressModel)
@ -85,7 +83,7 @@ async def create_shipment(shipment: ShipmentCreate, db: Session = Depends(get_db
db.query(ProposalModel).filter(ProposalModel.id == shipment.proposal_id).first()
)
if not (contact_person or return_address or proposal):
if not (contact or return_address or proposal):
raise HTTPException(status_code=404, detail="Associated entity not found")
db_shipment = ShipmentModel(
@ -93,7 +91,7 @@ async def create_shipment(shipment: ShipmentCreate, db: Session = Depends(get_db
shipment_date=shipment.shipment_date,
shipment_status=shipment.shipment_status,
comments=shipment.comments,
contact_person_id=contact_person.id,
contact_id=contact.id,
return_address_id=return_address.id,
proposal_id=proposal.id,
)
@ -189,8 +187,8 @@ async def update_shipment(
# Validate relationships by IDs
contact_person = (
db.query(ContactPersonModel)
.filter(ContactPersonModel.id == updated_shipment.contact_person_id)
db.query(ContactModel)
.filter(ContactModel.id == updated_shipment.contact_person_id)
.first()
)
return_address = (
@ -225,9 +223,7 @@ async def update_shipment(
for key, value in update_fields.items():
if key == "contact_person_id":
contact_person = (
db.query(ContactPersonModel)
.filter(ContactPersonModel.id == value)
.first()
db.query(ContactModel).filter(ContactModel.id == value).first()
)
if not contact_person:
raise HTTPException(
@ -342,9 +338,9 @@ async def remove_dewar_from_shipment(
return shipment
@router.get("/contact_persons", response_model=List[ContactPersonSchema])
@router.get("/contact_persons", response_model=List[ContactSchema])
async def get_shipment_contact_persons(db: Session = Depends(get_db)):
contact_persons = db.query(ContactPersonModel).all()
contact_persons = db.query(ContactModel).all()
return contact_persons