add media model

This commit is contained in:
X4Lo committed 2024-05-17 11:51:11 +01:00
1 parent 76c4e47a38
commit 7e493d8866
6 files changed
+54 -4

No files matched your search

+5
View File
@@ -11,6 +11,7 @@ const Episode = require('../models/Episode');
const EpisodeSeen = require('../models/EpisodeSeen');
const Genre = require('../models/Genre');
const EntryGenre = require('../models/EntryGenre');
const Media = require('../models/Media');
// ? one to one
@@ -84,6 +85,10 @@ Genre.hasMany(EntryGenre, { foreignKey: 'genre_id', as: 'entryGenres' });
EntryGenre.belongsTo(Genre, { foreignKey: 'genre_id', as: 'genre' });
// * ENTRY & MEDIA - ONE TO MANY
Entry.hasMany(Media, { foreignKey: 'entry_id', as: 'medias', onDelete: 'CASCADE', });
Media.belongsTo(Entry, { foreignKey: 'entry_id', as: 'entry' });
// * ENTRY & SEASON - ONE TO MANY
Entry.hasMany(Season, { foreignKey: 'entry_id', as: 'seasons', onDelete: 'CASCADE', });
Season.belongsTo(Entry, { foreignKey: 'entry_id', as: 'entry' });
+4 -1
View File
@@ -8,6 +8,7 @@ const Entry = sequelize.define("entry",
title: { type: DataTypes.STRING(100) },
original_title: { type: DataTypes.STRING(100) },
release_date: { type: DataTypes.DATE },
release_status: { type: DataTypes.STRING(50) },
runtime: { type: DataTypes.INTEGER },
tagline: { type: DataTypes.STRING(200) },
@@ -29,7 +30,9 @@ const Entry = sequelize.define("entry",
banner_path: { type: DataTypes.STRING(200) },
date_first_seen: { type: DataTypes.DATEONLY },
date_last_seen: { type: DataTypes.DATEONLY }
date_last_seen: { type: DataTypes.DATEONLY },
last_fetch: { type: DataTypes.DATEONLY },
}
);
+23
View File
@@ -0,0 +1,23 @@
const { DataTypes } = require('sequelize');
const sequelize = require('../db/database');
const Media = sequelize.define("media",
{
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
entry_id: {
type: DataTypes.INTEGER,
references: {
model: 'Entries',
key: 'id'
}
},
type: { type: DataTypes.STRING(50) },
path: { type: DataTypes.STRING(200) },
is_local: { type: DataTypes.BOOLEAN },
is_selected: { type: DataTypes.BOOLEAN },
}
);
module.exports = Media;
+3 -1
View File
@@ -50,12 +50,14 @@ app.use('/api/v1/media/:category/:type', (req, res, next) => {
// * other api routes
app.use('/api/v1', routes);
// ! Error handling middleware
app.use(errorHandler);
// Start the server
const relations = require('./db/relations.js');
const sequelizeHooks = require('./db/sequelizeHooks.js');
const { initializeGenres, initializeData } = require('./db/dataInitializer.js');
console.log(`Syning database schema...`);
console.log(`Syncing database schema...`);
sequelize
// .sync({force: true}) // will drop all tables and recreate them.
// .sync({ alter: true }) // will attempt to automatically alter tables to fit the model definitions.
@@ -1,6 +1,7 @@
import { EntryId } from './entryId.model';
import { EntryRating } from './entryRating.model';
import { EntrySeen } from './entrySeen.model';
import { Media } from './media.model';
import { Season } from './season.model';
export interface Entry {
@@ -10,7 +11,7 @@ export interface Entry {
entryRating: EntryRating;
entrySeen: EntrySeen[];
seasons: Season[];
title: string;
original_title: string;
release_date: Date;
@@ -35,10 +36,12 @@ export interface Entry {
date_first_seen: Date;
date_last_seen: Date;
genres: string[];
medias: Media[];
// temp fields
poster_path: string;
banner_path: string;
genres: string[];
createdAt: Date;
updatedAt: Date;
@@ -0,0 +1,14 @@
export interface Media {
id: number;
entry_id: number;
type: string;
path: string;
is_local: boolean;
is_selected: boolean;
createdAt: Date;
updatedAt: Date;
}