feat(people): add pagination support to getAllPeople endpoint

Support optional page, limit, and search query params.
Returns { data, total, page, totalPages } when paginated,
plain array for backward compatibility.

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
Mohammed AbadandCopilot committed 2026-04-27 13:29:16 +01:00
1 parent 8aca121b10
commit 6d676d803c
5 files changed
+57 -87

No files matched your search

+10 -1
View File
@@ -14,7 +14,16 @@ class PeopleController {
}
async getAllPeople(req, res) {
const people = await _peopleService.getAllPeople();
const { page, limit, search } = req.query;
const options = {};
if (page && limit) {
options.page = parseInt(page);
options.limit = parseInt(limit);
}
if (search) {
options.search = search;
}
const people = await _peopleService.getAllPeople(false, options);
res.status(200).json(people);
}
+27 -3
View File
@@ -19,7 +19,7 @@ class PeopleService {
return PeopleService.instance;
}
async getAllPeople(includeCrew = false) {
async getAllPeople(includeCrew = false, { page, limit, search } = {}) {
let where = {
where: {
cast_type: 'cast'
@@ -30,7 +30,13 @@ class PeopleService {
where = {};
}
const people = await People.findAll({
const peopleWhere = {};
if (search) {
peopleWhere.name = { [Op.like]: `%${search}%` };
}
const queryOptions = {
where: peopleWhere,
order: [["popularity", "DESC"]],
include: [
{
@@ -45,8 +51,26 @@ class PeopleService {
},
{ model: Media, as: 'medias' }
],
});
};
// If pagination params provided, use findAndCountAll
if (page != null && limit != null) {
queryOptions.limit = limit;
queryOptions.offset = (page - 1) * limit;
queryOptions.distinct = true;
const { count, rows } = await People.findAndCountAll(queryOptions);
return {
data: rows,
total: count,
page,
totalPages: Math.ceil(count / limit),
};
}
// Legacy: return plain array for backward compat
const people = await People.findAll(queryOptions);
return people;
}