fix(backend): include EpisodeSeen in season episodes and add entry credits endpoint

- Add getEntryCredits service method returning all cast + crew with People, ordered by cast_type, order, episode_count
- Add getEntryCredits controller method
- Add GET /entries/:id/credits route in entry.routes.js
- Include EpisodeSeen association in getSeasonEpisodes so seen dates are returned to frontend
This commit is contained in:
Mohammed Abad committed 2026-04-29 16:04:10 +01:00
1 parent e460290b9b
commit 22d111ef71
7 files changed
+51 -3

No files matched your search

+7
View File
@@ -99,6 +99,13 @@ class EntryController {
res.status(200).json(seasons);
});
// * GET - Get ALL credits (cast + crew) for an entry
getEntryCredits = asyncWrapper(async (req, res) => {
const { id } = req.params;
const credits = await _entryService.getEntryCredits(id);
res.status(200).json(credits);
});
// * PUT - REQUEST ENTRY REFRECH
refrechEntry = asyncWrapper(async (req, res, next) => {
const { id } = req.params;
+7 -1
View File
@@ -1,4 +1,5 @@
const Episode = require("../models/Episode");
const EpisodeSeen = require("../models/EpisodeSeen");
const Season = require("../models/Season");
@@ -53,7 +54,12 @@ class SeasonController {
const episodes = await Episode.findAll({
where: {
season_id: req.params.id
}
},
include: [{ model: EpisodeSeen }],
order: [
['episode_number', 'ASC'],
[EpisodeSeen, 'date_seen', 'ASC'],
],
});
if (episodes) {
+1
View File
@@ -30,6 +30,7 @@ entryRouter.put('/:id/ids', entryController.updateEntryIds);
entryRouter.delete('/:id', entryController.deleteEntry);
entryRouter.get('/:id/seasons', entryController.getEntrySeasons);
entryRouter.get('/:id/credits', entryController.getEntryCredits);
entryRouter.put('/:id/refresh', entryController.refrechEntry);
entryRouter.put('/:id/fetch-collection', entryController.fetchEntryCollection);
+31 -1
View File
@@ -118,6 +118,36 @@ class EntryService {
return entry;
}
/**
* Retrieves ALL credits (cast + crew) for an entry with associated people.
* Used by the Cast & Crew page to lazy-render large credit lists.
*
* @param {number} id - The entry ID.
* @returns {Promise<Array>} Array of plain credit objects with `people` populated.
*/
async getEntryCredits(id) {
if (!id) {
throw new BadRequestError("Entry id not provided");
}
const entry = await Entry.findByPk(id, { attributes: ['id'] });
if (!entry) {
throw new NotFoundError("Entry with the provided id was not found");
}
const credits = await Credit.findAll({
where: { entry_id: id },
include: [{ model: People, as: 'person' }],
order: [
['cast_type', 'ASC'],
['order', 'ASC'],
['episode_count', 'DESC'],
],
});
return credits.map(c => c.get({ plain: true }));
}
async createEntry(data, plain = true) {
// creating the object
var is_tvseries = data.release_date == null ? true : false;
@@ -454,4 +484,4 @@ class EntryService {
}
module.exports = new EntryService();
module.exports = new EntryService();