Backend: minor changes
This commit is contained in:
1 parent
b6c04e765f
commit
c8141fb87b
3 files changed
+53
-21
No files matched your search
@@ -457,6 +457,7 @@ class EntryManager {
|
||||
|
||||
if (!oldEntry)
|
||||
throw NotFoundError('Entry Not Found');
|
||||
|
||||
const entryData = await fetchEntryData(oldEntry.entryId.tmdb_id, oldEntry.is_tvseries);
|
||||
|
||||
if (!entryData)
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -41,7 +41,8 @@ class PeopleService {
|
||||
include: { model: Media, as: "medias" }
|
||||
},
|
||||
...where
|
||||
}
|
||||
},
|
||||
{ model: Media, as: 'medias' }
|
||||
],
|
||||
});
|
||||
|
||||
@@ -59,7 +60,8 @@ class PeopleService {
|
||||
as: "entry",
|
||||
include: { model: Media, as: "medias" }
|
||||
},
|
||||
}
|
||||
},
|
||||
{ model: Media, as: 'medias' }
|
||||
]
|
||||
});
|
||||
|
||||
@@ -83,6 +85,7 @@ class PeopleService {
|
||||
include: { model: Media, as: "medias" }
|
||||
}
|
||||
},
|
||||
{ model: Media, as: 'medias' }
|
||||
]
|
||||
});
|
||||
|
||||
@@ -107,6 +110,33 @@ class PeopleService {
|
||||
}
|
||||
}
|
||||
|
||||
async createOrUpdatePerson(personData) {
|
||||
return await People.findOrCreate({
|
||||
where: { tmdb_id: personData.tmdb_id },
|
||||
defaults: {
|
||||
name: personData.name,
|
||||
biography: personData.biography,
|
||||
birthday: personData.birthday,
|
||||
deathday: personData.deathday,
|
||||
place_of_birth: personData.place_of_birth,
|
||||
profile_path: personData.profile_path,
|
||||
popularity: personData.popularity,
|
||||
fully_fetched: true,
|
||||
last_fetch: new Date(),
|
||||
},
|
||||
include: [
|
||||
{
|
||||
model: Credit, as: 'roles',
|
||||
include: {
|
||||
model: Entry, as: 'entry',
|
||||
include: [{ model: Media, as: 'medias' }]
|
||||
}
|
||||
},
|
||||
{ model: Media, as: 'medias' }
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async updatePerson(id, personData) {
|
||||
const person = await People.findByPk(id);
|
||||
|
||||
|
||||
Reference in new issue
Block a user