This commit is contained in:
@@ -107,6 +107,44 @@ def delete_one(session: Session, _id: int) -> models.FormPublic:
|
||||
return result
|
||||
|
||||
|
||||
def get_delete_dependencies(
|
||||
session: Session,
|
||||
_id: int
|
||||
) -> list[models.DeleteDependency]:
|
||||
statement = select(models.Form).where(models.Form.id == _id)
|
||||
result = session.exec(statement)
|
||||
form = result.first()
|
||||
if not form:
|
||||
raise exceptions.FormNotFoundError(messages.Messages.not_found('form'))
|
||||
print(_id)
|
||||
statement_shipment = (
|
||||
select(models.Shipment)
|
||||
.where(models.Shipment.form_id == _id)
|
||||
.distinct()
|
||||
)
|
||||
statement_contracts = (
|
||||
select(models.Contract)
|
||||
.where(models.Contract.form_id == _id)
|
||||
.distinct()
|
||||
)
|
||||
shipments = session.exec(statement_shipment).all()
|
||||
contracts = session.exec(statement_contracts).all()
|
||||
result = [
|
||||
models.DeleteDependency(
|
||||
name=sh.name,
|
||||
id=sh.id,
|
||||
type='shipment'
|
||||
) for sh in shipments
|
||||
] + [
|
||||
models.DeleteDependency(
|
||||
name=f'{co.firstname} {co.lastname}',
|
||||
id=co.id,
|
||||
type='contract'
|
||||
) for co in contracts
|
||||
]
|
||||
return result
|
||||
|
||||
|
||||
def is_allowed(
|
||||
session: Session,
|
||||
user: models.User,
|
||||
|
||||
Reference in New Issue
Block a user