Fixed E2E test suites

This commit is contained in:
Alejandro Celaya 2022-12-11 13:22:16 +01:00
parent 0d7a0ee9ea
commit 0c3523c34a

View File

@ -39,9 +39,7 @@ class ShortUrlRepository extends EntitySpecificationRepository implements ShortU
->setFirstResult($filtering->offset);
// In case the ordering has been specified, the query could be more complex. Process it
if ($filtering->orderBy->hasOrderField()) {
$this->processOrderByForList($qb, $filtering);
}
$this->processOrderByForList($qb, $filtering);
$result = $qb->getQuery()->getResult();
if ($filtering->orderBy->field === 'visits') {
@ -53,6 +51,12 @@ class ShortUrlRepository extends EntitySpecificationRepository implements ShortU
private function processOrderByForList(QueryBuilder $qb, ShortUrlsListFiltering $filtering): void
{
// With no explicit order by, fallback to dateCreated-DESC
if (! $filtering->orderBy->hasOrderField()) {
$qb->orderBy('s.dateCreated', 'DESC');
return;
}
$fieldName = $filtering->orderBy->field;
$order = $filtering->orderBy->direction;
@ -65,9 +69,6 @@ class ShortUrlRepository extends EntitySpecificationRepository implements ShortU
->orderBy('COUNT(DISTINCT v)', $order);
} elseif (contains(['longUrl', 'shortCode', 'dateCreated', 'title'], $fieldName)) {
$qb->orderBy('s.' . $fieldName, $order);
} else {
// With no explicit order by, fallback to dateCreated-DESC
$qb->orderBy('s.dateCreated', 'DESC');
}
}