BE entry service: upgraded saveEntry + add deleteEntry
This commit is contained in:
1 parent
eecb1443ca
commit
f964562cb2
1 file changed
+47
-8
@@ -1,20 +1,29 @@
|
||||
const Entry = require('../models/Entry.js')
|
||||
const Collection = require('../models/Collection.js')
|
||||
const EntryId = require('../models/EntryId.js')
|
||||
const EntryRating = require('../models/EntryRating.js')
|
||||
const EntryRating = require('../models/EntryRating.js');
|
||||
const Season = require('../models/Season.js');
|
||||
|
||||
async function saveEntry(data, isMovie) {
|
||||
async function saveEntry(data) {
|
||||
// creating the object
|
||||
var title = data.title || data.name;
|
||||
var original_title = data.original_title || data.original_name;
|
||||
|
||||
var runtime = data.runtime || null;
|
||||
|
||||
var is_tvseries = data.release_date == null ? true : false;
|
||||
var release_date = data.release_date || data.first_air_date;
|
||||
|
||||
let movie = Entry.build({
|
||||
title: data.title,
|
||||
original_title: data.original_title,
|
||||
release_date: data.release_date,
|
||||
runtime: data.runtime,
|
||||
title: title,
|
||||
original_title: original_title,
|
||||
release_date: release_date,
|
||||
runtime: runtime,
|
||||
|
||||
storyline: data.overview,
|
||||
country: data.production_countries.length > 0 ? data.production_countries[0].name : null,
|
||||
|
||||
is_tvseries: !isMovie,
|
||||
is_tvseries: is_tvseries,
|
||||
status: data.status,
|
||||
|
||||
poster_path: data.poster_path,
|
||||
@@ -35,6 +44,31 @@ async function saveEntry(data, isMovie) {
|
||||
imdb_id: data.imdb_id,
|
||||
});
|
||||
|
||||
let seasons = [];
|
||||
if (is_tvseries) {
|
||||
data.seasons.forEach(async (season) => {
|
||||
const s = await Season.create({
|
||||
tmdb_id: season.id,
|
||||
|
||||
entry_id: savedMovie.id,
|
||||
|
||||
name: season.name,
|
||||
overview: season.overview,
|
||||
season_number: season.season_number,
|
||||
air_date: season.air_date,
|
||||
|
||||
user_rating: 0,
|
||||
tmdb_rating: season.vote_average,
|
||||
|
||||
poster_path: season.poster_path,
|
||||
banner_path: null,
|
||||
})
|
||||
|
||||
seasons.push(s)
|
||||
});
|
||||
|
||||
await savedMovie.setDataValue('seasons', seasons);
|
||||
}
|
||||
|
||||
savedMovie.setDataValue('entryRating', ratings);
|
||||
savedMovie.setDataValue('entryId', ids);
|
||||
@@ -50,7 +84,12 @@ async function getEntry(id) {
|
||||
return Entry.findByPk(id);
|
||||
}
|
||||
|
||||
async function deleteEntry() {
|
||||
async function deleteEntry(id) {
|
||||
await Entry.destroy({
|
||||
where: {
|
||||
id: id
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
Reference in new issue
Block a user