add table view for collection info page
This commit is contained in:
1 parent
7e493d8866
commit
ec45cd342f
13 files changed
+330
-9
No files matched your search
@@ -4,6 +4,9 @@ const UserCollectionEntry = require('../models/UserCollectionEntry');
|
||||
const Entry = require('../models/Entry');
|
||||
const EntryId = require('../models/EntryId');
|
||||
const EntryRating = require('../models/EntryRating');
|
||||
const Season = require('../models/Season');
|
||||
const Genre = require('../models/Genre');
|
||||
|
||||
const { Sequelize } = require('sequelize');
|
||||
const router = express.Router();
|
||||
const multer = require('multer');
|
||||
@@ -46,7 +49,9 @@ router.get('/:id', async (req, res) => {
|
||||
as: 'entries',
|
||||
include: [
|
||||
{ model: EntryId, as: 'entryId' },
|
||||
{ model: EntryRating, as: 'entryRating' }
|
||||
{ model: EntryRating, as: 'entryRating' },
|
||||
{ model: Season, as: 'seasons' },
|
||||
{ model: Genre, as: 'genres' },
|
||||
],
|
||||
through: {
|
||||
model: UserCollectionEntry,
|
||||
@@ -57,7 +62,13 @@ router.get('/:id', async (req, res) => {
|
||||
});
|
||||
|
||||
if (userCollection) {
|
||||
res.status(200).json(userCollection);
|
||||
const collectionData = userCollection.get({ plain: true });
|
||||
for (let i = 0; i < collectionData.entries.length; i++) {
|
||||
const genres = collectionData.entries[i].genres.map(genre => genre.name);
|
||||
collectionData.entries[i].genres = genres
|
||||
}
|
||||
|
||||
res.status(200).json(collectionData);
|
||||
} else {
|
||||
res.status(404).json({ message: 'UserCollection not found' });
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user