From ef9e1911f94e99dc68cbd09b09107b467d9d4657 Mon Sep 17 00:00:00 2001 From: X4Lo Date: Fri, 11 Jul 2025 15:12:07 +0100 Subject: [PATCH] B: Added People and Credit Models for entry crew and cast --- backend/config/relations.js | 12 +++++++++++- backend/models/Credit.js | 25 +++++++++++++++++++++++++ backend/models/Entry.js | 1 + backend/models/People.js | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 backend/models/Credit.js create mode 100644 backend/models/People.js diff --git a/backend/config/relations.js b/backend/config/relations.js index 65a43f6..084ea54 100644 --- a/backend/config/relations.js +++ b/backend/config/relations.js @@ -14,6 +14,8 @@ const EntryGenre = require('../models/EntryGenre'); const Media = require('../models/Media'); const Network = require('../models/Network'); const EntryNetwork = require('../models/EntryNetwork'); +const People = require('../models/People'); +const Credit = require('../models/Credit'); // ? one to one @@ -191,4 +193,12 @@ EpisodeSeen.belongsTo(Entry, { foreignKey: 'entry_id' }); // * ---- Franchise.hasMany(Entry, { foreignKey: 'franchise_id' }); -Entry.belongsTo(Franchise, { foreignKey: 'franchise_id' }); \ No newline at end of file +Entry.belongsTo(Franchise, { foreignKey: 'franchise_id' }); + +// * ENTRY & Credit - ONE TO MANY +Entry.hasMany(Credit, { foreignKey: 'entry_id', as: 'credits', onDelete: 'CASCADE', }); +Credit.belongsTo(Entry, { foreignKey: 'entry_id', as: 'entry' }); + +// * PEOPLE & CAST - ONE TO MANY +People.hasMany(Credit, { foreignKey: 'people_id', as: 'roles', onDelete: 'CASCADE', }); +Credit.belongsTo(People, { foreignKey: 'people_id', as: 'person' }); \ No newline at end of file diff --git a/backend/models/Credit.js b/backend/models/Credit.js new file mode 100644 index 0000000..49afcc5 --- /dev/null +++ b/backend/models/Credit.js @@ -0,0 +1,25 @@ +const { DataTypes } = require('sequelize'); +const sequelize = require('../config/database'); + +const Credit = sequelize.define("credits", + { + id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true }, + + tmdb_credit_id: { type: DataTypes.STRING(100) }, + + adult: { type: DataTypes.BOOLEAN, defaultValue: false }, + profile_path: { type: DataTypes.STRING(200), field: 'profile_path' }, + + character: { type: DataTypes.STRING(100) }, + order: { type: DataTypes.INTEGER }, + + cast_type: { type: DataTypes.ENUM('cast', 'crew'), field: 'cast_type', defaultValue: 'cast' }, + department: { type: DataTypes.STRING(100) }, + job: { type: DataTypes.STRING(100) }, + + entry_id: { type: DataTypes.INTEGER, field: 'entry_id' }, + people_id: { type: DataTypes.INTEGER, field: 'people_id' }, + } +); + +module.exports = Credit; \ No newline at end of file diff --git a/backend/models/Entry.js b/backend/models/Entry.js index 3197968..c9ada7a 100644 --- a/backend/models/Entry.js +++ b/backend/models/Entry.js @@ -19,6 +19,7 @@ const Entry = sequelize.define("entry", network_studio: { type: DataTypes.STRING(40), field: 'network_studio' }, collection_id: { type: DataTypes.INTEGER, field: 'collection_id' }, max_cast: { type: DataTypes.INTEGER, field: 'max_cast', defaultValue: 10 }, + credit_fetched: { type: DataTypes.BOOLEAN, defaultValue: false, field: 'is_tvseries' }, watchlist: { type: DataTypes.BOOLEAN, defaultValue: false }, favorit: { type: DataTypes.BOOLEAN, defaultValue: false }, diff --git a/backend/models/People.js b/backend/models/People.js new file mode 100644 index 0000000..33426cf --- /dev/null +++ b/backend/models/People.js @@ -0,0 +1,33 @@ +const { DataTypes } = require('sequelize'); +const sequelize = require('../config/database'); + +const People = sequelize.define("peoples", + { + id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true }, + + tmdb_id: { type: DataTypes.STRING(100) }, + + name: { type: DataTypes.STRING(100) }, + birthday: { type: DataTypes.DATEONLY }, + deathday: { type: DataTypes.DATEONLY, allowNull: true }, + gender: { type: DataTypes.INTEGER }, + + biography: { type: DataTypes.TEXT }, + place_of_birth: { type: DataTypes.STRING(100), field: 'place_of_birth' }, + + adult: { type: DataTypes.BOOLEAN, defaultValue: false }, + popularity: { type: DataTypes.FLOAT }, + + known_for_department: { type: DataTypes.STRING(50), field: 'known_for_department' }, + homepage: { type: DataTypes.STRING(200), allowNull: true }, + + imdb_id: { type: DataTypes.STRING(20), field: 'imdb_id' }, + profile_path: { type: DataTypes.STRING(200), field: 'profile_path' }, + + last_fetch: { type: DataTypes.DATEONLY, field: 'last_fetch' }, + profile_update: { type: DataTypes.DATEONLY, field: 'profile_update' }, + fully_fetched: { type: DataTypes.BOOLEAN, defaultValue: false }, + } +); + +module.exports = People; \ No newline at end of file