Added actors pagination.
This commit is contained in:
@@ -62,20 +62,23 @@ export async function fetchActorsById(actorIds) {
|
||||
.groupBy('actors.id', 'avatars.id'),
|
||||
]);
|
||||
|
||||
return actorIds.map((actorId) => {
|
||||
const curatedActors = actorIds.map((actorId) => {
|
||||
const actor = actors.find((actorEntry) => actorEntry.id === actorId);
|
||||
|
||||
if (!actor) {
|
||||
console.warn(`Can't find ${actorId}`);
|
||||
return null;
|
||||
}
|
||||
|
||||
return curateActor(actor);
|
||||
}).filter(Boolean);
|
||||
|
||||
return curatedActors;
|
||||
}
|
||||
|
||||
function curateOptions(options) {
|
||||
if (options?.limit > 100) {
|
||||
throw new HttpError('Limit must be <= 100', 400);
|
||||
if (options?.limit > 120) {
|
||||
throw new HttpError('Limit must be <= 120', 400);
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -108,8 +111,6 @@ function buildQuery(filters) {
|
||||
|
||||
['gender', 'country'].forEach((attribute) => {
|
||||
if (filters[attribute]) {
|
||||
console.log(attribute, filters[attribute]);
|
||||
|
||||
query.bool.must.push({
|
||||
equals: {
|
||||
[attribute]: filters[attribute],
|
||||
@@ -197,6 +198,9 @@ 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',
|
||||
query,
|
||||
|
||||
@@ -24,8 +24,6 @@ function curateScene(rawScene, assets) {
|
||||
return null;
|
||||
}
|
||||
|
||||
console.log(assets.channel);
|
||||
|
||||
return {
|
||||
id: rawScene.id,
|
||||
title: rawScene.title,
|
||||
|
||||
@@ -26,7 +26,7 @@ export async function fetchActorsApi(req, res) {
|
||||
total,
|
||||
} = await fetchActors(curateActorsQuery(req.query), {
|
||||
page: Number(req.query.page) || 1,
|
||||
limit: Number(req.query.limit) || 50,
|
||||
limit: Number(req.query.limit) || 120,
|
||||
});
|
||||
|
||||
res.send({
|
||||
|
||||
Reference in New Issue
Block a user