Front/Back: add entry settings modal
This commit is contained in:
1 parent
8724a96b81
commit
625ec3367e
15 files changed
+334
-57
No files matched your search
@@ -1,12 +1,11 @@
|
||||
const express = require('express');
|
||||
const entryRouter = express.Router();
|
||||
const path = require('path');
|
||||
|
||||
const { fetchEntryData, fetchCollectionData } = require('../services/tmdbService');
|
||||
const { saveEntry, refrechEntry, SyncSeriesData } = require('../services/models-services/entryService');
|
||||
const { bulkImportMovies, bulkImportTmdb, bulkImportEpisodes } = require('../services/importerService');
|
||||
const { entryPicturesUpload } = require('../services/mutlerStorageLocations');
|
||||
const { generatePreview, doGeneratePreview } = require('../services/mediaService');
|
||||
const { doGeneratePreview } = require('../services/mediaService');
|
||||
|
||||
const { Sequelize } = require('sequelize');
|
||||
const Entry = require('../models/Entry');
|
||||
@@ -17,14 +16,13 @@ const EntrySeen = require('../models/EntrySeen');
|
||||
const Season = require('../models/Season');
|
||||
const Media = require('../models/Media');
|
||||
const Episode = require('../models/Episode');
|
||||
const UserCollection = require('../models/Collection');
|
||||
const Collection = require('../models/Collection');
|
||||
const { upsertOfficialCollection } = require('../services/models-services/collectionService');
|
||||
const { logToFile } = require('../services/logService');
|
||||
|
||||
// ! /entries
|
||||
// * GET - ALL ENTRIES
|
||||
entryRouter.get('/', async (req, res) => {
|
||||
const { page, pageSize } = req.body;
|
||||
|
||||
const entries = await Entry.findAll({
|
||||
include: [
|
||||
@@ -80,7 +78,7 @@ entryRouter.get('/:id', async (req, res) => {
|
||||
{ model: Season, as: 'seasons' },
|
||||
{ model: Media, as: 'medias' },
|
||||
{
|
||||
model: UserCollection, as: 'collections',
|
||||
model: Collection, as: 'collections',
|
||||
include: [
|
||||
{ model: Media, as: 'medias' }
|
||||
]
|
||||
@@ -98,16 +96,17 @@ entryRouter.get('/:id', async (req, res) => {
|
||||
[{ model: EntrySeen, as: 'entrySeen' }, 'date_seen', 'DESC'] // Order the entry-seen list
|
||||
]
|
||||
});
|
||||
|
||||
if (!entry) { // ! entry not found
|
||||
res.status(404).json({ message: 'Entry not found' });
|
||||
}
|
||||
|
||||
const entryData = entry.get({ plain: true });
|
||||
const genres = entryData.genres.map(genre => genre.name);
|
||||
const entryObjectData = entry.get({ plain: true });
|
||||
const genres = entryObjectData.genres.map(genre => genre.name);
|
||||
|
||||
entryData.genres = genres;
|
||||
entryObjectData.genres = genres;
|
||||
|
||||
res.status(200).json(entryData);
|
||||
res.status(200).json(entryObjectData);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
console.log(error);
|
||||
@@ -154,7 +153,7 @@ entryRouter.get('/:id/seasons', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// * POST - CREATE ENTRY
|
||||
// * POST - FETCH AND CREATE USING TMDB ID
|
||||
entryRouter.post('/', async (req, res) => {
|
||||
const { tmdb_id, is_tvserie } = req.body;
|
||||
|
||||
@@ -213,7 +212,7 @@ entryRouter.post('/bulk-import-episodes-seen', async (req, res) => {
|
||||
// * PUT - ENTRY UPDATE
|
||||
entryRouter.put('/:id', async (req, res) => {
|
||||
const { id } = req.params;
|
||||
const { favorit, hidden, watchlist } = req.body;
|
||||
const { entryData } = req.body;
|
||||
|
||||
// ? checking if the provied id is valid
|
||||
const oldEntry = await Entry.findByPk(id);
|
||||
@@ -222,43 +221,66 @@ entryRouter.put('/:id', async (req, res) => {
|
||||
return res.status(404).json({ message: `Entry with the provided id was not found` });
|
||||
|
||||
// ? updating
|
||||
await oldEntry.update({
|
||||
favorit: favorit,
|
||||
watchlist: watchlist,
|
||||
hidden: hidden
|
||||
});
|
||||
await oldEntry.update(entryData);
|
||||
|
||||
// ? returning a new entry with updated values
|
||||
let includes = [
|
||||
{ model: EntryId, as: 'entryId' },
|
||||
{ model: EntryRating, as: 'entryRating' },
|
||||
{ model: EntrySeen, as: 'entrySeen' },
|
||||
{ model: Media, as: 'medias' },
|
||||
{
|
||||
model: Genre,
|
||||
as: 'genres',
|
||||
attributes: ['name'],
|
||||
through: {
|
||||
attributes: []
|
||||
}
|
||||
}
|
||||
];
|
||||
// let includes = [
|
||||
// { model: EntryId, as: 'entryId' },
|
||||
// { model: EntryRating, as: 'entryRating' },
|
||||
// { model: EntrySeen, as: 'entrySeen' },
|
||||
// { model: Media, as: 'medias' },
|
||||
// {
|
||||
// model: Genre,
|
||||
// as: 'genres',
|
||||
// attributes: ['name'],
|
||||
// through: {
|
||||
// attributes: []
|
||||
// }
|
||||
// }
|
||||
// ];
|
||||
|
||||
if (oldEntry.is_tvseries) includes.push({ model: Season, as: 'seasons' });
|
||||
// if (oldEntry.is_tvseries) includes.push({ model: Season, as: 'seasons' });
|
||||
|
||||
// const updatedEntry = await Entry.findByPk(id, {
|
||||
// include: includes,
|
||||
// order: [
|
||||
// [{ model: EntrySeen, as: 'entrySeen' }, 'date_seen', 'DESC'] // Order the entry-seen list
|
||||
// ]
|
||||
// });
|
||||
|
||||
const updatedEntry = await Entry.findByPk(id, {
|
||||
include: includes,
|
||||
include: [
|
||||
{ model: EntryId, as: 'entryId' },
|
||||
{ model: EntryRating, as: 'entryRating' },
|
||||
{ model: EntrySeen, as: 'entrySeen' },
|
||||
{ model: Season, as: 'seasons' },
|
||||
{ model: Media, as: 'medias' },
|
||||
{
|
||||
model: Collection, as: 'collections',
|
||||
include: [
|
||||
{ model: Media, as: 'medias' }
|
||||
]
|
||||
},
|
||||
{
|
||||
model: Genre,
|
||||
as: 'genres',
|
||||
attributes: ['name'], // Only fetch the genre ID
|
||||
through: {
|
||||
attributes: [] // Do not fetch any attributes from the join table
|
||||
}
|
||||
}
|
||||
],
|
||||
order: [
|
||||
[{ model: EntrySeen, as: 'entrySeen' }, 'date_seen', 'DESC'] // Order the entry-seen list
|
||||
]
|
||||
});
|
||||
|
||||
const entryData = updatedEntry.get({ plain: true });
|
||||
const genres = entryData.genres.map(genre => genre.name);
|
||||
const entryObjectData = updatedEntry.get({ plain: true });
|
||||
const genres = entryObjectData.genres.map(genre => genre.name);
|
||||
|
||||
entryData.genres = genres;
|
||||
entryObjectData.genres = genres;
|
||||
|
||||
res.status(201).json(entryData);
|
||||
res.status(201).json(entryObjectData);
|
||||
});
|
||||
|
||||
// * GET - REQUEST ENTRY REFRECH
|
||||
@@ -289,7 +311,7 @@ entryRouter.get('/:id/fetch-collection', async (req, res, next) => {
|
||||
if (entryData.belongs_to_collection) {
|
||||
let collectionData = entryData.belongs_to_collection;
|
||||
|
||||
const [oldCollection, createdCollection] = await UserCollection.findOrCreate({
|
||||
const [oldCollection, createdCollection] = await Collection.findOrCreate({
|
||||
where: { tmdbId: collectionData.id },
|
||||
defaults: {
|
||||
name: collectionData.name,
|
||||
@@ -425,7 +447,8 @@ entryRouter.delete('/:entryId/media/:mediaId', async (req, res) => {
|
||||
if (media && media.isSelected) {
|
||||
let otherMedia = await Media.findOne({
|
||||
where: {
|
||||
entryId: media.entryId,
|
||||
mediaable: 'entry',
|
||||
mediaableId: media.mediaableId,
|
||||
type: media.type,
|
||||
isSelected: false
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user