add media model
This commit is contained in:
1 parent
76c4e47a38
commit
7e493d8866
6 files changed
+54
-4
No files matched your search
@@ -11,6 +11,7 @@ const Episode = require('../models/Episode');
|
|||||||
const EpisodeSeen = require('../models/EpisodeSeen');
|
const EpisodeSeen = require('../models/EpisodeSeen');
|
||||||
const Genre = require('../models/Genre');
|
const Genre = require('../models/Genre');
|
||||||
const EntryGenre = require('../models/EntryGenre');
|
const EntryGenre = require('../models/EntryGenre');
|
||||||
|
const Media = require('../models/Media');
|
||||||
|
|
||||||
|
|
||||||
// ? one to one
|
// ? one to one
|
||||||
@@ -84,6 +85,10 @@ Genre.hasMany(EntryGenre, { foreignKey: 'genre_id', as: 'entryGenres' });
|
|||||||
EntryGenre.belongsTo(Genre, { foreignKey: 'genre_id', as: 'genre' });
|
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 & SEASON - ONE TO MANY
|
||||||
Entry.hasMany(Season, { foreignKey: 'entry_id', as: 'seasons', onDelete: 'CASCADE', });
|
Entry.hasMany(Season, { foreignKey: 'entry_id', as: 'seasons', onDelete: 'CASCADE', });
|
||||||
Season.belongsTo(Entry, { foreignKey: 'entry_id', as: 'entry' });
|
Season.belongsTo(Entry, { foreignKey: 'entry_id', as: 'entry' });
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ const Entry = sequelize.define("entry",
|
|||||||
title: { type: DataTypes.STRING(100) },
|
title: { type: DataTypes.STRING(100) },
|
||||||
original_title: { type: DataTypes.STRING(100) },
|
original_title: { type: DataTypes.STRING(100) },
|
||||||
release_date: { type: DataTypes.DATE },
|
release_date: { type: DataTypes.DATE },
|
||||||
|
release_status: { type: DataTypes.STRING(50) },
|
||||||
runtime: { type: DataTypes.INTEGER },
|
runtime: { type: DataTypes.INTEGER },
|
||||||
|
|
||||||
tagline: { type: DataTypes.STRING(200) },
|
tagline: { type: DataTypes.STRING(200) },
|
||||||
@@ -29,7 +30,9 @@ const Entry = sequelize.define("entry",
|
|||||||
banner_path: { type: DataTypes.STRING(200) },
|
banner_path: { type: DataTypes.STRING(200) },
|
||||||
|
|
||||||
date_first_seen: { type: DataTypes.DATEONLY },
|
date_first_seen: { type: DataTypes.DATEONLY },
|
||||||
date_last_seen: { type: DataTypes.DATEONLY }
|
date_last_seen: { type: DataTypes.DATEONLY },
|
||||||
|
|
||||||
|
last_fetch: { type: DataTypes.DATEONLY },
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -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
@@ -50,12 +50,14 @@ app.use('/api/v1/media/:category/:type', (req, res, next) => {
|
|||||||
// * other api routes
|
// * other api routes
|
||||||
app.use('/api/v1', routes);
|
app.use('/api/v1', routes);
|
||||||
|
|
||||||
|
// ! Error handling middleware
|
||||||
|
app.use(errorHandler);
|
||||||
|
|
||||||
// Start the server
|
// Start the server
|
||||||
const relations = require('./db/relations.js');
|
const relations = require('./db/relations.js');
|
||||||
const sequelizeHooks = require('./db/sequelizeHooks.js');
|
const sequelizeHooks = require('./db/sequelizeHooks.js');
|
||||||
const { initializeGenres, initializeData } = require('./db/dataInitializer.js');
|
const { initializeGenres, initializeData } = require('./db/dataInitializer.js');
|
||||||
console.log(`Syning database schema...`);
|
console.log(`Syncing database schema...`);
|
||||||
sequelize
|
sequelize
|
||||||
// .sync({force: true}) // will drop all tables and recreate them.
|
// .sync({force: true}) // will drop all tables and recreate them.
|
||||||
// .sync({ alter: true }) // will attempt to automatically alter tables to fit the model definitions.
|
// .sync({ alter: true }) // will attempt to automatically alter tables to fit the model definitions.
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { EntryId } from './entryId.model';
|
import { EntryId } from './entryId.model';
|
||||||
import { EntryRating } from './entryRating.model';
|
import { EntryRating } from './entryRating.model';
|
||||||
import { EntrySeen } from './entrySeen.model';
|
import { EntrySeen } from './entrySeen.model';
|
||||||
|
import { Media } from './media.model';
|
||||||
import { Season } from './season.model';
|
import { Season } from './season.model';
|
||||||
|
|
||||||
export interface Entry {
|
export interface Entry {
|
||||||
@@ -10,7 +11,7 @@ export interface Entry {
|
|||||||
entryRating: EntryRating;
|
entryRating: EntryRating;
|
||||||
entrySeen: EntrySeen[];
|
entrySeen: EntrySeen[];
|
||||||
seasons: Season[];
|
seasons: Season[];
|
||||||
|
|
||||||
title: string;
|
title: string;
|
||||||
original_title: string;
|
original_title: string;
|
||||||
release_date: Date;
|
release_date: Date;
|
||||||
@@ -35,10 +36,12 @@ export interface Entry {
|
|||||||
date_first_seen: Date;
|
date_first_seen: Date;
|
||||||
date_last_seen: Date;
|
date_last_seen: Date;
|
||||||
|
|
||||||
|
genres: string[];
|
||||||
|
medias: Media[];
|
||||||
|
|
||||||
// temp fields
|
// temp fields
|
||||||
poster_path: string;
|
poster_path: string;
|
||||||
banner_path: string;
|
banner_path: string;
|
||||||
genres: string[];
|
|
||||||
|
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
updatedAt: 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;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user