Auto-upgrade TV status on watch, full-width layout, settings tabs

Marking episode/entry as watched now auto-upgrades TV series from
plan_to_watch/null to watching. Settings page uses tabs (General/Maintenance)
with 2-column grid. AppLayout container removed for full-width pages.
This commit is contained in:
X4Lo committed 2026-06-23 03:53:22 +01:00
1 parent cdbaedd7d0
commit b001ee2240
4 files changed
+267 -215

No files matched your search

+27 -17
View File
@@ -1,7 +1,7 @@
const Entry = require("../models/Entry");
const Episode = require("../models/Episode");
const EpisodeSeen = require("../models/EpisodeSeen");
const Season = require("../models/Season");
const Entry = require('../models/Entry');
const Episode = require('../models/Episode');
const EpisodeSeen = require('../models/EpisodeSeen');
const Season = require('../models/Season');
class EpisodeSeenController {
constructor() {
@@ -25,7 +25,7 @@ class EpisodeSeenController {
const episodeSeen = await EpisodeSeen.findByPk(req.params.id);
if (!episodeSeen) {
res.status(404).json({ message: "Episode seen record not found." });
res.status(404).json({ message: 'Episode seen record not found.' });
}
res.status(200).json(episodeSeen);
@@ -39,10 +39,10 @@ class EpisodeSeenController {
const { entry_id, episode_id, date_seen, seen_with } = req.body;
const entry = await Entry.findByPk(entry_id);
if (!entry) return res.status(404).json({ error: "Entry not found" });
if (!entry) return res.status(404).json({ error: 'Entry not found' });
const episode = await Episode.findByPk(episode_id);
if (!episode) return res.status(404).json({ error: "Episode not found" });
if (!episode) return res.status(404).json({ error: 'Episode not found' });
// Create a new EpisodeSeen record
const newEpisodeSeen = await EpisodeSeen.create({
@@ -51,6 +51,16 @@ class EpisodeSeenController {
date_seen,
seen_with,
});
// Auto-upgrade: plan_to_watch or null → watching when first episode is marked
if (
entry.is_tvseries &&
(!entry.watch_status || entry.watch_status === 'plan_to_watch')
) {
entry.watch_status = 'watching';
await entry.save();
}
res.status(201).json(newEpisodeSeen);
} catch (error) {
res.status(400).json({ error: error.message });
@@ -63,7 +73,7 @@ class EpisodeSeenController {
const { episodeId } = req.params;
const episodeSeens = await EpisodeSeen.findAll({
where: { episode_id: episodeId },
order: [["date_seen", "DESC"]],
order: [['date_seen', 'DESC']],
});
if (episodeSeens.length > 0) {
@@ -71,7 +81,7 @@ class EpisodeSeenController {
} else {
res
.status(404)
.json({ message: "No records found for the given episode ID." });
.json({ message: 'No records found for the given episode ID.' });
}
} catch (error) {
res.status(500).json({ error: error.message });
@@ -89,17 +99,17 @@ class EpisodeSeenController {
include: [
{
model: Season,
attributes: ["season_number"],
attributes: ['season_number'],
},
],
attributes: ["episode_number"],
attributes: ['episode_number'],
},
],
order: [
["date_seen", "DESC"],
[{ model: Episode }, { model: Season }, "season_number", "DESC"],
['date_seen', 'DESC'],
[{ model: Episode }, { model: Season }, 'season_number', 'DESC'],
// [Sequelize.literal('"Episode->Season"."season_number"'), 'DESC'], // ! or this
[Episode, "episode_number", "DESC"],
[Episode, 'episode_number', 'DESC'],
],
});
@@ -118,14 +128,14 @@ class EpisodeSeenController {
if (!episodeSeen)
return res
.status(404)
.json({ message: "Episode seen record not found." });
.json({ message: 'Episode seen record not found.' });
const updated = await episodeSeen.update({ date_seen, seen_with });
if (updated) {
res.status(200).json(updated);
} else {
res.status(404).json({ message: "Episode seen record not found." });
res.status(404).json({ message: 'Episode seen record not found.' });
}
} catch (error) {
res.status(500).json({ error: error.message });
@@ -137,7 +147,7 @@ class EpisodeSeenController {
// ? getting the episode seen object
const oldEpisodeSeen = await EpisodeSeen.findByPk(req.params.id);
if (!oldEpisodeSeen)
res.status(404).json({ message: "Episode seen record not found." });
res.status(404).json({ message: 'Episode seen record not found.' });
// ?deleting the episode seen
const deleted = await oldEpisodeSeen.destroy();