const Entry = require("../models/Entry"); const Collection = require("../models/Collection"); const { Op } = require("sequelize"); class HomepageIntegrationController { constructor() { if (!HomepageIntegrationController.instance) { HomepageIntegrationController.instance = this; } return HomepageIntegrationController.instance; } async getStats(req, res) { try { const notSeries = { is_tvseries: { [Op.or]: [false, null] } }; const isSeries = { is_tvseries: true }; const [ totalEntries, library, libraryMovies, librarySeries, watchlist, watchlistMovies, watchlistSeries, collections, favorits, ] = await Promise.all([ Entry.count(), Entry.count({ where: { watchlist: { [Op.or]: [false, null] } } }), Entry.count({ where: { watchlist: { [Op.or]: [false, null] }, ...notSeries }, }), Entry.count({ where: { watchlist: { [Op.or]: [false, null] }, ...isSeries }, }), Entry.count({ where: { watchlist: true } }), Entry.count({ where: { watchlist: true, ...notSeries } }), Entry.count({ where: { watchlist: true, ...isSeries } }), Collection.count(), Entry.count({ where: { favorit: true } }), ]); return res.status(200).json({ totalEntries, library, libraryMovies, librarySeries, watchlist, watchlistMovies, watchlistSeries, collections, favorits, }); } catch (error) { console.error("Homepage integration error:", error); return res.status(500).json({ error: "Failed to fetch library stats" }); } } } module.exports = new HomepageIntegrationController();