Backend: minor changes
This commit is contained in:
1 parent
b6c04e765f
commit
c8141fb87b
3 files changed
+54
-22
No files matched your search
@@ -457,6 +457,7 @@ class EntryManager {
|
|||||||
|
|
||||||
if (!oldEntry)
|
if (!oldEntry)
|
||||||
throw NotFoundError('Entry Not Found');
|
throw NotFoundError('Entry Not Found');
|
||||||
|
|
||||||
const entryData = await fetchEntryData(oldEntry.entryId.tmdb_id, oldEntry.is_tvseries);
|
const entryData = await fetchEntryData(oldEntry.entryId.tmdb_id, oldEntry.is_tvseries);
|
||||||
|
|
||||||
if (!entryData)
|
if (!entryData)
|
||||||
|
|||||||
@@ -62,6 +62,15 @@ class EntryService {
|
|||||||
return entriesWithGenreNames;
|
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) {
|
async getEntryById(id, plain = true) {
|
||||||
if (!id) {
|
if (!id) {
|
||||||
throw new BadRequestError("Entry id not provided");
|
throw new BadRequestError("Entry id not provided");
|
||||||
@@ -77,44 +86,36 @@ class EntryService {
|
|||||||
{ model: Network, as: 'networks' },
|
{ model: Network, as: 'networks' },
|
||||||
{
|
{
|
||||||
model: Cast, as: 'credits',
|
model: Cast, as: 'credits',
|
||||||
include: [
|
where: { cast_type: 'cast' },
|
||||||
{ model: People, as: 'person' }
|
order: [['order', 'ASC']],
|
||||||
]
|
limit: 10,
|
||||||
|
include: [{ model: People, as: 'person' }]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
model: Collection, as: 'collections',
|
model: Collection, as: 'collections',
|
||||||
include: [
|
include: [{ model: Media, as: 'medias' }]
|
||||||
{ model: Media, as: 'medias' }
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
model: Genre,
|
model: Genre,
|
||||||
as: 'genres',
|
as: 'genres',
|
||||||
attributes: ['name', 'id'],
|
attributes: ['name', 'id'],
|
||||||
through: {
|
through: { attributes: [] }
|
||||||
attributes: [] // Do not fetch any attributes from the join table
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
order: [
|
order: [[{ model: EntrySeen, as: 'entrySeen' }, 'date_seen', 'DESC']]
|
||||||
[{ model: EntrySeen, as: 'entrySeen' }, 'date_seen', 'DESC'] // Order the entry-seen list
|
|
||||||
]
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!entry) {
|
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) {
|
if (plain) {
|
||||||
const plainEntry = entry.get({ plain: true });
|
const plainEntry = entry.get({ plain: true });
|
||||||
const genres = plainEntry.genres.map(genre => genre.name);
|
plainEntry.genres = plainEntry.genres.map(g => g.name);
|
||||||
|
|
||||||
plainEntry.genres = genres;
|
|
||||||
|
|
||||||
return plainEntry;
|
return plainEntry;
|
||||||
} else {
|
|
||||||
return entry;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
async createEntry(data, plain = true) {
|
async createEntry(data, plain = true) {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ class PeopleService {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if(includeCrew){
|
if (includeCrew) {
|
||||||
where = {};
|
where = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +41,8 @@ class PeopleService {
|
|||||||
include: { model: Media, as: "medias" }
|
include: { model: Media, as: "medias" }
|
||||||
},
|
},
|
||||||
...where
|
...where
|
||||||
}
|
},
|
||||||
|
{ model: Media, as: 'medias' }
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -59,7 +60,8 @@ class PeopleService {
|
|||||||
as: "entry",
|
as: "entry",
|
||||||
include: { model: Media, as: "medias" }
|
include: { model: Media, as: "medias" }
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
|
{ model: Media, as: 'medias' }
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -83,6 +85,7 @@ class PeopleService {
|
|||||||
include: { model: Media, as: "medias" }
|
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) {
|
async updatePerson(id, personData) {
|
||||||
const person = await People.findByPk(id);
|
const person = await People.findByPk(id);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user