catalog: improve sort fields namings

Signed-off-by: Vincenzo Scamporlino <vincenzos@spotify.com>
This commit is contained in:
Vincenzo Scamporlino
2023-01-24 11:25:57 +01:00
parent 58c78d3748
commit 7c47a38cc1
@@ -356,8 +356,7 @@ export class DefaultEntitiesCatalog implements EntitiesCatalog {
...cursor.sortFields[0],
};
const [sortFieldValue, metadataSortFieldValue] =
cursor.sortFieldValues || [];
const [prevItemSortFieldValue, prevItemUid] = cursor.sortFieldValues || [];
const dbQuery = db('search')
.join('final_entities', 'search.entity_id', 'final_entities.entity_id')
@@ -379,17 +378,17 @@ export class DefaultEntitiesCatalog implements EntitiesCatalog {
const isOrderingDescending = sortField.order === 'desc';
if (sortFieldValue) {
if (prevItemSortFieldValue) {
dbQuery.andWhere(
'value',
isFetchingBackwards !== isOrderingDescending ? '<' : '>',
sortFieldValue,
prevItemSortFieldValue,
);
dbQuery.orWhere(function nested() {
this.where('value', '=', sortFieldValue).andWhere(
this.where('value', '=', prevItemSortFieldValue).andWhere(
'search.entity_id',
isFetchingBackwards !== isOrderingDescending ? '<' : '>',
metadataSortFieldValue,
prevItemUid,
);
});
}