86 lines
2.3 KiB
JavaScript
86 lines
2.3 KiB
JavaScript
const { Sequelize } = require("sequelize");
|
|
const Collection = require("../models/Collection");
|
|
const Genre = require("../models/Genre");
|
|
const Media = require("../models/Media");
|
|
|
|
|
|
async function initializeData() {
|
|
initializeGenres();
|
|
|
|
|
|
// const collections = await Collection.findAll({
|
|
// where: {
|
|
// posterPath: { [Sequelize.Op.notLike]: '/%' }
|
|
// }
|
|
// });
|
|
|
|
// collections.forEach(collection => {
|
|
// Media.create({
|
|
// mediaable: 'collection',
|
|
// mediaableId: collection.id,
|
|
// type: 'poster',
|
|
// path: collection.posterPath,
|
|
// isLocal: true,
|
|
// isSelected: true
|
|
// })
|
|
// });
|
|
|
|
// console.log(collections);
|
|
}
|
|
|
|
async function initializeGenres() {
|
|
try {
|
|
// * data to insert:
|
|
const initialGenres = [
|
|
{ id: 10759, name: 'Action & Adventure' },
|
|
{ id: 16, name: 'Animation' },
|
|
{ id: 35, name: 'Comedy' },
|
|
{ id: 80, name: 'Crime' },
|
|
{ id: 99, name: 'Documentary' },
|
|
{ id: 18, name: 'Drama' },
|
|
{ id: 10751, name: 'Family' },
|
|
{ id: 10762, name: 'Kids' },
|
|
{ id: 9648, name: 'Mystery' },
|
|
{ id: 10763, name: 'News' },
|
|
{ id: 10764, name: 'Reality' },
|
|
{ id: 10765, name: 'Sci-Fi & Fantasy' },
|
|
{ id: 10766, name: 'Soap' },
|
|
{ id: 10767, name: 'Talk' },
|
|
{ id: 10768, name: 'War & Politics' },
|
|
{ id: 37, name: 'Western' },
|
|
{ id: 28, name: 'Action' },
|
|
{ id: 12, name: 'Adventure' },
|
|
{ id: 14, name: 'Fantasy' },
|
|
{ id: 36, name: 'History' },
|
|
{ id: 27, name: 'Horror' },
|
|
{ id: 10402, name: 'Music' },
|
|
{ id: 10749, name: 'Romance' },
|
|
{ id: 878, name: 'Science Fiction' },
|
|
{ id: 10770, name: 'TV Movie' },
|
|
{ id: 53, name: 'Thriller' },
|
|
{ id: 10752, name: 'War' }
|
|
];
|
|
|
|
// * Check if the data already exists
|
|
const existingGenres = await Genre.findAll();
|
|
|
|
// ? If data already exists, return
|
|
if (existingGenres.length == initialGenres.length) {
|
|
console.log('Genres already initialized');
|
|
return;
|
|
}
|
|
|
|
// ? If data doesn't exist, insert initial data
|
|
await Genre.bulkCreate(initialGenres);
|
|
|
|
console.log(`${initialGenres.length} Genres initialized successfully`);
|
|
} catch (error) {
|
|
console.error('Error initializing data:', error);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
initializeData,
|
|
|
|
initializeGenres,
|
|
} |