fixed entry genres not showing up after updating favorit/hidden status
This commit is contained in:
1 parent
5807652843
commit
dde494a11e
2 files changed
+27
-21
No files matched your search
@@ -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);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user