Add watch status for TV series with UI and auto-fix
Added watch_status column to Entry model (plan_to_watch/watching/completed/ on_hold/dropped). Status pill on entry details page opens selection dialog. Set Status in quick actions menu and EntryCard dropdown (TV only). Status filter in Library filter popover. Maintenance auto-fix endpoint that sets statuses based on watched episodes (excl. season 0).
This commit is contained in:
1 parent
a5659cf4c8
commit
cdbaedd7d0
11 files changed
+663
-286
No files matched your search
@@ -1,9 +1,9 @@
|
||||
const EntryRating = require("../models/EntryRating");
|
||||
const collectionManager = require("../services/collectionManager");
|
||||
const entryManager = require("../services/entryManager");
|
||||
const entryService = require("../services/entryService");
|
||||
const tmdbService = require("../services/tmdbService");
|
||||
const asyncWrapper = require("../utils/asyncWrapper");
|
||||
const EntryRating = require('../models/EntryRating');
|
||||
const collectionManager = require('../services/collectionManager');
|
||||
const entryManager = require('../services/entryManager');
|
||||
const entryService = require('../services/entryService');
|
||||
const tmdbService = require('../services/tmdbService');
|
||||
const asyncWrapper = require('../utils/asyncWrapper');
|
||||
|
||||
const _collectionManager = collectionManager;
|
||||
const _entryManager = entryManager;
|
||||
@@ -105,7 +105,7 @@ class EntryController {
|
||||
const seasons = await _entryService.getEntrySeasons(id);
|
||||
|
||||
if (seasons.length == 0) {
|
||||
res.status(204).json({ message: "Provided entry has no seasons" });
|
||||
return res.status(204).json({ message: 'Provided entry has no seasons' });
|
||||
}
|
||||
|
||||
res.status(200).json(seasons);
|
||||
@@ -145,7 +145,7 @@ class EntryController {
|
||||
const { page } = req.query;
|
||||
const data = await tmdbService.fetchTrending(type, page || 1);
|
||||
if (!data)
|
||||
return res.status(500).json({ message: "Failed to fetch trending data" });
|
||||
return res.status(500).json({ message: 'Failed to fetch trending data' });
|
||||
res.status(200).json(data);
|
||||
});
|
||||
|
||||
@@ -155,7 +155,7 @@ class EntryController {
|
||||
const { page } = req.query;
|
||||
const data = await tmdbService.fetchPopular(type, page || 1);
|
||||
if (!data)
|
||||
return res.status(500).json({ message: "Failed to fetch popular data" });
|
||||
return res.status(500).json({ message: 'Failed to fetch popular data' });
|
||||
res.status(200).json(data);
|
||||
});
|
||||
|
||||
@@ -163,10 +163,10 @@ class EntryController {
|
||||
getTmdbSearch = asyncWrapper(async (req, res) => {
|
||||
const { query, page } = req.query;
|
||||
if (!query)
|
||||
return res.status(400).json({ message: "Query parameter is required" });
|
||||
return res.status(400).json({ message: 'Query parameter is required' });
|
||||
const data = await tmdbService.searchMulti(query, page || 1);
|
||||
if (!data)
|
||||
return res.status(500).json({ message: "Failed to search TMDB" });
|
||||
return res.status(500).json({ message: 'Failed to search TMDB' });
|
||||
res.status(200).json(data);
|
||||
});
|
||||
|
||||
@@ -178,7 +178,7 @@ class EntryController {
|
||||
if (!data)
|
||||
return res
|
||||
.status(500)
|
||||
.json({ message: "Failed to fetch top rated data" });
|
||||
.json({ message: 'Failed to fetch top rated data' });
|
||||
res.status(200).json(data);
|
||||
});
|
||||
|
||||
@@ -187,17 +187,17 @@ class EntryController {
|
||||
const { page } = req.query;
|
||||
const data = await tmdbService.fetchUpcoming(page || 1);
|
||||
if (!data)
|
||||
return res.status(500).json({ message: "Failed to fetch upcoming data" });
|
||||
return res.status(500).json({ message: 'Failed to fetch upcoming data' });
|
||||
res.status(200).json(data);
|
||||
});
|
||||
|
||||
// * GET - TMDB PREVIEW (fetch details without saving to library)
|
||||
getTmdbPreview = asyncWrapper(async (req, res) => {
|
||||
const { type, tmdbId } = req.params;
|
||||
const is_tvserie = type === "tv";
|
||||
const is_tvserie = type === 'tv';
|
||||
const data = await tmdbService.fetchEntryData(tmdbId, is_tvserie);
|
||||
if (!data)
|
||||
return res.status(404).json({ message: "Entry not found on TMDB" });
|
||||
return res.status(404).json({ message: 'Entry not found on TMDB' });
|
||||
|
||||
// Fetch credits in parallel
|
||||
const creditsData = await tmdbService.fetchEntryCredits(tmdbId, is_tvserie);
|
||||
@@ -208,7 +208,7 @@ class EntryController {
|
||||
for (const c of creditsData.cast) {
|
||||
credits.push({
|
||||
id: c.credit_id || c.id,
|
||||
cast_type: "cast",
|
||||
cast_type: 'cast',
|
||||
character: is_tvserie
|
||||
? c.roles?.[0]?.character || c.character || null
|
||||
: c.character || null,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const maintenanceService = require("../services/maintenanceService");
|
||||
const maintenanceService = require('../services/maintenanceService');
|
||||
|
||||
const _maintenanceService = maintenanceService;
|
||||
|
||||
@@ -63,6 +63,11 @@ class MaintenanceController {
|
||||
const result = await _maintenanceService.cleanDuplicateCredits();
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
|
||||
async autoFixWatchStatuses(req, res) {
|
||||
const result = await _maintenanceService.autoFixWatchStatuses();
|
||||
return res.status(200).json(result);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new MaintenanceController();
|
||||
+24
-18
@@ -1,13 +1,13 @@
|
||||
const { DataTypes } = require("sequelize");
|
||||
const sequelize = require("../config/database");
|
||||
const { DataTypes } = require('sequelize');
|
||||
const sequelize = require('../config/database');
|
||||
|
||||
const Entry = sequelize.define("entry", {
|
||||
const Entry = sequelize.define('entry', {
|
||||
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
|
||||
|
||||
title: { type: DataTypes.STRING(500) },
|
||||
original_title: { type: DataTypes.STRING(100), field: "original_title" },
|
||||
release_date: { type: DataTypes.DATE, field: "release_date" },
|
||||
release_status: { type: DataTypes.STRING(50), field: "release_status" },
|
||||
original_title: { type: DataTypes.STRING(100), field: 'original_title' },
|
||||
release_date: { type: DataTypes.DATE, field: 'release_date' },
|
||||
release_status: { type: DataTypes.STRING(50), field: 'release_status' },
|
||||
runtime: { type: DataTypes.INTEGER },
|
||||
|
||||
tagline: { type: DataTypes.STRING(200) },
|
||||
@@ -15,13 +15,13 @@ const Entry = sequelize.define("entry", {
|
||||
country: { type: DataTypes.STRING(30) },
|
||||
|
||||
certification: { type: DataTypes.INTEGER },
|
||||
network_studio: { type: DataTypes.STRING(40), field: "network_studio" },
|
||||
collection_id: { type: DataTypes.INTEGER, field: "collection_id" },
|
||||
max_cast: { type: DataTypes.INTEGER, field: "max_cast", defaultValue: 10 },
|
||||
network_studio: { type: DataTypes.STRING(40), field: 'network_studio' },
|
||||
collection_id: { type: DataTypes.INTEGER, field: 'collection_id' },
|
||||
max_cast: { type: DataTypes.INTEGER, field: 'max_cast', defaultValue: 10 },
|
||||
credit_fetched: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: false,
|
||||
field: "credit_fetched",
|
||||
field: 'credit_fetched',
|
||||
},
|
||||
|
||||
watchlist: { type: DataTypes.BOOLEAN, defaultValue: false },
|
||||
@@ -30,29 +30,35 @@ const Entry = sequelize.define("entry", {
|
||||
showInCalendar: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: true,
|
||||
field: "show_in_calendar",
|
||||
field: 'show_in_calendar',
|
||||
},
|
||||
autoSync: { type: DataTypes.BOOLEAN, defaultValue: true, field: "auto_sync" },
|
||||
autoSync: { type: DataTypes.BOOLEAN, defaultValue: true, field: 'auto_sync' },
|
||||
|
||||
note: { type: DataTypes.STRING(2000) },
|
||||
|
||||
is_tvseries: { type: DataTypes.BOOLEAN, field: "is_tvseries" },
|
||||
is_tvseries: { type: DataTypes.BOOLEAN, field: 'is_tvseries' },
|
||||
status: { type: DataTypes.STRING(20) },
|
||||
|
||||
poster_path: { type: DataTypes.STRING(200), field: "poster_path" },
|
||||
banner_path: { type: DataTypes.STRING(200), field: "banner_path" },
|
||||
poster_path: { type: DataTypes.STRING(200), field: 'poster_path' },
|
||||
banner_path: { type: DataTypes.STRING(200), field: 'banner_path' },
|
||||
|
||||
date_first_seen: { type: DataTypes.DATEONLY, field: "date_first_seen" },
|
||||
date_last_seen: { type: DataTypes.DATEONLY, field: "date_last_seen" },
|
||||
date_first_seen: { type: DataTypes.DATEONLY, field: 'date_first_seen' },
|
||||
date_last_seen: { type: DataTypes.DATEONLY, field: 'date_last_seen' },
|
||||
|
||||
last_fetch: { type: DataTypes.DATEONLY },
|
||||
|
||||
entry_sync_status: {
|
||||
type: DataTypes.STRING(50),
|
||||
field: "entry_sync_status",
|
||||
field: 'entry_sync_status',
|
||||
allowNull: true,
|
||||
},
|
||||
director: { type: DataTypes.STRING(200), allowNull: true },
|
||||
watch_status: {
|
||||
type: DataTypes.STRING(20),
|
||||
field: 'watch_status',
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = Entry;
|
||||
@@ -1,61 +1,67 @@
|
||||
const express = require("express");
|
||||
const express = require('express');
|
||||
const maintenanceRouter = express.Router();
|
||||
|
||||
const maintenanceController = require("../controllers/maintenanceController");
|
||||
const maintenanceController = require('../controllers/maintenanceController');
|
||||
|
||||
// ! /maintenance
|
||||
// * GET - Orphan files
|
||||
maintenanceRouter.get("/orphan-files", maintenanceController.getOrpanFiles);
|
||||
maintenanceRouter.get('/orphan-files', maintenanceController.getOrpanFiles);
|
||||
|
||||
// * GET - Missing files
|
||||
maintenanceRouter.get(
|
||||
"/orphan-media-records",
|
||||
'/orphan-media-records',
|
||||
maintenanceController.getOrphanMediaRecords,
|
||||
);
|
||||
|
||||
// * DELETE - Orphan files
|
||||
maintenanceRouter.delete(
|
||||
"/orphan-files",
|
||||
'/orphan-files',
|
||||
maintenanceController.deleteOrpanFiles,
|
||||
);
|
||||
|
||||
// * DELETE - Missing files
|
||||
maintenanceRouter.delete(
|
||||
"/orphan-media-records",
|
||||
'/orphan-media-records',
|
||||
maintenanceController.deleteOrphanMediaRecords,
|
||||
);
|
||||
|
||||
// * GET - Orphan people (dry run)
|
||||
maintenanceRouter.get("/orphan-people", maintenanceController.getOrphanPeople);
|
||||
maintenanceRouter.get('/orphan-people', maintenanceController.getOrphanPeople);
|
||||
|
||||
// * DELETE - Orphan people
|
||||
maintenanceRouter.delete(
|
||||
"/orphan-people",
|
||||
'/orphan-people',
|
||||
maintenanceController.deleteOrphanPeople,
|
||||
);
|
||||
|
||||
// * GET - Missing directors count
|
||||
maintenanceRouter.get(
|
||||
"/missing-directors",
|
||||
'/missing-directors',
|
||||
maintenanceController.getMissingDirectors,
|
||||
);
|
||||
|
||||
// * POST - Fix missing directors
|
||||
maintenanceRouter.post(
|
||||
"/missing-directors",
|
||||
'/missing-directors',
|
||||
maintenanceController.fixMissingDirectors,
|
||||
);
|
||||
|
||||
// * GET - Duplicate credits count
|
||||
maintenanceRouter.get(
|
||||
"/duplicate-credits",
|
||||
'/duplicate-credits',
|
||||
maintenanceController.getDuplicateCredits,
|
||||
);
|
||||
|
||||
// * DELETE - Clean duplicate credits
|
||||
maintenanceRouter.delete(
|
||||
"/duplicate-credits",
|
||||
'/duplicate-credits',
|
||||
maintenanceController.cleanDuplicateCredits,
|
||||
);
|
||||
|
||||
// * POST - Auto-fix watch statuses based on watched episodes
|
||||
maintenanceRouter.post(
|
||||
'/auto-fix-watch-statuses',
|
||||
maintenanceController.autoFixWatchStatuses,
|
||||
);
|
||||
|
||||
module.exports = maintenanceRouter;
|
||||
@@ -1,14 +1,14 @@
|
||||
const path = require("path");
|
||||
const fsPromises = require("fs").promises;
|
||||
const fs = require("fs");
|
||||
const path = require('path');
|
||||
const fsPromises = require('fs').promises;
|
||||
const fs = require('fs');
|
||||
|
||||
const Media = require("../models/Media");
|
||||
const People = require("../models/People");
|
||||
const Credit = require("../models/Credit");
|
||||
const Entry = require("../models/Entry");
|
||||
const Media = require('../models/Media');
|
||||
const People = require('../models/People');
|
||||
const Credit = require('../models/Credit');
|
||||
const Entry = require('../models/Entry');
|
||||
|
||||
const { logToFile } = require("./logService");
|
||||
const configService = require("./configService");
|
||||
const { logToFile } = require('./logService');
|
||||
const configService = require('./configService');
|
||||
|
||||
const _configService = configService;
|
||||
|
||||
@@ -32,30 +32,30 @@ class MaintenanceService {
|
||||
const dataPath = await _configService.getMediaFolder();
|
||||
|
||||
const mediaTypeFolder = {
|
||||
"entry;poster": path.join(dataPath, "images", "entries", "posters"),
|
||||
"entry;logo": path.join(dataPath, "images", "entries", "logos"),
|
||||
"entry;backdrop": path.join(dataPath, "images", "entries", "backdrops"),
|
||||
'entry;poster': path.join(dataPath, 'images', 'entries', 'posters'),
|
||||
'entry;logo': path.join(dataPath, 'images', 'entries', 'logos'),
|
||||
'entry;backdrop': path.join(dataPath, 'images', 'entries', 'backdrops'),
|
||||
|
||||
"collection;poster": path.join(
|
||||
'collection;poster': path.join(
|
||||
dataPath,
|
||||
"images",
|
||||
"collections",
|
||||
"posters",
|
||||
'images',
|
||||
'collections',
|
||||
'posters',
|
||||
),
|
||||
"collection;backdrop": path.join(
|
||||
'collection;backdrop': path.join(
|
||||
dataPath,
|
||||
"images",
|
||||
"collections",
|
||||
"backdrops",
|
||||
'images',
|
||||
'collections',
|
||||
'backdrops',
|
||||
),
|
||||
|
||||
"season;poster": path.join(dataPath, "images", "seasons", "posters"),
|
||||
"episode;still": path.join(dataPath, "images", "episodes", "stills"),
|
||||
'season;poster': path.join(dataPath, 'images', 'seasons', 'posters'),
|
||||
'episode;still': path.join(dataPath, 'images', 'episodes', 'stills'),
|
||||
};
|
||||
|
||||
let missingFiles = [];
|
||||
for (let i = 0; i < allMedia.length; i++) {
|
||||
const folderType = `${allMedia[i].mediaable};${allMedia[i].type.replace("_preview", "")}`;
|
||||
const folderType = `${allMedia[i].mediaable};${allMedia[i].type.replace('_preview', '')}`;
|
||||
|
||||
if (!mediaTypeFolder[folderType]) continue;
|
||||
|
||||
@@ -73,7 +73,7 @@ class MaintenanceService {
|
||||
};
|
||||
|
||||
for (let i = 0; i < missingFiles.length; i++) {
|
||||
removed[missingFiles[i].type + "s"] += 1;
|
||||
removed[missingFiles[i].type + 's'] += 1;
|
||||
if (!dry) missingFiles[i].destroy();
|
||||
}
|
||||
|
||||
@@ -100,31 +100,31 @@ class MaintenanceService {
|
||||
|
||||
// ? Getting the name (without extention) of all media in database
|
||||
const allMedia = (await Media.findAll()).map((m) => {
|
||||
return m.path.split(".")[0];
|
||||
return m.path.split('.')[0];
|
||||
});
|
||||
|
||||
// ? Loop trough the files of the images folder and check
|
||||
// ? if a file doesnt exist in the allMedia array and mark it to delete
|
||||
const mediaTypeFolder = {
|
||||
"entry;poster": path.join(dataPath, "images", "entries", "posters"),
|
||||
"entry;logo": path.join(dataPath, "images", "entries", "logos"),
|
||||
"entry;backdrop": path.join(dataPath, "images", "entries", "backdrops"),
|
||||
'entry;poster': path.join(dataPath, 'images', 'entries', 'posters'),
|
||||
'entry;logo': path.join(dataPath, 'images', 'entries', 'logos'),
|
||||
'entry;backdrop': path.join(dataPath, 'images', 'entries', 'backdrops'),
|
||||
|
||||
"collection;poster": path.join(
|
||||
'collection;poster': path.join(
|
||||
dataPath,
|
||||
"images",
|
||||
"collections",
|
||||
"posters",
|
||||
'images',
|
||||
'collections',
|
||||
'posters',
|
||||
),
|
||||
"collection;backdrop": path.join(
|
||||
'collection;backdrop': path.join(
|
||||
dataPath,
|
||||
"images",
|
||||
"collections",
|
||||
"backdrops",
|
||||
'images',
|
||||
'collections',
|
||||
'backdrops',
|
||||
),
|
||||
|
||||
"season;poster": path.join(dataPath, "images", "seasons", "posters"),
|
||||
"episode;still": path.join(dataPath, "images", "episodes", "stills"),
|
||||
'season;poster': path.join(dataPath, 'images', 'seasons', 'posters'),
|
||||
'episode;still': path.join(dataPath, 'images', 'episodes', 'stills'),
|
||||
};
|
||||
|
||||
// * counter
|
||||
@@ -146,12 +146,12 @@ class MaintenanceService {
|
||||
// Check each file in the directory
|
||||
for (let file of files) {
|
||||
// preparing the file name
|
||||
const fileName = file.split(".")[0].replace("_preview", "");
|
||||
const fileName = file.split('.')[0].replace('_preview', '');
|
||||
const isInDatabase = allMedia.includes(fileName);
|
||||
|
||||
// if the file isn't in database even on other extentions then delete it
|
||||
if (!isInDatabase) {
|
||||
removed[folderType.split(";")[1] + "s"]++; // Increment the count of removed files
|
||||
removed[folderType.split(';')[1] + 's']++; // Increment the count of removed files
|
||||
if (!dry) {
|
||||
const filePath = path.join(directory, file);
|
||||
await fsPromises.unlink(filePath);
|
||||
@@ -182,14 +182,14 @@ class MaintenanceService {
|
||||
* @param {boolean} [dry=false] - if true only return the count
|
||||
*/
|
||||
async deleteOrphanPeople(dry = false) {
|
||||
const { Sequelize } = require("sequelize");
|
||||
const { Sequelize } = require('sequelize');
|
||||
|
||||
// Find all people who have no credits and are not pinned
|
||||
const allPeople = await People.findAll({
|
||||
include: [
|
||||
{
|
||||
model: Credit,
|
||||
as: "roles",
|
||||
as: 'roles',
|
||||
required: false,
|
||||
},
|
||||
],
|
||||
@@ -222,9 +222,9 @@ class MaintenanceService {
|
||||
include: [
|
||||
{
|
||||
model: Credit,
|
||||
as: "credits",
|
||||
where: { cast_type: "crew", job: "Director" },
|
||||
include: [{ model: People, as: "person", attributes: ["name"] }],
|
||||
as: 'credits',
|
||||
where: { cast_type: 'crew', job: 'Director' },
|
||||
include: [{ model: People, as: 'person', attributes: ['name'] }],
|
||||
required: false,
|
||||
},
|
||||
],
|
||||
@@ -257,20 +257,20 @@ class MaintenanceService {
|
||||
* @param {boolean} [dry=false] - if true only count, if false also delete
|
||||
*/
|
||||
async cleanDuplicateCredits(dry = false) {
|
||||
const { Sequelize } = require("sequelize");
|
||||
const { Sequelize } = require('sequelize');
|
||||
|
||||
const duplicates = await Credit.findAll({
|
||||
attributes: [
|
||||
"entry_id",
|
||||
"people_id",
|
||||
"cast_type",
|
||||
"character",
|
||||
"job",
|
||||
[Sequelize.fn("COUNT", Sequelize.col("id")), "cnt"],
|
||||
[Sequelize.fn("GROUP_CONCAT", Sequelize.col("id")), "ids"],
|
||||
'entry_id',
|
||||
'people_id',
|
||||
'cast_type',
|
||||
'character',
|
||||
'job',
|
||||
[Sequelize.fn('COUNT', Sequelize.col('id')), 'cnt'],
|
||||
[Sequelize.fn('GROUP_CONCAT', Sequelize.col('id')), 'ids'],
|
||||
],
|
||||
group: ["entry_id", "people_id", "cast_type", "character", "job"],
|
||||
having: Sequelize.literal("COUNT(id) > 1"),
|
||||
group: ['entry_id', 'people_id', 'cast_type', 'character', 'job'],
|
||||
having: Sequelize.literal('COUNT(id) > 1'),
|
||||
raw: true,
|
||||
});
|
||||
|
||||
@@ -280,7 +280,7 @@ class MaintenanceService {
|
||||
if (!dry) {
|
||||
for (const row of duplicates) {
|
||||
const idList = row.ids
|
||||
.split(",")
|
||||
.split(',')
|
||||
.map(Number)
|
||||
.sort((a, b) => a - b);
|
||||
// Keep the newest (highest ID), delete the older ones
|
||||
@@ -310,6 +310,92 @@ class MaintenanceService {
|
||||
deleted: deletedCount,
|
||||
};
|
||||
}
|
||||
|
||||
async autoFixWatchStatuses() {
|
||||
const Episode = require('../models/Episode');
|
||||
const EpisodeSeen = require('../models/EpisodeSeen');
|
||||
const Season = require('../models/Season');
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const tvEntries = await Entry.findAll({
|
||||
where: { is_tvseries: true },
|
||||
include: [
|
||||
{
|
||||
model: Season,
|
||||
as: 'seasons',
|
||||
where: { season_number: { [Op.gt]: 0 } },
|
||||
include: [
|
||||
{
|
||||
model: Episode,
|
||||
as: 'episodes',
|
||||
include: [{ model: EpisodeSeen, as: 'episodeSeens' }],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
let toCompleted = 0;
|
||||
let toWatching = 0;
|
||||
let toPlanToWatch = 0;
|
||||
|
||||
for (const entry of tvEntries) {
|
||||
let totalEpisodes = 0;
|
||||
let watchedEpisodes = 0;
|
||||
|
||||
for (const season of entry.seasons || []) {
|
||||
for (const ep of season.episodes || []) {
|
||||
totalEpisodes++;
|
||||
if (ep.episodeSeens && ep.episodeSeens.length > 0) {
|
||||
watchedEpisodes++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const allWatched = totalEpisodes > 0 && watchedEpisodes === totalEpisodes;
|
||||
const hasSomeWatched = watchedEpisodes > 0;
|
||||
|
||||
// Completed but not all watched → downgrade to watching
|
||||
if (entry.watch_status === 'completed' && !allWatched) {
|
||||
entry.watch_status = 'watching';
|
||||
await entry.save();
|
||||
toWatching++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// All watched → completed (unless already completed)
|
||||
if (allWatched && entry.watch_status !== 'completed') {
|
||||
entry.watch_status = 'completed';
|
||||
await entry.save();
|
||||
toCompleted++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Has some watched but no status → watching
|
||||
if (hasSomeWatched && !entry.watch_status) {
|
||||
entry.watch_status = 'watching';
|
||||
await entry.save();
|
||||
toWatching++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// In watchlist with no status → plan to watch
|
||||
if (entry.watchlist && !entry.watch_status) {
|
||||
entry.watch_status = 'plan_to_watch';
|
||||
await entry.save();
|
||||
toPlanToWatch++;
|
||||
}
|
||||
}
|
||||
|
||||
logToFile(
|
||||
`Auto-fixed watch statuses: ${toCompleted} completed, ${toWatching} watching, ${toPlanToWatch} plan_to_watch`,
|
||||
);
|
||||
return {
|
||||
completed: toCompleted,
|
||||
watching: toWatching,
|
||||
planToWatch: toPlanToWatch,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new MaintenanceService();
|
||||
Reference in new issue
Block a user