random changes
This commit is contained in:
1 parent
5008940c59
commit
d06a21097f
7 files changed
+27
-61
No files matched your search
@@ -46,7 +46,7 @@ Entry.belongsToMany(UserCollection, {
|
||||
foreignKey: 'entry_id',
|
||||
otherKey: 'user_collection_id',
|
||||
onDelete: 'CASCADE',
|
||||
as: 'userCollections',
|
||||
as: 'collections',
|
||||
});
|
||||
|
||||
UserCollection.belongsToMany(Entry, {
|
||||
@@ -86,8 +86,8 @@ EntryGenre.belongsTo(Genre, { foreignKey: 'genre_id', as: 'genre' });
|
||||
|
||||
|
||||
// * ENTRY & MEDIA - ONE TO MANY
|
||||
Entry.hasMany(Media, { foreignKey: 'entry_id', as: 'medias', onDelete: 'CASCADE', });
|
||||
Media.belongsTo(Entry, { foreignKey: 'entry_id', as: 'entry' });
|
||||
Entry.hasMany(Media, { foreignKey: 'entryId', as: 'medias', onDelete: 'CASCADE', });
|
||||
Media.belongsTo(Entry, { foreignKey: 'entryId', as: 'entry' });
|
||||
|
||||
// * ENTRY & SEASON - ONE TO MANY
|
||||
Entry.hasMany(Season, { foreignKey: 'entry_id', as: 'seasons', onDelete: 'CASCADE', });
|
||||
|
||||
@@ -81,7 +81,6 @@ UserCollectionEntry.afterDestroy(async (instance, options) => {
|
||||
name: sequelize.literal('name')
|
||||
}
|
||||
|
||||
// ? updating collection poster
|
||||
const collectionsEntries = await UserCollectionEntry.findAll({
|
||||
where: {
|
||||
user_collection_id: instance.user_collection_id
|
||||
@@ -91,14 +90,15 @@ 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 {
|
||||
// todo add is customPoster field
|
||||
if (userCollection.poster_path == entry.poster_path) {
|
||||
updates.poster_path = collectionsEntries[0].entry.poster_path;
|
||||
}
|
||||
// ? 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
|
||||
|
||||
Reference in new issue
Block a user