add networks + random changes
This commit is contained in:
1 parent
bb36b2bd44
commit
5dc5a023b8
26 files changed
+1399
-1975
No files matched your search
+30
-12
@@ -12,6 +12,8 @@ const EpisodeSeen = require('../models/EpisodeSeen');
|
||||
const Genre = require('../models/Genre');
|
||||
const EntryGenre = require('../models/EntryGenre');
|
||||
const Media = require('../models/Media');
|
||||
const Network = require('../models/Network');
|
||||
const EntryNetwork = require('../models/EntryNetwork');
|
||||
|
||||
|
||||
// ? one to one
|
||||
@@ -84,39 +86,55 @@ EntryGenre.belongsTo(Entry, { foreignKey: 'entry_id', as: 'entry' });
|
||||
Genre.hasMany(EntryGenre, { foreignKey: 'genre_id', as: 'entryGenres' });
|
||||
EntryGenre.belongsTo(Genre, { foreignKey: 'genre_id', as: 'genre' });
|
||||
|
||||
// * ENTRY & NETWORK - MANY TO MANY
|
||||
Entry.belongsToMany(Network, {
|
||||
through: EntryNetwork,
|
||||
foreignKey: 'entry_id',
|
||||
otherKey: 'network_id',
|
||||
onDelete: 'CASCADE',
|
||||
as: 'networks',
|
||||
});
|
||||
|
||||
Network.belongsToMany(Entry, {
|
||||
through: EntryNetwork,
|
||||
foreignKey: 'network_id',
|
||||
otherKey: 'entry_id',
|
||||
onDelete: 'CASCADE',
|
||||
as: 'entries',
|
||||
});
|
||||
|
||||
// * ENTRY & MEDIA - ONE TO MANY
|
||||
// Entry.hasMany(Media, { foreignKey: 'entryId', as: 'medias', onDelete: 'CASCADE', });
|
||||
// Media.belongsTo(Entry, { foreignKey: 'entryId', as: 'entry' });
|
||||
|
||||
Media.belongsTo(Entry, {
|
||||
foreignKey: 'mediaableId',
|
||||
as: 'entry',
|
||||
Media.belongsTo(Entry, {
|
||||
foreignKey: 'mediaableId',
|
||||
as: 'entry',
|
||||
constraints: false,
|
||||
where: {
|
||||
mediaable: 'entry'
|
||||
}
|
||||
});
|
||||
|
||||
Media.belongsTo(Collection, {
|
||||
foreignKey: 'mediaableId',
|
||||
as: 'collection',
|
||||
Media.belongsTo(Collection, {
|
||||
foreignKey: 'mediaableId',
|
||||
as: 'collection',
|
||||
constraints: false,
|
||||
where: {
|
||||
mediaable: 'collection'
|
||||
}
|
||||
});
|
||||
|
||||
Entry.hasMany(Media, {
|
||||
foreignKey: 'mediaableId',
|
||||
constraints: false,
|
||||
Entry.hasMany(Media, {
|
||||
foreignKey: 'mediaableId',
|
||||
constraints: false,
|
||||
as: 'medias',
|
||||
scope: { mediaable: 'entry' }
|
||||
});
|
||||
|
||||
Collection.hasMany(Media, {
|
||||
foreignKey: 'mediaableId',
|
||||
constraints: false,
|
||||
Collection.hasMany(Media, {
|
||||
foreignKey: 'mediaableId',
|
||||
constraints: false,
|
||||
as: 'medias',
|
||||
scope: { mediaable: 'collection' }
|
||||
});
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
const CustomError = require('../errors/CustomError');
|
||||
const { logToFile } = require('../services/logService');
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
const { DataTypes } = require('sequelize');
|
||||
const sequelize = require('../config/database');
|
||||
|
||||
const EntryNetwork = sequelize.define('entryNetwork',
|
||||
{
|
||||
network_id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
references: {
|
||||
model: 'Networks',
|
||||
key: 'id'
|
||||
}
|
||||
},
|
||||
entry_id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
references: {
|
||||
model: 'Entries',
|
||||
key: 'id'
|
||||
}
|
||||
},
|
||||
order: {
|
||||
type: DataTypes.INTEGER
|
||||
}
|
||||
},
|
||||
{
|
||||
primaryKey: ['network_id', 'entry_id'],
|
||||
}
|
||||
);
|
||||
|
||||
module.exports = EntryNetwork;
|
||||
@@ -0,0 +1,18 @@
|
||||
const { DataTypes } = require('sequelize');
|
||||
const sequelize = require('../config/database');
|
||||
|
||||
const Network = sequelize.define("network",
|
||||
{
|
||||
id: { type: DataTypes.INTEGER, primaryKey: true },
|
||||
|
||||
name: { type: DataTypes.STRING(30) },
|
||||
originCountry: { type: DataTypes.STRING(100), field: 'origin_country' },
|
||||
homepage: { type: DataTypes.STRING(100), field: 'homepage' },
|
||||
|
||||
logoPath: { type: DataTypes.STRING(200), field: 'logo_path' },
|
||||
posterPath: { type: DataTypes.STRING(200), field: 'poster_path' },
|
||||
backdropPath: { type: DataTypes.STRING(200), field: 'backdrop_path' },
|
||||
}
|
||||
);
|
||||
|
||||
module.exports = Network;
|
||||
@@ -546,8 +546,8 @@ async function refrechEntry(entryId) {
|
||||
|
||||
// ? fetch collection
|
||||
if (entryData.belongs_to_collection) {
|
||||
const collectionService = require('./collectionService.js');
|
||||
await collectionService.upsertOfficialCollection(entryData.belongs_to_collection.id);
|
||||
const collectionService = require('../collectionService.js');
|
||||
await collectionService.createOrUpdateCollection(entryData.belongs_to_collection.id);
|
||||
}
|
||||
|
||||
// + end of: refrech logic
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
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();
|
||||
Reference in new issue
Block a user