From dde494a11e1728ea21cd4d5d782c1bb61c014c6b Mon Sep 17 00:00:00 2001 From: Mohammed Abad Date: Sat, 11 May 2024 06:25:52 +0100 Subject: [PATCH] fixed entry genres not showing up after updating favorit/hidden status --- backend/routes/entryRoutes.js | 32 +++++++++++-------- .../entry/entry-page/entry-page.component.ts | 16 ++++++---- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/backend/routes/entryRoutes.js b/backend/routes/entryRoutes.js index 1395665..f0eb2b3 100644 --- a/backend/routes/entryRoutes.js +++ b/backend/routes/entryRoutes.js @@ -91,7 +91,7 @@ entryRouter.post('/', async (req, res) => { res.status(201).json(entry); }); -// * POST - BULK IMPORT MOVIES +// ! import routes entryRouter.post('/bulk-import-movies', async (req, res) => { const { movies } = req.body; @@ -131,8 +131,7 @@ entryRouter.post('/bulk-import-episodes-seen', async (req, res) => { res.status(201).json(createdRows); }); - - +// + import routes end // * PUT - ENTRY UPDATE entryRouter.put('/:id', async (req, res) => { const { id } = req.params; @@ -159,7 +158,7 @@ entryRouter.put('/:id', async (req, res) => { { model: Genre, as: 'genres', - attributes: ['id'], + attributes: ['name'], through: { attributes: [] } @@ -168,22 +167,30 @@ entryRouter.put('/:id', async (req, res) => { if (oldEntry.is_tvseries) includes.push({ model: Season, as: 'seasons' }); - const entry = await Entry.findByPk(id, { + const updatedEntry = await Entry.findByPk(id, { include: includes }); - res.status(201).json(entry); + const entryData = updatedEntry.get({ plain: true }); + const genres = entryData.genres.map(genre => genre.name); + + entryData.genres = genres; + + res.status(201).json(entryData); }); -// * GET - REQUEST ENTRY UPDATE +// * GET - REQUEST ENTRY REFRECH entryRouter.get('/:id/refrech', async (req, res) => { const { id } = req.params; // ? checking if the provied id is valid + // ! note: the includes are required for the update const oldEntry = await Entry.findByPk(id, { include: [ { model: EntryId, as: 'entryId' }, { model: EntryRating, as: 'entryRating' }, + { model: EntrySeen, as: 'entrySeen' }, + { model: Season, as: 'seasons' }, { model: Genre, as: 'genres', @@ -198,7 +205,6 @@ entryRouter.get('/:id/refrech', async (req, res) => { if (!oldEntry) return res.status(404).json({ message: `Entry id not found` }); - // ? getting new data from TMDB const data = await fetchEntryData(oldEntry.entryId.tmdb_id, oldEntry.is_tvseries); if (data == null) return res.status(500).json({ message: `Counldn't fetch data from TMDB` }); @@ -211,6 +217,7 @@ entryRouter.get('/:id/refrech', async (req, res) => { { model: EntryId, as: 'entryId' }, { model: EntryRating, as: 'entryRating' }, { model: EntrySeen, as: 'entrySeen' }, + { model: Season, as: 'seasons' }, { model: Genre, as: 'genres', @@ -220,17 +227,14 @@ entryRouter.get('/:id/refrech', async (req, res) => { } } ]; - if (oldEntry.is_tvseries) includes.push({ model: Season, as: 'seasons' }); - const entry = await Entry.findByPk(id, { + const updatedEntry = await Entry.findByPk(id, { include: includes }); - const entryData = entry.get({ plain: true }); - const genres = entryData.genres.map(genre => genre.name); - - entryData.genres = genres; + const entryData = updatedEntry.get({ plain: true }); + entryData.genres = entryData.genres.map(genre => genre.name); res.status(201).json(entryData); }); diff --git a/frontend/src/app/features/entry/entry-page/entry-page.component.ts b/frontend/src/app/features/entry/entry-page/entry-page.component.ts index 24df3b8..fe92c06 100644 --- a/frontend/src/app/features/entry/entry-page/entry-page.component.ts +++ b/frontend/src/app/features/entry/entry-page/entry-page.component.ts @@ -70,6 +70,7 @@ export class EntryPageComponent implements OnInit { this.route.data.subscribe( (data) => { this.entry = data['entry'] as Entry; + // console.log(this.entry); if (this.entry.is_tvseries) { // ? sorting seasons @@ -90,7 +91,7 @@ export class EntryPageComponent implements OnInit { season.episodes = episodes; }, error: (error) => { - console.log(`Couldn't fetch season episodes data:`, error); + // console.log(`Couldn't fetch season episodes data:`, error); this.toastr.success( 'Error', `Couldn't get season ${season.season_number} episodes.`, @@ -163,7 +164,7 @@ export class EntryPageComponent implements OnInit { // TODO show notification } else { - console.log('Seen dialog was cancelled'); + // console.log('Seen dialog was cancelled'); } }); } @@ -251,7 +252,7 @@ export class EntryPageComponent implements OnInit { }, complete: () => { this.lockActions = false; - } + }, }); } @@ -266,7 +267,8 @@ export class EntryPageComponent implements OnInit { }); dialogRef.afterClosed().subscribe((result) => { - console.log('Modal Closed: ', result); + // TODO update entry page collections + // console.log('Modal Closed: ', result); }); } } @@ -368,7 +370,8 @@ export class EntryPageComponent implements OnInit { // console.log('Episode seen dialog closed with:', result); if (result.watchDate == '') { // TODO show no date was passed notification - return console.log(`Episode seen dialog closed with no date.`); + console.log(`Episode seen dialog closed with no date.`); + return; } episodeSeen.date_seen = result.watchDate; @@ -402,7 +405,6 @@ export class EntryPageComponent implements OnInit { dialogRef.afterClosed().subscribe((result) => { if (result) { - console.log(result); if (result.confirmed != true) return; // first start by calling the service and deleting the episode-seen @@ -442,7 +444,7 @@ export class EntryPageComponent implements OnInit { } triggerEpisodeWatchedDeletedEvent() { - console.log(`Emitted Episode Watched Deleted Event`); + // console.log(`Emitted Episode Watched Deleted Event`); } // + end EPISODE SEEN