Major rework of media handelling, and collections

This commit is contained in:
X4Lo committed 2024-09-13 21:27:01 +01:00
1 parent b42e055691
commit f7cb2bed53
37 files changed
+1120 -411

No files matched your search

+30 -6
View File
@@ -89,13 +89,37 @@ EntryGenre.belongsTo(Genre, { foreignKey: 'genre_id', as: 'genre' });
// Entry.hasMany(Media, { foreignKey: 'entryId', as: 'medias', onDelete: 'CASCADE', });
// Media.belongsTo(Entry, { foreignKey: 'entryId', as: 'entry' });
// * ENTRY & MEDIA - ONE TO MANY
Media.belongsTo(Entry, { foreignKey: 'mediaableId', as: 'entry', constraints: false, scope: { mediaable: 'entry' } });
Media.belongsTo(Collection, { foreignKey: 'mediaableId', as: 'collection', constraints: false, scope: { mediaable: 'collection' } });
Media.belongsTo(Entry, {
foreignKey: 'mediaableId',
as: 'entry',
constraints: false,
where: {
mediaable: 'entry'
}
});
// * ENTRY & COLLECTION - ONE TO MANY
Entry.hasMany(Media, { foreignKey: 'mediaableId', constraints: false, as: 'medias', scope: { mediaable: 'entry' } });
Collection.hasMany(Media, { foreignKey: 'mediaableId', constraints: false, as: 'medias', scope: { mediaable: 'collection' } });
Media.belongsTo(Collection, {
foreignKey: 'mediaableId',
as: 'collection',
constraints: false,
where: {
mediaable: 'collection'
}
});
Entry.hasMany(Media, {
foreignKey: 'mediaableId',
constraints: false,
as: 'medias',
scope: { mediaable: 'entry' }
});
Collection.hasMany(Media, {
foreignKey: 'mediaableId',
constraints: false,
as: 'medias',
scope: { mediaable: 'collection' }
});
// * ENTRY & SEASON - ONE TO MANY
Entry.hasMany(Season, { foreignKey: 'entry_id', as: 'seasons', onDelete: 'CASCADE', });
+9 -9
View File
@@ -4,7 +4,7 @@ const Entry = require('../models/Entry')
const EntryId = require('../models/EntryId')
const EntryRating = require('../models/EntryRating')
const EntrySeen = require('../models/EntrySeen');
const UserCollection = require('../models/UserCollection');
const UserCollection = require('../models/Collection');
const UserCollectionEntry = require('../models/UserCollectionEntry');
const Season = require('../models/Season');
const Episode = require('../models/Episode');
@@ -92,14 +92,14 @@ UserCollectionEntry.afterDestroy(async (instance, options) => {
// ? updating collection poster
// ? remove the poster if the collection is empty now
if (collectionsEntries.length == 0) {
updates.poster = null;
} else {
// ? replace poster it belonged to the removed entry
// if (userCollection.poster_path == entry.poster_path) {
// updates.poster_path = collectionsEntries[0].entry.poster_path;
// }
}
// if (collectionsEntries.length == 0) {
// updates.poster = null;
// } else {
// // ? replace poster it belonged to the removed entry
// // if (userCollection.poster_path == entry.poster_path) {
// // updates.poster_path = collectionsEntries[0].entry.poster_path;
// // }
// }
// ? updating order, only if the removed entry isn't placed at the end
let order = instance.order;