Backend: minor changes
This commit is contained in:
1 parent
b6c04e765f
commit
c8141fb87b
3 files changed
+54
-22
No files matched your search
@@ -62,6 +62,15 @@ class EntryService {
|
||||
return entriesWithGenreNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves an entry by its ID, optionally as a plain object.
|
||||
*
|
||||
* @param {number} id - The entry ID to retrieve.
|
||||
* @param {boolean} [plain=true] - Whether to return a plain object or a Sequelize instance.
|
||||
* @returns {Promise<Object>} The entry data.
|
||||
* @throws {BadRequestError} If no ID is provided.
|
||||
* @throws {NotFoundError} If no entry is found with the given ID.
|
||||
*/
|
||||
async getEntryById(id, plain = true) {
|
||||
if (!id) {
|
||||
throw new BadRequestError("Entry id not provided");
|
||||
@@ -77,44 +86,36 @@ class EntryService {
|
||||
{ model: Network, as: 'networks' },
|
||||
{
|
||||
model: Cast, as: 'credits',
|
||||
include: [
|
||||
{ model: People, as: 'person' }
|
||||
]
|
||||
where: { cast_type: 'cast' },
|
||||
order: [['order', 'ASC']],
|
||||
limit: 10,
|
||||
include: [{ model: People, as: 'person' }]
|
||||
},
|
||||
{
|
||||
model: Collection, as: 'collections',
|
||||
include: [
|
||||
{ model: Media, as: 'medias' }
|
||||
]
|
||||
include: [{ model: Media, as: 'medias' }]
|
||||
},
|
||||
{
|
||||
model: Genre,
|
||||
as: 'genres',
|
||||
attributes: ['name', 'id'],
|
||||
through: {
|
||||
attributes: [] // Do not fetch any attributes from the join table
|
||||
}
|
||||
through: { attributes: [] }
|
||||
}
|
||||
],
|
||||
order: [
|
||||
[{ model: EntrySeen, as: 'entrySeen' }, 'date_seen', 'DESC'] // Order the entry-seen list
|
||||
]
|
||||
order: [[{ model: EntrySeen, as: 'entrySeen' }, 'date_seen', 'DESC']]
|
||||
});
|
||||
|
||||
if (!entry) {
|
||||
throw new NotFoundError("Entry with the provided id was not found")
|
||||
throw new NotFoundError("Entry with the provided id was not found");
|
||||
}
|
||||
|
||||
if (plain) {
|
||||
const plainEntry = entry.get({ plain: true });
|
||||
const genres = plainEntry.genres.map(genre => genre.name);
|
||||
|
||||
plainEntry.genres = genres;
|
||||
|
||||
plainEntry.genres = plainEntry.genres.map(g => g.name);
|
||||
return plainEntry;
|
||||
} else {
|
||||
return entry;
|
||||
}
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
async createEntry(data, plain = true) {
|
||||
|
||||
Reference in new issue
Block a user