inventorymgr/transfer_requests.py
def create_transfer_request() -> Dict[str, bool]:
    """API endpoint for creating transfer requests."""
    transfer_request_data = NewTransferRequest.parse_obj(request.json)
    borrowstate = BorrowState.query.get(transfer_request_data.borrowstate_id)
    issuing_user = User.query.get(session["user_id"])
    if borrowstate is None:
        raise APIError(reason="unknown_borrowstate", status_code=400)
    if borrowstate.borrowing_user_id != issuing_user.id:
        raise APIError(reason="insufficient_permissions", status_code=403)
    if borrowstate.returned_at is not None:
        raise APIError(reason="item_not_borrowed", status_code=400)
    target_user = User.query.get(transfer_request_data.target_user_id)
    item = borrowstate.borrowed_item
    if not set(item.required_qualifications) <= set(target_user.qualifications):
        raise APIError(reason="missing_qualifications", status_code=403)
    transfer_request = TransferRequest(
        target_user=target_user, issuing_user=issuing_user, borrowstate=borrowstate
    )
    db.session.add(transfer_request)
    db.session.commit()
    return {"success": True}
API endpoint for creating transfer requests.
API endpoint for creating transfer requests.
API endpoint for creating transfer requests .
def create_transfer_request() -> Dict[str, bool]:
    transfer_request_data = NewTransferRequest.parse_obj(request.json)
    borrowstate = BorrowState.query.get(transfer_request_data.borrowstate_id)
    issuing_user = User.query.get(session["user_id"])
    if borrowstate is None:
        raise APIError(reason="unknown_borrowstate", status_code=400)
    if borrowstate.borrowing_user_id != issuing_user.id:
        raise APIError(reason="insufficient_permissions", status_code=403)
    if borrowstate.returned_at is not None:
        raise APIError(reason="item_not_borrowed", status_code=400)
    target_user = User.query.get(transfer_request_data.target_user_id)
    item = borrowstate.borrowed_item
    if not set(item.required_qualifications) <= set(target_user.qualifications):
        raise APIError(reason="missing_qualifications", status_code=403)
    transfer_request = TransferRequest(
        target_user=target_user, issuing_user=issuing_user, borrowstate=borrowstate
    )
    db.session.add(transfer_request)
    db.session.commit()
    return {"success": True}
def create_transfer_request ( ) -> Dict [ str , bool ] : transfer_request_data = NewTransferRequest . parse_obj ( request . json ) borrowstate = BorrowState . query . get ( transfer_request_data . borrowstate_id ) issuing_user = User . query . get ( session [ "user_id" ] ) if borrowstate is None : raise APIError ( reason = "unknown_borrowstate" , status_code = 400 ) if borrowstate . borrowing_user_id != issuing_user . id : raise APIError ( reason = "insufficient_permissions" , status_code = 403 ) if borrowstate . returned_at is not None : raise APIError ( reason = "item_not_borrowed" , status_code = 400 ) target_user = User . query . get ( transfer_request_data . target_user_id ) item = borrowstate . borrowed_item if not set ( item . required_qualifications ) <= set ( target_user . qualifications ) : raise APIError ( reason = "missing_qualifications" , status_code = 403 ) transfer_request = TransferRequest ( target_user = target_user , issuing_user = issuing_user , borrowstate = borrowstate ) db . session . add ( transfer_request ) db . session . commit ( ) return { "success" : True }
API endpoint for creating transfer requests.
API endpoint for creating transfer requests .
"""API endpoint for creating transfer requests."""