61 lines
1.4 KiB
JavaScript
61 lines
1.4 KiB
JavaScript
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,
|
|
} |