Added entry service
This commit is contained in:
1 parent
bf288d5ab7
commit
3b9e39bd80
1 file changed
+61
@@ -0,0 +1,61 @@
|
|||||||
|
const Entry = require('../models/Entry.js')
|
||||||
|
const Collection = require('../models/Collection.js')
|
||||||
|
const EntryId = require('../models/EntryId.js')
|
||||||
|
const EntryRating = require('../models/EntryRating.js')
|
||||||
|
|
||||||
|
async function saveEntry(data, isMovie) {
|
||||||
|
// creating the object
|
||||||
|
let movie = Entry.build({
|
||||||
|
title: data.title,
|
||||||
|
original_title: data.original_title,
|
||||||
|
release_date: data.release_date,
|
||||||
|
runtime: data.runtime,
|
||||||
|
|
||||||
|
storyline: data.overview,
|
||||||
|
country: data.production_countries.length > 0 ? data.production_countries[0].name : null,
|
||||||
|
|
||||||
|
is_tvseries: !isMovie,
|
||||||
|
status: data.status,
|
||||||
|
|
||||||
|
poster_path: data.poster_path,
|
||||||
|
});
|
||||||
|
|
||||||
|
const savedMovie = await movie.save();
|
||||||
|
|
||||||
|
// Assuming EntryRating and EntryId are correctly defined and imported
|
||||||
|
const ratings = await EntryRating.create({
|
||||||
|
entry_id: savedMovie.id,
|
||||||
|
user_rating: 0, // Assuming a default value for user rating
|
||||||
|
tmdb_rating: data.vote_average,
|
||||||
|
});
|
||||||
|
|
||||||
|
const ids = await EntryId.create({
|
||||||
|
entry_id: savedMovie.id,
|
||||||
|
tmdb_id: data.id,
|
||||||
|
imdb_id: data.imdb_id,
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
savedMovie.setDataValue('entryRating', ratings);
|
||||||
|
savedMovie.setDataValue('entryId', ids);
|
||||||
|
|
||||||
|
return savedMovie;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function updateEntry() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getEntry(id) {
|
||||||
|
return Entry.findByPk(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteEntry() {
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
saveEntry,
|
||||||
|
updateEntry,
|
||||||
|
getEntry,
|
||||||
|
deleteEntry,
|
||||||
|
}
|
||||||
Reference in new issue
Block a user