diff --git a/backend/services/entryService.js b/backend/services/entryService.js new file mode 100644 index 0000000..71488c9 --- /dev/null +++ b/backend/services/entryService.js @@ -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, +} \ No newline at end of file