Switching to the registry paradigm
This commit is contained in:
@@ -2,7 +2,7 @@ import uuid
|
||||
from fastapi import Depends, HTTPException
|
||||
|
||||
from firm.core.routes import get_crud_router
|
||||
from firm.core.depends import get_logged_tenant_db_cursor
|
||||
from firm.core.depends import get_authed_tenant_registry
|
||||
|
||||
from firm.contract.models import Contract, ContractDraft, ContractDraftStatus, replace_variables_in_value, ContractFilters
|
||||
from firm.contract.schemas import ContractCreate, ContractRead, ContractUpdate, ContractInit
|
||||
@@ -17,10 +17,10 @@ del(contract_router.routes[3]) #update
|
||||
del(contract_router.routes[1]) #create
|
||||
|
||||
@contract_router.post("/", response_description="Contract Successfully created")
|
||||
async def create(schema: ContractCreate, db=Depends(get_logged_tenant_db_cursor)) -> ContractRead:
|
||||
await schema.validate_foreign_key(db)
|
||||
async def create(schema: ContractCreate, reg=Depends(get_authed_tenant_registry)) -> ContractRead:
|
||||
await schema.validate_foreign_key(reg.db)
|
||||
|
||||
draft = await ContractDraft.get(db, schema.draft_id)
|
||||
draft = await ContractDraft.get(reg.db, schema.draft_id)
|
||||
if not draft:
|
||||
raise HTTPException(status_code=404, detail=f"Contract draft not found!")
|
||||
|
||||
@@ -31,7 +31,7 @@ async def create(schema: ContractCreate, db=Depends(get_logged_tenant_db_cursor)
|
||||
contract_dict = schema.model_dump()
|
||||
del(contract_dict['draft_id'])
|
||||
|
||||
lawyer = await Entity.get(db, db.user.entity_id)
|
||||
lawyer = await Entity.get(reg.db, reg.user.entity_id)
|
||||
contract_dict['lawyer'] = lawyer.model_dump()
|
||||
|
||||
contract_dict['name'] = draft.name
|
||||
@@ -39,9 +39,9 @@ async def create(schema: ContractCreate, db=Depends(get_logged_tenant_db_cursor)
|
||||
parties = []
|
||||
for p in draft.parties:
|
||||
parties.append({
|
||||
'entity': await Entity.get(db, p.entity_id),
|
||||
'entity': await Entity.get(reg.db, p.entity_id),
|
||||
'part': p.part,
|
||||
'representative': await Entity.get(db, p.representative_id) if p.representative_id else None,
|
||||
'representative': await Entity.get(reg.db, p.representative_id) if p.representative_id else None,
|
||||
'signature_uuid': str(uuid.uuid4())
|
||||
})
|
||||
|
||||
@@ -50,7 +50,7 @@ async def create(schema: ContractCreate, db=Depends(get_logged_tenant_db_cursor)
|
||||
provisions = []
|
||||
for p in draft.provisions:
|
||||
p = p.provision
|
||||
provision = await ProvisionTemplate.get(db, p.provision_template_id) if p.type == "template" \
|
||||
provision = await ProvisionTemplate.get(reg.db, p.provision_template_id) if p.type == "template" \
|
||||
else p
|
||||
|
||||
provisions.append({
|
||||
@@ -60,11 +60,11 @@ async def create(schema: ContractCreate, db=Depends(get_logged_tenant_db_cursor)
|
||||
|
||||
contract_dict['provisions'] = provisions
|
||||
|
||||
record = await Contract.create(db, ContractInit(**contract_dict))
|
||||
await draft.update_status(db, ContractDraftStatus.published)
|
||||
record = await Contract.create(reg.db, ContractInit(**contract_dict))
|
||||
await draft.update_status(reg.db, ContractDraftStatus.published)
|
||||
|
||||
return ContractRead.from_model(record)
|
||||
|
||||
@contract_router.put("/{record_id}", response_description="")
|
||||
async def update(record_id: str, contract_form: ContractUpdate, db=Depends(get_logged_tenant_db_cursor)) -> ContractRead:
|
||||
async def update(record_id: str, contract_form: ContractUpdate, reg=Depends(get_authed_tenant_registry)) -> ContractRead:
|
||||
raise HTTPException(status_code=400, detail="No modification on contract")
|
||||
|
||||
Reference in New Issue
Block a user