feat: Add new command

This commit is contained in:
2026-06-10 17:01:51 +03:00
parent f9dc59729c
commit dc05528405
5 changed files with 74 additions and 0 deletions

View File

@@ -81,10 +81,46 @@ class UpdatePurchaseRequestStatusCommand:
values['tx_hash'] = tx_hash
if status == 'completed':
values['completed_at'] = datetime.now(timezone.utc)
else:
values['completed_at'] = None
return await self._unit_of_work.purchase_request_repository.update(request_id, values=values)
class UpdatePurchaseRequestCommand:
ALLOWED_FIELDS = frozenset({
'status',
'usdt_amount',
'rub_amount',
'exchange_rate',
'service_fee_percent',
'comment',
'admin_comment',
'target_wallet_chain',
'target_wallet_address',
'tx_hash',
'assigned_to',
})
def __init__(self, unit_of_work: IUnitOfWork, logger: ILogger):
self._unit_of_work = unit_of_work
self._logger = logger
@transactional
async def __call__(self, request_id: str, *, values: dict[str, Any]) -> PurchaseRequestEntity:
filtered = {k: v for k, v in values.items() if k in self.ALLOWED_FIELDS}
status = filtered.get('status')
if status is not None:
if status not in VALID_STATUSES:
raise ApplicationException(status_code=400, message='Invalid status')
if status == 'completed':
filtered['completed_at'] = datetime.now(timezone.utc)
else:
filtered['completed_at'] = None
return await self._unit_of_work.purchase_request_repository.update(request_id, values=filtered)
class SetPurchaseRequestQuoteCommand:
def __init__(self, unit_of_work: IUnitOfWork, logger: ILogger):
self._unit_of_work = unit_of_work