- Implement AdminDomainOrderTest to cover admin functionalities for domain orders including listing, confirming registration, KYC updates, activation, rejection, and refunds. - Implement ClientDomainOrderTest to cover client functionalities for placing domain orders, including validation for balance, duplicate orders, and domain normalization. - Ensure proper handling of domain pricing and service statuses throughout the tests.
92 lines
2.8 KiB
PHP
92 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories\Api\Domain;
|
|
|
|
use App\Enums\Product\ProductTypeEnums;
|
|
use App\Models\Order;
|
|
use App\Models\Service;
|
|
use App\Repositories\Api\BaseApiRepository;
|
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
|
|
|
class DomainOrderRepository extends BaseApiRepository
|
|
{
|
|
public function getModel(): string
|
|
{
|
|
return Order::class;
|
|
}
|
|
|
|
public function getDomainOrders(array $filters = []): LengthAwarePaginator
|
|
{
|
|
$perPage = min((int) ($filters['per_page'] ?? 15), 200);
|
|
|
|
$query = $this->model->newQuery()
|
|
->with(['customer', 'orderItems.product', 'orderItems.service', 'invoice'])
|
|
->whereHas('orderItems.product', fn ($q) =>
|
|
$q->where('product_type', ProductTypeEnums::DOMAIN->value)
|
|
)
|
|
->orderByDesc('created_at');
|
|
|
|
if (!empty($filters['status'])) {
|
|
$query->whereHas('orderItems.service', fn ($q) =>
|
|
$q->where('status', $filters['status'])
|
|
);
|
|
}
|
|
|
|
if (!empty($filters['customer'])) {
|
|
$s = $filters['customer'];
|
|
$query->whereHas('customer', fn ($q) =>
|
|
$q->where('fullname', 'like', "%{$s}%")
|
|
->orWhere('email', 'like', "%{$s}%")
|
|
);
|
|
}
|
|
|
|
if (!empty($filters['domain'])) {
|
|
$d = $filters['domain'];
|
|
$query->whereHas('orderItems', fn ($q) =>
|
|
$q->where('domain_name', 'like', "%{$d}%")
|
|
);
|
|
}
|
|
|
|
if (!empty($filters['from'])) {
|
|
$query->where('created_at', '>=', $filters['from']);
|
|
}
|
|
|
|
if (!empty($filters['to'])) {
|
|
$query->where('created_at', '<=', $filters['to'] . ' 23:59:59');
|
|
}
|
|
|
|
return $query->paginate($perPage);
|
|
}
|
|
|
|
public function findDomainOrder(int $id): ?Order
|
|
{
|
|
return $this->model->newQuery()
|
|
->with(['customer', 'orderItems.product', 'orderItems.service', 'invoice.invoiceItems'])
|
|
->whereHas('orderItems.product', fn ($q) =>
|
|
$q->where('product_type', ProductTypeEnums::DOMAIN->value)
|
|
)
|
|
->find($id);
|
|
}
|
|
|
|
public function countPending(): int
|
|
{
|
|
return $this->model->newQuery()
|
|
->whereHas('orderItems.product', fn ($q) =>
|
|
$q->where('product_type', ProductTypeEnums::DOMAIN->value)
|
|
)
|
|
->whereHas('orderItems.service', fn ($q) =>
|
|
$q->where('status', 'pending')
|
|
)
|
|
->count();
|
|
}
|
|
|
|
public function hasPendingOrActiveDomainByName(string $normalizedDomain): bool
|
|
{
|
|
return Service::whereHas('orderItem', fn ($q) =>
|
|
$q->where('domain_name', $normalizedDomain)
|
|
)
|
|
->whereNotIn('status', ['cancelled', 'refunded', 'terminated'])
|
|
->exists();
|
|
}
|
|
}
|