Add Watch Buddies feature
- Created WatchBuddy model - M:N junctions to EntrySeen/EpisodeSeen and Media relation for profile pictures - Full CRUD + search + profile picture upload - WatchBuddySelect multi-select with search and inline create, replaced all seen_with text inputs - WatchBuddiesPage (grid) and WatchBuddyProfilePage (edit form, icon-based contacts, poster-grid watch history, monthly timeline)
This commit is contained in:
1 parent
4313a794ce
commit
e82b905886
28 files changed
+6813
-374
No files matched your search
+159
-114
@@ -1,21 +1,24 @@
|
||||
// Import models
|
||||
const Franchise = require("../models/Franchise");
|
||||
const Entry = require("../models/Entry");
|
||||
const EntryId = require("../models/EntryId");
|
||||
const EntryRating = require("../models/EntryRating");
|
||||
const EntrySeen = require("../models/EntrySeen");
|
||||
const Collection = require("../models/Collection");
|
||||
const UserCollectionEntry = require("../models/UserCollectionEntry");
|
||||
const Season = require("../models/Season");
|
||||
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");
|
||||
const Network = require("../models/Network");
|
||||
const EntryNetwork = require("../models/EntryNetwork");
|
||||
const People = require("../models/People");
|
||||
const Credit = require("../models/Credit");
|
||||
const Franchise = require('../models/Franchise');
|
||||
const Entry = require('../models/Entry');
|
||||
const EntryId = require('../models/EntryId');
|
||||
const EntryRating = require('../models/EntryRating');
|
||||
const EntrySeen = require('../models/EntrySeen');
|
||||
const Collection = require('../models/Collection');
|
||||
const UserCollectionEntry = require('../models/UserCollectionEntry');
|
||||
const Season = require('../models/Season');
|
||||
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');
|
||||
const Network = require('../models/Network');
|
||||
const EntryNetwork = require('../models/EntryNetwork');
|
||||
const People = require('../models/People');
|
||||
const Credit = require('../models/Credit');
|
||||
const WatchBuddy = require('../models/WatchBuddy');
|
||||
const EntrySeenBuddy = require('../models/EntrySeenBuddy');
|
||||
const EpisodeSeenBuddy = require('../models/EpisodeSeenBuddy');
|
||||
|
||||
// ? one to one
|
||||
// A hasOne B = A > B
|
||||
@@ -26,221 +29,263 @@ const Credit = require("../models/Credit");
|
||||
|
||||
// * ENTRY & EntryId - ONE TO ONE
|
||||
Entry.hasOne(EntryId, {
|
||||
foreignKey: "entry_id",
|
||||
as: "entryId",
|
||||
onDelete: "CASCADE",
|
||||
foreignKey: 'entry_id',
|
||||
as: 'entryId',
|
||||
onDelete: 'CASCADE',
|
||||
});
|
||||
EntryId.belongsTo(Entry, { foreignKey: "entry_id", as: "entry" });
|
||||
EntryId.belongsTo(Entry, { foreignKey: 'entry_id', as: 'entry' });
|
||||
|
||||
// * ENTRY & EntryRating - ONE TO ONE
|
||||
Entry.hasOne(EntryRating, {
|
||||
foreignKey: "entry_id",
|
||||
as: "entryRating",
|
||||
onDelete: "CASCADE",
|
||||
foreignKey: 'entry_id',
|
||||
as: 'entryRating',
|
||||
onDelete: 'CASCADE',
|
||||
});
|
||||
EntryRating.belongsTo(Entry, { foreignKey: "entry_id", as: "entry" });
|
||||
EntryRating.belongsTo(Entry, { foreignKey: 'entry_id', as: 'entry' });
|
||||
|
||||
// * ENTRY & ENTRY_SEEN - ONE TO MANY
|
||||
Entry.hasMany(EntrySeen, {
|
||||
foreignKey: "entry_id",
|
||||
as: "entrySeen",
|
||||
onDelete: "CASCADE",
|
||||
foreignKey: 'entry_id',
|
||||
as: 'entrySeen',
|
||||
onDelete: 'CASCADE',
|
||||
});
|
||||
EntrySeen.belongsTo(Entry, { foreignKey: "entry_id", as: "entry" });
|
||||
EntrySeen.belongsTo(Entry, { foreignKey: 'entry_id', as: 'entry' });
|
||||
|
||||
// * ENTRY & LIST - MANY TO MANY
|
||||
Entry.belongsToMany(Collection, {
|
||||
through: UserCollectionEntry,
|
||||
foreignKey: "entry_id",
|
||||
otherKey: "user_collection_id",
|
||||
onDelete: "CASCADE",
|
||||
as: "collections",
|
||||
foreignKey: 'entry_id',
|
||||
otherKey: 'user_collection_id',
|
||||
onDelete: 'CASCADE',
|
||||
as: 'collections',
|
||||
});
|
||||
|
||||
Collection.belongsToMany(Entry, {
|
||||
through: UserCollectionEntry,
|
||||
foreignKey: "user_collection_id",
|
||||
otherKey: "entry_id",
|
||||
onDelete: "CASCADE",
|
||||
as: "entries",
|
||||
foreignKey: 'user_collection_id',
|
||||
otherKey: 'entry_id',
|
||||
onDelete: 'CASCADE',
|
||||
as: 'entries',
|
||||
});
|
||||
|
||||
Entry.hasMany(UserCollectionEntry, {
|
||||
foreignKey: "entry_id",
|
||||
as: "userCollectionEntries",
|
||||
foreignKey: 'entry_id',
|
||||
as: 'userCollectionEntries',
|
||||
});
|
||||
UserCollectionEntry.belongsTo(Entry, { foreignKey: "entry_id", as: "entry" });
|
||||
UserCollectionEntry.belongsTo(Entry, { foreignKey: 'entry_id', as: 'entry' });
|
||||
Collection.hasMany(UserCollectionEntry, {
|
||||
foreignKey: "user_collection_id",
|
||||
as: "userCollectionEntries",
|
||||
foreignKey: 'user_collection_id',
|
||||
as: 'userCollectionEntries',
|
||||
});
|
||||
UserCollectionEntry.belongsTo(Collection, {
|
||||
foreignKey: "user_collection_id",
|
||||
as: "userCollection",
|
||||
foreignKey: 'user_collection_id',
|
||||
as: 'userCollection',
|
||||
});
|
||||
|
||||
// * ENTRY & GENRE - MANY TO MANY
|
||||
Entry.belongsToMany(Genre, {
|
||||
through: EntryGenre,
|
||||
foreignKey: "entry_id",
|
||||
otherKey: "genre_id",
|
||||
onDelete: "CASCADE",
|
||||
as: "genres",
|
||||
foreignKey: 'entry_id',
|
||||
otherKey: 'genre_id',
|
||||
onDelete: 'CASCADE',
|
||||
as: 'genres',
|
||||
});
|
||||
|
||||
Genre.belongsToMany(Entry, {
|
||||
through: EntryGenre,
|
||||
foreignKey: "genre_id",
|
||||
otherKey: "entry_id",
|
||||
onDelete: "CASCADE",
|
||||
as: "entries",
|
||||
foreignKey: 'genre_id',
|
||||
otherKey: 'entry_id',
|
||||
onDelete: 'CASCADE',
|
||||
as: 'entries',
|
||||
});
|
||||
|
||||
Entry.hasMany(EntryGenre, { foreignKey: "entry_id", as: "entryGenres" });
|
||||
EntryGenre.belongsTo(Entry, { foreignKey: "entry_id", as: "entry" });
|
||||
Genre.hasMany(EntryGenre, { foreignKey: "genre_id", as: "entryGenres" });
|
||||
EntryGenre.belongsTo(Genre, { foreignKey: "genre_id", as: "genre" });
|
||||
Entry.hasMany(EntryGenre, { foreignKey: 'entry_id', as: 'entryGenres' });
|
||||
EntryGenre.belongsTo(Entry, { foreignKey: 'entry_id', as: 'entry' });
|
||||
Genre.hasMany(EntryGenre, { foreignKey: 'genre_id', as: 'entryGenres' });
|
||||
EntryGenre.belongsTo(Genre, { foreignKey: 'genre_id', as: 'genre' });
|
||||
|
||||
// * ENTRY & NETWORK - MANY TO MANY
|
||||
Entry.belongsToMany(Network, {
|
||||
through: EntryNetwork,
|
||||
foreignKey: "entry_id",
|
||||
otherKey: "network_id",
|
||||
onDelete: "CASCADE",
|
||||
as: "networks",
|
||||
foreignKey: 'entry_id',
|
||||
otherKey: 'network_id',
|
||||
onDelete: 'CASCADE',
|
||||
as: 'networks',
|
||||
});
|
||||
|
||||
Network.belongsToMany(Entry, {
|
||||
through: EntryNetwork,
|
||||
foreignKey: "network_id",
|
||||
otherKey: "entry_id",
|
||||
onDelete: "CASCADE",
|
||||
as: "entries",
|
||||
foreignKey: 'network_id',
|
||||
otherKey: 'entry_id',
|
||||
onDelete: 'CASCADE',
|
||||
as: 'entries',
|
||||
});
|
||||
|
||||
// ! MEDIA
|
||||
// * MEDIA & ENTRY - MANY TO ONE
|
||||
Media.belongsTo(Entry, {
|
||||
foreignKey: "mediaableId",
|
||||
as: "entry",
|
||||
foreignKey: 'mediaableId',
|
||||
as: 'entry',
|
||||
constraints: false,
|
||||
where: {
|
||||
mediaable: "entry",
|
||||
mediaable: 'entry',
|
||||
},
|
||||
});
|
||||
|
||||
Entry.hasMany(Media, {
|
||||
foreignKey: "mediaableId",
|
||||
foreignKey: 'mediaableId',
|
||||
constraints: false,
|
||||
as: "medias",
|
||||
scope: { mediaable: "entry" },
|
||||
as: 'medias',
|
||||
scope: { mediaable: 'entry' },
|
||||
});
|
||||
|
||||
// * MEDIA & People - MANY TO ONE
|
||||
Media.belongsTo(People, {
|
||||
foreignKey: "mediaableId",
|
||||
as: "people",
|
||||
foreignKey: 'mediaableId',
|
||||
as: 'people',
|
||||
constraints: false,
|
||||
where: {
|
||||
mediaable: "people",
|
||||
mediaable: 'people',
|
||||
},
|
||||
});
|
||||
|
||||
People.hasMany(Media, {
|
||||
foreignKey: "mediaableId",
|
||||
foreignKey: 'mediaableId',
|
||||
constraints: false,
|
||||
as: "medias",
|
||||
scope: { mediaable: "people" },
|
||||
as: 'medias',
|
||||
scope: { mediaable: 'people' },
|
||||
});
|
||||
|
||||
// * MEDIA & Collection - MANY TO ONE
|
||||
Media.belongsTo(Collection, {
|
||||
foreignKey: "mediaableId",
|
||||
as: "collection",
|
||||
foreignKey: 'mediaableId',
|
||||
as: 'collection',
|
||||
constraints: false,
|
||||
where: {
|
||||
mediaable: "collection",
|
||||
mediaable: 'collection',
|
||||
},
|
||||
});
|
||||
|
||||
Collection.hasMany(Media, {
|
||||
foreignKey: "mediaableId",
|
||||
foreignKey: 'mediaableId',
|
||||
constraints: false,
|
||||
as: "medias",
|
||||
scope: { mediaable: "collection" },
|
||||
as: 'medias',
|
||||
scope: { mediaable: 'collection' },
|
||||
});
|
||||
|
||||
// * MEDIA & Season - MANY TO ONE
|
||||
Media.belongsTo(Season, {
|
||||
foreignKey: "mediaableId",
|
||||
as: "season",
|
||||
foreignKey: 'mediaableId',
|
||||
as: 'season',
|
||||
constraints: false,
|
||||
where: {
|
||||
mediaable: "season",
|
||||
mediaable: 'season',
|
||||
},
|
||||
});
|
||||
|
||||
Season.hasMany(Media, {
|
||||
foreignKey: "mediaableId",
|
||||
foreignKey: 'mediaableId',
|
||||
constraints: false,
|
||||
as: "medias",
|
||||
scope: { mediaable: "season" },
|
||||
as: 'medias',
|
||||
scope: { mediaable: 'season' },
|
||||
});
|
||||
|
||||
// * MEDIA & Episode - MANY TO ONE
|
||||
Media.belongsTo(Episode, {
|
||||
foreignKey: "mediaableId",
|
||||
as: "episode",
|
||||
foreignKey: 'mediaableId',
|
||||
as: 'episode',
|
||||
constraints: false,
|
||||
where: {
|
||||
mediaable: "episode",
|
||||
mediaable: 'episode',
|
||||
},
|
||||
});
|
||||
|
||||
Episode.hasMany(Media, {
|
||||
foreignKey: "mediaableId",
|
||||
foreignKey: 'mediaableId',
|
||||
constraints: false,
|
||||
as: "medias",
|
||||
scope: { mediaable: "episode" },
|
||||
as: 'medias',
|
||||
scope: { mediaable: 'episode' },
|
||||
});
|
||||
// ! MEDIA END
|
||||
|
||||
// * ENTRY & SEASON - ONE TO MANY
|
||||
Entry.hasMany(Season, {
|
||||
foreignKey: "entry_id",
|
||||
as: "seasons",
|
||||
onDelete: "CASCADE",
|
||||
foreignKey: 'entry_id',
|
||||
as: 'seasons',
|
||||
onDelete: 'CASCADE',
|
||||
});
|
||||
Season.belongsTo(Entry, { foreignKey: "entry_id", as: "entry" });
|
||||
Season.belongsTo(Entry, { foreignKey: 'entry_id', as: 'entry' });
|
||||
|
||||
// * SEASON & EPISODE - ONE TO MANY
|
||||
Season.hasMany(Episode, { foreignKey: "season_id", onDelete: "CASCADE" });
|
||||
Episode.belongsTo(Season, { foreignKey: "season_id" });
|
||||
Season.hasMany(Episode, { foreignKey: 'season_id', onDelete: 'CASCADE' });
|
||||
Episode.belongsTo(Season, { foreignKey: 'season_id' });
|
||||
|
||||
// * EPISODE & EPISODE_SEEN - ONE TO MANY
|
||||
Episode.hasMany(EpisodeSeen, { foreignKey: "episode_id", onDelete: "CASCADE" });
|
||||
EpisodeSeen.belongsTo(Episode, { foreignKey: "episode_id" });
|
||||
Episode.hasMany(EpisodeSeen, { foreignKey: 'episode_id', onDelete: 'CASCADE' });
|
||||
EpisodeSeen.belongsTo(Episode, { foreignKey: 'episode_id' });
|
||||
|
||||
// * ENTRY & EPISODE_SEEN - ONE TO MANY
|
||||
Entry.hasMany(EpisodeSeen, { foreignKey: "entry_id", onDelete: "CASCADE" });
|
||||
EpisodeSeen.belongsTo(Entry, { foreignKey: "entry_id" });
|
||||
Entry.hasMany(EpisodeSeen, { foreignKey: 'entry_id', onDelete: 'CASCADE' });
|
||||
EpisodeSeen.belongsTo(Entry, { foreignKey: 'entry_id' });
|
||||
|
||||
// * ----
|
||||
Franchise.hasMany(Entry, { foreignKey: "franchise_id" });
|
||||
Entry.belongsTo(Franchise, { foreignKey: "franchise_id" });
|
||||
Franchise.hasMany(Entry, { foreignKey: 'franchise_id' });
|
||||
Entry.belongsTo(Franchise, { foreignKey: 'franchise_id' });
|
||||
|
||||
// * ENTRY & Credit - ONE TO MANY
|
||||
Entry.hasMany(Credit, {
|
||||
foreignKey: "entry_id",
|
||||
as: "credits",
|
||||
onDelete: "CASCADE",
|
||||
foreignKey: 'entry_id',
|
||||
as: 'credits',
|
||||
onDelete: 'CASCADE',
|
||||
});
|
||||
Credit.belongsTo(Entry, { foreignKey: "entry_id", as: "entry" });
|
||||
Credit.belongsTo(Entry, { foreignKey: 'entry_id', as: 'entry' });
|
||||
|
||||
// * PEOPLE & CAST - ONE TO MANY
|
||||
People.hasMany(Credit, {
|
||||
foreignKey: "people_id",
|
||||
as: "roles",
|
||||
onDelete: "CASCADE",
|
||||
foreignKey: 'people_id',
|
||||
as: 'roles',
|
||||
onDelete: 'CASCADE',
|
||||
});
|
||||
Credit.belongsTo(People, { foreignKey: 'people_id', as: 'person' });
|
||||
|
||||
// * WATCH BUDDY — MEDIA (profile picture)
|
||||
WatchBuddy.hasMany(Media, {
|
||||
foreignKey: 'mediaableId',
|
||||
constraints: false,
|
||||
as: 'medias',
|
||||
scope: { mediaable: 'watch_buddy' },
|
||||
});
|
||||
Media.belongsTo(WatchBuddy, {
|
||||
foreignKey: 'mediaableId',
|
||||
as: 'watchBuddy',
|
||||
constraints: false,
|
||||
where: { mediaable: 'watch_buddy' },
|
||||
});
|
||||
|
||||
// * ENTRY_SEEN & WATCH_BUDDY - MANY TO MANY
|
||||
EntrySeen.belongsToMany(WatchBuddy, {
|
||||
through: EntrySeenBuddy,
|
||||
foreignKey: 'entry_seen_id',
|
||||
otherKey: 'watch_buddy_id',
|
||||
as: 'buddies',
|
||||
});
|
||||
WatchBuddy.belongsToMany(EntrySeen, {
|
||||
through: EntrySeenBuddy,
|
||||
foreignKey: 'watch_buddy_id',
|
||||
otherKey: 'entry_seen_id',
|
||||
as: 'entrySeens',
|
||||
});
|
||||
|
||||
// * EPISODE_SEEN & WATCH_BUDDY - MANY TO MANY
|
||||
EpisodeSeen.belongsToMany(WatchBuddy, {
|
||||
through: EpisodeSeenBuddy,
|
||||
foreignKey: 'episode_seen_id',
|
||||
otherKey: 'watch_buddy_id',
|
||||
as: 'buddies',
|
||||
});
|
||||
WatchBuddy.belongsToMany(EpisodeSeen, {
|
||||
through: EpisodeSeenBuddy,
|
||||
foreignKey: 'watch_buddy_id',
|
||||
otherKey: 'episode_seen_id',
|
||||
as: 'episodeSeens',
|
||||
});
|
||||
Credit.belongsTo(People, { foreignKey: "people_id", as: "person" });
|
||||
Reference in new issue
Block a user