Moved filter sections to their own components.
This commit is contained in:
@@ -23,13 +23,14 @@ export function curateActor(actor, context = {}) {
|
||||
alpha2: actor.residence_country_alpha2,
|
||||
name: actor.residence_country_name,
|
||||
},
|
||||
avatar: actor.avatar_id ? {
|
||||
id: actor.avatar_id,
|
||||
path: actor.avatar_path,
|
||||
thumbnail: actor.avatar_thumbnail,
|
||||
lazy: actor.avatar_lazy,
|
||||
isS3: actor.avatar_s3,
|
||||
} : null,
|
||||
avatar: actor.avatar && {
|
||||
id: actor.avatar.id,
|
||||
path: actor.avatar.path,
|
||||
thumbnail: actor.avatar.thumbnail,
|
||||
lazy: actor.avatar.lazy,
|
||||
isS3: actor.avatar.is_s3,
|
||||
},
|
||||
likes: actor.stashed,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -46,20 +47,9 @@ export function sortActorsByGender(actors) {
|
||||
|
||||
export async function fetchActorsById(actorIds) {
|
||||
const [actors] = await Promise.all([
|
||||
knex('actors')
|
||||
.select(
|
||||
'actors.*',
|
||||
'avatars.id as avatar_id',
|
||||
'avatars.path as avatar_path',
|
||||
'avatars.thumbnail as avatar_thumbnail',
|
||||
'avatars.lazy as avatar_lazy',
|
||||
'avatars.width as avatar_width',
|
||||
'avatars.height as avatar_height',
|
||||
'avatars.is_s3 as avatar_s3',
|
||||
)
|
||||
.whereIn('actors.id', actorIds)
|
||||
.leftJoin('media as avatars', 'avatars.id', 'actors.avatar_media_id')
|
||||
.groupBy('actors.id', 'avatars.id'),
|
||||
knex('actors_meta')
|
||||
.select('actors_meta.*')
|
||||
.whereIn('actors_meta.id', actorIds),
|
||||
]);
|
||||
|
||||
const curatedActors = actorIds.map((actorId) => {
|
||||
@@ -85,6 +75,7 @@ function curateOptions(options) {
|
||||
page: options?.page || 1,
|
||||
limit: options?.limit || 30,
|
||||
requireAvatar: options?.requireAvatar || false,
|
||||
order: [options.order?.[0] || 'name', options.order?.[1] || 'asc'],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -194,12 +185,33 @@ function buildQuery(filters) {
|
||||
return { query, expressions };
|
||||
}
|
||||
|
||||
const sortMap = {
|
||||
likes: 'stashed',
|
||||
scenes: 'scenes',
|
||||
};
|
||||
|
||||
function getSort(order) {
|
||||
if (order[0] === 'name') {
|
||||
return [{
|
||||
slug: order[1],
|
||||
}];
|
||||
}
|
||||
|
||||
return [
|
||||
{
|
||||
[sortMap[order[0]]]: order[1],
|
||||
},
|
||||
{
|
||||
slug: 'asc', // sort by name where primary order is equal
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
export async function fetchActors(filters, rawOptions) {
|
||||
const options = curateOptions(rawOptions);
|
||||
const { query, expressions } = buildQuery(filters);
|
||||
|
||||
console.log(options);
|
||||
console.log('offset', (options.page - 1) * options.limit);
|
||||
|
||||
const result = await searchApi.search({
|
||||
index: 'actors',
|
||||
@@ -207,7 +219,7 @@ export async function fetchActors(filters, rawOptions) {
|
||||
expressions,
|
||||
limit: options.limit,
|
||||
offset: (options.page - 1) * options.limit,
|
||||
sort: [{ slug: 'asc' }],
|
||||
sort: getSort(options.order),
|
||||
aggs: {
|
||||
countries: {
|
||||
terms: {
|
||||
|
||||
@@ -27,6 +27,7 @@ export async function fetchActorsApi(req, res) {
|
||||
} = await fetchActors(curateActorsQuery(req.query), {
|
||||
page: Number(req.query.page) || 1,
|
||||
limit: Number(req.query.limit) || 120,
|
||||
order: req.query.order?.split('.') || ['likes', 'desc'],
|
||||
});
|
||||
|
||||
res.send({
|
||||
|
||||
Reference in New Issue
Block a user