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 Entry = require('../models/Entry.js')
|
||||||
const Collection = require('../models/Collection.js')
|
const Collection = require('../models/Collection.js')
|
||||||
const EntryId = require('../models/EntryId.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
|
// 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({
|
let movie = Entry.build({
|
||||||
title: data.title,
|
title: title,
|
||||||
original_title: data.original_title,
|
original_title: original_title,
|
||||||
release_date: data.release_date,
|
release_date: release_date,
|
||||||
runtime: data.runtime,
|
runtime: runtime,
|
||||||
|
|
||||||
storyline: data.overview,
|
storyline: data.overview,
|
||||||
country: data.production_countries.length > 0 ? data.production_countries[0].name : null,
|
country: data.production_countries.length > 0 ? data.production_countries[0].name : null,
|
||||||
|
|
||||||
is_tvseries: !isMovie,
|
is_tvseries: is_tvseries,
|
||||||
status: data.status,
|
status: data.status,
|
||||||
|
|
||||||
poster_path: data.poster_path,
|
poster_path: data.poster_path,
|
||||||
@@ -35,6 +44,31 @@ async function saveEntry(data, isMovie) {
|
|||||||
imdb_id: data.imdb_id,
|
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('entryRating', ratings);
|
||||||
savedMovie.setDataValue('entryId', ids);
|
savedMovie.setDataValue('entryId', ids);
|
||||||
@@ -50,7 +84,12 @@ async function getEntry(id) {
|
|||||||
return Entry.findByPk(id);
|
return Entry.findByPk(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteEntry() {
|
async function deleteEntry(id) {
|
||||||
|
await Entry.destroy({
|
||||||
|
where: {
|
||||||
|
id: id
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
Reference in new issue
Block a user