const Collection = require("../models/Collection"); const Entry = require("../models/Entry"); const EntryId = require("../models/EntryId"); const EntryRating = require("../models/EntryRating"); const Genre = require("../models/Genre"); const Media = require("../models/Media"); const Network = require("../models/Network"); const Season = require("../models/Season"); class NetworkService { constructor() { if (!NetworkService.instance) { NetworkService.instance = this; } return NetworkService.instance; } async getNetworks() { const networks = await Network.findAll({ include: [ { model: Entry, as: "entries", include: { model: Media, as: "medias" }, }, ], order: [["name", "ASC"]], }); return networks; } async getNetworkById(id) { const network = await Network.findByPk(id, { include: [ { model: Entry, as: "entries", include: [ { model: EntryId, as: "entryId" }, { model: EntryRating, as: "entryRating" }, { model: Season, as: "seasons" }, { model: Media, as: "medias" }, { model: Genre, as: "genres" }, ], }, ], }); return network; } async createOrUpdateNetwork(networkData) { return await Network.findOrCreate({ where: { id: networkData.id }, defaults: { id: networkData.id, name: networkData.name, originCountry: networkData.originCountry, homepage: networkData.homepage, logoPath: networkData.logoPath, posterPath: networkData.posterPath, backdropPath: networkData.backdropPath, }, }); } } module.exports = new NetworkService();