This commit is contained in:
X4Lo committed 2024-04-21 17:05:48 +01:00
commit cf305cabae
5 files changed
+76 -5

No files matched your search

+63
View File
@@ -0,0 +1,63 @@
const Genre = require("../models/Genre");
async function initializeData() {
initializeGenres();
}
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,
}
+1 -1
View File
@@ -5,7 +5,7 @@ const Entry = sequelize.define("entry",
{
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
title: { type: DataTypes.STRING(50) },
title: { type: DataTypes.STRING(100) },
original_title: { type: DataTypes.STRING(50) },
release_date: { type: DataTypes.DATE },
runtime: { type: DataTypes.INTEGER },
+1 -1
View File
@@ -17,7 +17,7 @@ const Episode = sequelize.define("episode",
}
},
name: { type: DataTypes.STRING(30) },
name: { type: DataTypes.STRING(100) },
overview: { type: DataTypes.STRING(1000) },
episode_number: { type: DataTypes.INTEGER },
episode_type: { type: DataTypes.STRING(60) },
+4 -1
View File
@@ -29,13 +29,16 @@ app.use((req, res, next) => {
app.use('/api/v1', routes);
// Start the server
const relations = require('./db/relations.js')
const relations = require('./db/relations.js');
const { initializeGenres, initializeData } = require('./db/dataInitializer.js');
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.
.sync()
.then((result) => {
initializeData();
app.listen(PORT, () => {
//const Entry = require("./models/Entry.js")
console.log(`Backend server running on http://localhost:${PORT}`);
@@ -40,7 +40,8 @@
</h2>
<div id="collapse{{seen.id}}" class="accordion-collapse collapse"
[attr.aria-labelledby]="'heading' + seen.id" data-bs-parent="#accordionWatchHistory">
<div class="accordion-body"> <strong>Seen With:</strong><br>Person1, person 2</div>
<div class="accordion-body"> <strong>Seen With:</strong><br>{{seen.seen_with.split(", ").join("\n")}}
</div>
<div class="d-flex justify-content-end">
<button type="button" class="btn btn-icon-only">
<span class="material-symbols-outlined" (click)="removeEntrySeen(seen.id)">
@@ -66,7 +67,7 @@
<!-- Interraction buttons -->
<div class="row">
<button class="btn btn-icon-only-success wh-48" (click)="openDialog()">
<button class="btn btn-icon-only-success wh-48" *ngIf="!entry.is_tvseries" (click)="openDialog()">
<span class="material-symbols-outlined">
visibility
</span>
@@ -116,6 +117,10 @@
<div class="row">
<h3>Cast</h3>
</div>
<div class="row">
<h3>Collections</h3>
</div>
</div>