Normalize to double quotes across all files with Prettier

This commit is contained in:
X4Lo committed 2026-06-21 22:28:08 +01:00
1 parent 73bff72cec
commit a5659cf4c8
190 files changed
+9523 -8859

No files matched your search

+170 -112
View File
@@ -1,24 +1,23 @@
const { Sequelize } = require('sequelize');
const Collection = require('../models/Collection');
const UserCollectionEntry = require('../models/UserCollectionEntry');
const Entry = require('../models/Entry');
const EntryId = require('../models/EntryId');
const EntryRating = require('../models/EntryRating');
const Season = require('../models/Season');
const Genre = require('../models/Genre');
const Media = require('../models/Media');
const { Sequelize } = require("sequelize");
const Collection = require("../models/Collection");
const UserCollectionEntry = require("../models/UserCollectionEntry");
const Entry = require("../models/Entry");
const EntryId = require("../models/EntryId");
const EntryRating = require("../models/EntryRating");
const Season = require("../models/Season");
const Genre = require("../models/Genre");
const Media = require("../models/Media");
const { logToFile } = require('../services/logService');
const collectionManager = require('../services/collectionManager');
const mediaOptimizerService = require('../services/mediaOptimizerService');
const collectionService = require('../services/collectionService');
const { logToFile } = require("../services/logService");
const collectionManager = require("../services/collectionManager");
const mediaOptimizerService = require("../services/mediaOptimizerService");
const collectionService = require("../services/collectionService");
const _mediaOptimizerService = mediaOptimizerService;
const _collectionManager = collectionManager;
const _collectionService = collectionService;
class CollectionController {
constructor() {
if (!CollectionController.instance) {
CollectionController.instance = this;
@@ -41,37 +40,41 @@ class CollectionController {
include: [
{
model: Entry,
as: 'entries',
as: "entries",
include: [
{ model: EntryId, as: 'entryId' },
{ model: EntryRating, as: 'entryRating' },
{ model: Season, as: 'seasons' },
{ model: Media, as: 'medias' },
{ model: Genre, as: 'genres' },
{ model: EntryId, as: "entryId" },
{ model: EntryRating, as: "entryRating" },
{ model: Season, as: "seasons" },
{ model: Media, as: "medias" },
{ model: Genre, as: "genres" },
],
through: {
model: UserCollectionEntry,
attributes: ['order'], // attributes (to include) from the join model
attributes: ["order"], // attributes (to include) from the join model
},
},
{ model: Media, as: 'medias' },
{ model: Media, as: "medias" },
],
order: [[Sequelize.literal("`entries->UserCollectionEntry`.`order`"), 'ASC']], // sort by 'order' in ascending order
order: [
[Sequelize.literal("`entries->UserCollectionEntry`.`order`"), "ASC"],
], // sort by 'order' in ascending order
});
if (collection) {
const collectionData = collection.get({ plain: true });
for (let i = 0; i < collectionData.entries.length; i++) {
const genres = collectionData.entries[i].genres.map(genre => genre.name);
collectionData.entries[i].genres = genres
const genres = collectionData.entries[i].genres.map(
(genre) => genre.name,
);
collectionData.entries[i].genres = genres;
}
res.status(200).json(collectionData);
} else {
res.status(404).json({ message: 'UserCollection not found' });
res.status(404).json({ message: "UserCollection not found" });
}
} catch (error) {
console.log(`Error getting collection info: `, error)
console.log(`Error getting collection info: `, error);
res.status(500).json({ error: error.message });
}
}
@@ -81,7 +84,13 @@ class CollectionController {
try {
const { name, description, userRating, posterPath } = req.body;
const isUserCollection = true;
const newUserCollection = await Collection.create({ name, description, userRating, posterPath, isUserCollection });
const newUserCollection = await Collection.create({
name,
description,
userRating,
posterPath,
isUserCollection,
});
res.status(201).json(newUserCollection);
} catch (error) {
res.status(400).json({ error: error.message });
@@ -95,7 +104,9 @@ class CollectionController {
const { name, description, userRating } = req.body;
const posterFile = req.files.poster ? req.files.poster[0] : undefined;
const backdropFile = req.files.backdrop ? req.files.backdrop[0] : undefined;
const backdropFile = req.files.backdrop
? req.files.backdrop[0]
: undefined;
let posterPath = posterFile ? posterFile.filename : undefined;
let backdropPath = backdropFile ? backdropFile.filename : undefined;
@@ -109,90 +120,113 @@ class CollectionController {
if (posterPath) {
// ? generating preview
_mediaOptimizerService.doGeneratePreview("collections", 'posters', posterPath).then((result) => {
const msg = `Collection Service | Generated Collection Preview`;
logToFile(msg);
}).catch((err) => {
const msg = `Collection Service | Error Generating Collection Preview`;
logToFile(msg);
logToFile(err);
});
_mediaOptimizerService
.doGeneratePreview("collections", "posters", posterPath)
.then((result) => {
const msg = `Collection Service | Generated Collection Preview`;
logToFile(msg);
})
.catch((err) => {
const msg = `Collection Service | Error Generating Collection Preview`;
logToFile(msg);
logToFile(err);
});
// Deselect existing posters for this collection
await Media.update(
{ isSelected: false },
{ where: { mediaable: 'collection', mediaableId: collectionId, type: 'poster', isSelected: true } }
{
where: {
mediaable: "collection",
mediaableId: collectionId,
type: "poster",
isSelected: true,
},
},
);
await Media.create({
mediaable: 'collection',
mediaable: "collection",
mediaableId: collectionId,
type: 'poster',
type: "poster",
path: posterPath,
isLocal: true,
isSelected: true,
isCustom: true
})
isCustom: true,
});
}
if (backdropPath) {
// ? generating preview
_mediaOptimizerService.doGeneratePreview("collections", 'backdrops', backdropPath).then((result) => {
const msg = `Collection Routes | Generated Collection Preview`;
logToFile(msg);
}).catch((err) => {
const msg = `Collection Routes | Error Generating Collection Preview`;
logToFile(msg);
logToFile(err);
});
_mediaOptimizerService
.doGeneratePreview("collections", "backdrops", backdropPath)
.then((result) => {
const msg = `Collection Routes | Generated Collection Preview`;
logToFile(msg);
})
.catch((err) => {
const msg = `Collection Routes | Error Generating Collection Preview`;
logToFile(msg);
logToFile(err);
});
// Deselect existing backdrops for this collection
await Media.update(
{ isSelected: false },
{ where: { mediaable: 'collection', mediaableId: collectionId, type: 'backdrop', isSelected: true } }
{
where: {
mediaable: "collection",
mediaableId: collectionId,
type: "backdrop",
isSelected: true,
},
},
);
// ? inserting data
await Media.create({
mediaable: 'collection',
mediaable: "collection",
mediaableId: collectionId,
type: 'backdrop',
type: "backdrop",
path: backdropPath,
isLocal: true,
isSelected: true,
isCustom: true
})
isCustom: true,
});
}
const oldCollection = await Collection.findByPk(collectionId, {
include: [{
model: Entry,
as: 'entries',
include: [
{ model: EntryId, as: 'entryId' },
{ model: EntryRating, as: 'entryRating' },
{ model: Season, as: 'seasons' },
{ model: Media, as: 'medias' },
{ model: Genre, as: 'genres' },
],
through: {
model: UserCollectionEntry,
attributes: ['order'], // attributes (to include) from the join model
include: [
{
model: Entry,
as: "entries",
include: [
{ model: EntryId, as: "entryId" },
{ model: EntryRating, as: "entryRating" },
{ model: Season, as: "seasons" },
{ model: Media, as: "medias" },
{ model: Genre, as: "genres" },
],
through: {
model: UserCollectionEntry,
attributes: ["order"], // attributes (to include) from the join model
},
},
},
{ model: Media, as: 'medias' },
{ model: Media, as: "medias" },
],
order: [[Sequelize.literal("`entries->UserCollectionEntry`.`order`"), 'ASC']], // sort by 'order' in ascending order
order: [
[Sequelize.literal("`entries->UserCollectionEntry`.`order`"), "ASC"],
], // sort by 'order' in ascending order
});
if (!oldCollection)
res.status(404).json({ message: 'Collection not found' });
res.status(404).json({ message: "Collection not found" });
await oldCollection.update(updateData);
res.status(200).json(oldCollection);
} catch (error) {
console.log(`UserCollection update (put) error: `, error)
console.log(`UserCollection update (put) error: `, error);
res.status(500).json({ error: error.message });
}
}
@@ -202,21 +236,25 @@ class CollectionController {
const collectionId = req.params.id;
const oldCollection = await Collection.findByPk(collectionId);
const collection = await _collectionManager.fetchAndSaveCollection(oldCollection.tmdbId);
const collection = await _collectionManager.fetchAndSaveCollection(
oldCollection.tmdbId,
);
if (collection) {
const collectionData = collection.get({ plain: true });
for (let i = 0; i < collectionData.entries.length; i++) {
const genres = collectionData.entries[i].genres.map(genre => genre.name);
collectionData.entries[i].genres = genres
const genres = collectionData.entries[i].genres.map(
(genre) => genre.name,
);
collectionData.entries[i].genres = genres;
}
res.status(200).json(collectionData);
} else {
res.status(404).json({ message: 'Collection not found' });
res.status(404).json({ message: "Collection not found" });
}
} catch (error) {
console.log(`UserCollection update (put) error: `, error)
console.log(`UserCollection update (put) error: `, error);
res.status(500).json({ error: error.message });
}
}
@@ -231,37 +269,41 @@ class CollectionController {
include: [
{
model: Entry,
as: 'entries',
as: "entries",
include: [
{ model: EntryId, as: 'entryId' },
{ model: EntryRating, as: 'entryRating' },
{ model: Season, as: 'seasons' },
{ model: Media, as: 'medias' },
{ model: Genre, as: 'genres' },
{ model: EntryId, as: "entryId" },
{ model: EntryRating, as: "entryRating" },
{ model: Season, as: "seasons" },
{ model: Media, as: "medias" },
{ model: Genre, as: "genres" },
],
through: {
model: UserCollectionEntry,
attributes: ['order'], // attributes (to include) from the join model
attributes: ["order"], // attributes (to include) from the join model
},
},
{ model: Media, as: 'medias' },
{ model: Media, as: "medias" },
],
order: [[Sequelize.literal("`entries->UserCollectionEntry`.`order`"), 'ASC']], // sort by 'order' in ascending order
order: [
[Sequelize.literal("`entries->UserCollectionEntry`.`order`"), "ASC"],
], // sort by 'order' in ascending order
});
if (collection) {
const collectionData = collection.get({ plain: true });
for (let i = 0; i < collectionData.entries.length; i++) {
const genres = collectionData.entries[i].genres.map(genre => genre.name);
collectionData.entries[i].genres = genres
const genres = collectionData.entries[i].genres.map(
(genre) => genre.name,
);
collectionData.entries[i].genres = genres;
}
res.status(200).json(collectionData);
} else {
res.status(404).json({ message: 'Collection not found' });
res.status(404).json({ message: "Collection not found" });
}
} catch (error) {
console.log(`UserCollection update (put) error: `, error)
console.log(`UserCollection update (put) error: `, error);
res.status(500).json({ error: error.message });
}
}
@@ -269,11 +311,13 @@ class CollectionController {
// todo: move to collection service
async deleteCollection(req, res) {
try {
const deleted = await Collection.destroy({ where: { id: req.params.id } });
const deleted = await Collection.destroy({
where: { id: req.params.id },
});
if (deleted) {
res.status(204).send();
} else {
res.status(404).json({ message: 'UserCollection not found' });
res.status(404).json({ message: "UserCollection not found" });
}
} catch (error) {
res.status(500).json({ error: error.message });
@@ -287,12 +331,15 @@ class CollectionController {
const newUserCollectionEntry = await UserCollectionEntry.create({
user_collection_id: collectionId,
entry_id: entryId
entry_id: entryId,
});
// ? set a default poster if none exists
const userCollection = await Collection.findByPk(collectionId);
if (!userCollection.poster_path || userCollection.poster_path.trim() == '') {
if (
!userCollection.poster_path ||
userCollection.poster_path.trim() == ""
) {
const entry = await Entry.findByPk(entryId);
userCollection.poster_path = entry.poster_path;
await userCollection.save();
@@ -300,7 +347,7 @@ class CollectionController {
res.status(201).json(newUserCollectionEntry);
} catch (error) {
console.log(error)
console.log(error);
res.status(400).json({ error: error.message });
}
}
@@ -315,18 +362,20 @@ class CollectionController {
const collectionEntry = await UserCollectionEntry.findOne({
where: {
user_collection_id: collectionId,
entry_id: entryId
}
entry_id: entryId,
},
});
if (!collectionEntry) {
res.status(404).json({ message: 'UserCollectionEntry not found.' });
res.status(404).json({ message: "UserCollectionEntry not found." });
}
// ? updating
await collectionEntry.update({ order: newOrder });
res.status(200).json({ message: 'UserCollectionEntry order updated successfully.' });
res
.status(200)
.json({ message: "UserCollectionEntry order updated successfully." });
} catch (error) {
console.log(`Error Updating UserCollectionEntry order: `, error);
res.status(500).json({ error: error.message });
@@ -340,15 +389,15 @@ class CollectionController {
const deleted = await UserCollectionEntry.findOne({
where: {
user_collection_id: collectionId,
entry_id: entryId
}
entry_id: entryId,
},
});
if (deleted) {
await deleted.destroy();
res.status(204).send();
} else {
res.status(404).json({ message: 'CollectionEntry not found.' });
res.status(404).json({ message: "CollectionEntry not found." });
}
} catch (error) {
res.status(500).json({ error: error.message });
@@ -362,14 +411,19 @@ class CollectionController {
try {
const result = await sequelize.transaction(async (t) => {
// Step 1: Create the userCollection
const newUserCollection = await Collection.create(listDetails, { transaction: t });
const newUserCollection = await Collection.create(listDetails, {
transaction: t,
});
// Step 2: Add an entry to the newly created userCollection
const newUserCollectionEntry = await UserCollectionEntry.create({
userCollectionId: newUserCollection.id,
entryId: entryId,
entryOrder: entryOrder
}, { transaction: t });
const newUserCollectionEntry = await UserCollectionEntry.create(
{
userCollectionId: newUserCollection.id,
entryId: entryId,
entryOrder: entryOrder,
},
{ transaction: t },
);
return { newUserCollection, newUserCollectionEntry };
});
@@ -377,11 +431,15 @@ class CollectionController {
// If the transaction is successful, send back the created userCollection and entry relationship
res.status(201).json(result);
} catch (error) {
console.error('Failed to create userCollection and add entry:', error);
res.status(500).json({ message: 'Failed to create userCollection and add entry', error: error.message });
console.error("Failed to create userCollection and add entry:", error);
res
.status(500)
.json({
message: "Failed to create userCollection and add entry",
error: error.message,
});
}
}
}
module.exports = new CollectionController();