Normalize to double quotes across all files with Prettier
This commit is contained in:
1 parent
73bff72cec
commit
a5659cf4c8
190 files changed
+9523
-8859
No files matched your search
@@ -1,17 +1,17 @@
|
||||
// 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 UserCollection = 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 sequelize = require('./database');
|
||||
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 UserCollection = 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 sequelize = require("./database");
|
||||
|
||||
// ! Hooks
|
||||
// ? user collections
|
||||
@@ -19,22 +19,27 @@ const sequelize = require('./database');
|
||||
UserCollectionEntry.afterCreate(async (instance, options) => {
|
||||
try {
|
||||
// ? mimicking a change in UserCollection to trigger updatedAt property update for the UserCollection
|
||||
const userCollections = await UserCollection.findByPk(instance.user_collection_id);
|
||||
const userCollections = await UserCollection.findByPk(
|
||||
instance.user_collection_id,
|
||||
);
|
||||
await userCollections.update({
|
||||
name: sequelize.literal('name')
|
||||
name: sequelize.literal("name"),
|
||||
});
|
||||
const userCollectionEntriesCount = await UserCollectionEntry.count({
|
||||
where: {
|
||||
user_collection_id: instance.user_collection_id
|
||||
}
|
||||
})
|
||||
user_collection_id: instance.user_collection_id,
|
||||
},
|
||||
});
|
||||
|
||||
// ? updating newly create UserCollectionEntry order
|
||||
await instance.update({
|
||||
order: userCollectionEntriesCount
|
||||
})
|
||||
order: userCollectionEntriesCount,
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(`Sequelize Hook Error: UserCollectionEntry.afterCreate: `, error)
|
||||
console.log(
|
||||
`Sequelize Hook Error: UserCollectionEntry.afterCreate: `,
|
||||
error,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -42,53 +47,64 @@ UserCollectionEntry.afterCreate(async (instance, options) => {
|
||||
UserCollectionEntry.afterUpdate(async (instance, options) => {
|
||||
try {
|
||||
// ? mimicking a change in UserCollection to trigger updatedAt property update for the UserCollection
|
||||
const userCollections = await UserCollection.findByPk(instance.user_collection_id);
|
||||
const userCollections = await UserCollection.findByPk(
|
||||
instance.user_collection_id,
|
||||
);
|
||||
await userCollections.update({
|
||||
name: sequelize.literal('name')
|
||||
name: sequelize.literal("name"),
|
||||
});
|
||||
|
||||
// ? updating other entries order
|
||||
const collectionEntries = await UserCollectionEntry.findAll({
|
||||
where: {
|
||||
user_collection_id: instance.user_collection_id
|
||||
user_collection_id: instance.user_collection_id,
|
||||
},
|
||||
order: [['order', 'ASC']]
|
||||
})
|
||||
order: [["order", "ASC"]],
|
||||
});
|
||||
|
||||
// * changing the order of all entries that are now after the updated entry
|
||||
// * changing the order of all entries that are now after the updated entry
|
||||
let startOrder = instance.order + 1;
|
||||
for (let i = 0; i < collectionEntries.length; i++) {
|
||||
if (collectionEntries[i].order >= instance.order && collectionEntries[i].entry_id != instance.entry_id) {
|
||||
await collectionEntries[i].update({ order: startOrder }, { hooks: false })
|
||||
if (
|
||||
collectionEntries[i].order >= instance.order &&
|
||||
collectionEntries[i].entry_id != instance.entry_id
|
||||
) {
|
||||
await collectionEntries[i].update(
|
||||
{ order: startOrder },
|
||||
{ hooks: false },
|
||||
);
|
||||
startOrder++;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(`Sequelize Hook Error: UserCollectionEntry.afterUpdate: `, error)
|
||||
console.log(
|
||||
`Sequelize Hook Error: UserCollectionEntry.afterUpdate: `,
|
||||
error,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// * entry remove
|
||||
UserCollectionEntry.afterDestroy(async (instance, options) => {
|
||||
try {
|
||||
const userCollection = await UserCollection.findByPk(instance.user_collection_id);
|
||||
const userCollection = await UserCollection.findByPk(
|
||||
instance.user_collection_id,
|
||||
);
|
||||
const entry = await Entry.findByPk(instance.entry_id);
|
||||
|
||||
if (!entry || !userCollection) return;
|
||||
|
||||
// ? mimicking a change to trigger updatedAt property update
|
||||
let updates = {
|
||||
name: sequelize.literal('name')
|
||||
}
|
||||
name: sequelize.literal("name"),
|
||||
};
|
||||
|
||||
const collectionsEntries = await UserCollectionEntry.findAll({
|
||||
where: {
|
||||
user_collection_id: instance.user_collection_id
|
||||
user_collection_id: instance.user_collection_id,
|
||||
},
|
||||
include: [
|
||||
{ model: Entry, as: 'entry' },
|
||||
]
|
||||
})
|
||||
include: [{ model: Entry, as: "entry" }],
|
||||
});
|
||||
|
||||
// ? updating collection poster
|
||||
// ? remove the poster if the collection is empty now
|
||||
@@ -106,16 +122,19 @@ UserCollectionEntry.afterDestroy(async (instance, options) => {
|
||||
if (instance.order != collectionsEntries.length) {
|
||||
for (let i = 0; i < collectionsEntries.length; i++) {
|
||||
if (collectionsEntries[i].order > instance.order) {
|
||||
collectionsEntries[i].update({ order: order }, { hooks: false })
|
||||
collectionsEntries[i].update({ order: order }, { hooks: false });
|
||||
order++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ? updating the collection updatedAt and poster maybe
|
||||
await userCollection.update(updates)
|
||||
await userCollection.update(updates);
|
||||
} catch (error) {
|
||||
console.log(`Sequelize Hook Error: UserCollectionEntry.afterDestroy: `, error)
|
||||
console.log(
|
||||
`Sequelize Hook Error: UserCollectionEntry.afterDestroy: `,
|
||||
error,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -128,22 +147,28 @@ EntrySeen.afterCreate(async (instance, options) => {
|
||||
|
||||
// this will ensure that the entry is updated anyways to trigger the updatedAt property
|
||||
let update = {
|
||||
watchlist: false
|
||||
watchlist: false,
|
||||
};
|
||||
|
||||
// ? comparing the instance.date_seen with the entry date_first_seen &
|
||||
// ? date_last_seen to check if they should be replaced
|
||||
if (!entry.date_first_seen || instance.date_seen < new Date(entry.date_first_seen)) {
|
||||
if (
|
||||
!entry.date_first_seen ||
|
||||
instance.date_seen < new Date(entry.date_first_seen)
|
||||
) {
|
||||
update.date_first_seen = instance.date_seen;
|
||||
}
|
||||
if (!entry.date_last_seen || instance.date_seen > new Date(entry.date_last_seen)) {
|
||||
if (
|
||||
!entry.date_last_seen ||
|
||||
instance.date_seen > new Date(entry.date_last_seen)
|
||||
) {
|
||||
update.date_last_seen = instance.date_seen;
|
||||
}
|
||||
|
||||
// * updating the entry
|
||||
await entry.update(update);
|
||||
} catch (error) {
|
||||
console.log(`Sequelize Hook Error: EntrySeen.afterCreate: `, error)
|
||||
console.log(`Sequelize Hook Error: EntrySeen.afterCreate: `, error);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -158,11 +183,9 @@ EntrySeen.afterUpdate(async (instance, options) => {
|
||||
// ? and the last one to: date_last_seen
|
||||
const entrySeens = await EntrySeen.findAll({
|
||||
where: {
|
||||
entry_id: instance.entry_id
|
||||
entry_id: instance.entry_id,
|
||||
},
|
||||
order: [
|
||||
['date_seen', 'ASC']
|
||||
]
|
||||
order: [["date_seen", "ASC"]],
|
||||
});
|
||||
|
||||
let update = {};
|
||||
@@ -172,7 +195,7 @@ EntrySeen.afterUpdate(async (instance, options) => {
|
||||
// * updating the entry
|
||||
await entry.update(update);
|
||||
} catch (error) {
|
||||
console.log(`Sequelize Hook Error: EntrySeen.afterUpdate: `, error)
|
||||
console.log(`Sequelize Hook Error: EntrySeen.afterUpdate: `, error);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -187,11 +210,9 @@ EntrySeen.afterDestroy(async (instance, options) => {
|
||||
// ? and the last one to: date_last_seen
|
||||
const entrySeens = await EntrySeen.findAll({
|
||||
where: {
|
||||
entry_id: instance.entry_id
|
||||
entry_id: instance.entry_id,
|
||||
},
|
||||
order: [
|
||||
['date_seen', 'ASC']
|
||||
]
|
||||
order: [["date_seen", "ASC"]],
|
||||
});
|
||||
|
||||
let update = {};
|
||||
@@ -209,7 +230,7 @@ EntrySeen.afterDestroy(async (instance, options) => {
|
||||
// * updating the entry
|
||||
await entry.update(update);
|
||||
} catch (error) {
|
||||
console.log(`Sequelize Hook Error: EntrySeen.afterUpdate: `, error)
|
||||
console.log(`Sequelize Hook Error: EntrySeen.afterUpdate: `, error);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -224,15 +245,21 @@ EpisodeSeen.afterCreate(async (instance, options) => {
|
||||
// this will ensure that the entry is updated anyways to trigger the updatedAt property
|
||||
let update = {
|
||||
// title: sequelize.literal('title')
|
||||
watchlist: false
|
||||
watchlist: false,
|
||||
};
|
||||
|
||||
// ? comparing the instance.date_seen with the entry date_first_seen &
|
||||
// ? date_last_seen to check if they should be replaced
|
||||
if (!entry.date_first_seen || instance.date_seen < new Date(entry.date_first_seen)) {
|
||||
if (
|
||||
!entry.date_first_seen ||
|
||||
instance.date_seen < new Date(entry.date_first_seen)
|
||||
) {
|
||||
update.date_first_seen = instance.date_seen;
|
||||
}
|
||||
if (!entry.date_last_seen || instance.date_seen > new Date(entry.date_last_seen)) {
|
||||
if (
|
||||
!entry.date_last_seen ||
|
||||
instance.date_seen > new Date(entry.date_last_seen)
|
||||
) {
|
||||
update.date_last_seen = instance.date_seen;
|
||||
}
|
||||
|
||||
@@ -245,22 +272,28 @@ EpisodeSeen.afterCreate(async (instance, options) => {
|
||||
|
||||
// this will ensure that the episode is updated anyways to trigger the updatedAt property
|
||||
let episodeUpdate = {
|
||||
name: sequelize.literal('name')
|
||||
name: sequelize.literal("name"),
|
||||
};
|
||||
|
||||
// ? comparing the instance.date_seen with the entry date_first_seen &
|
||||
// ? date_last_seen to check if they should be replaced
|
||||
if (!episode.date_first_seen || instance.date_seen < new Date(episode.date_first_seen)) {
|
||||
if (
|
||||
!episode.date_first_seen ||
|
||||
instance.date_seen < new Date(episode.date_first_seen)
|
||||
) {
|
||||
episodeUpdate.date_first_seen = instance.date_seen;
|
||||
}
|
||||
if (!episode.date_last_seen || instance.date_seen > new Date(episode.date_last_seen)) {
|
||||
if (
|
||||
!episode.date_last_seen ||
|
||||
instance.date_seen > new Date(episode.date_last_seen)
|
||||
) {
|
||||
episodeUpdate.date_last_seen = instance.date_seen;
|
||||
}
|
||||
|
||||
// * updating the episode
|
||||
await episode.update(episodeUpdate);
|
||||
} catch (error) {
|
||||
console.log(`Sequelize Hook Error: EpisodeSeen.afterCreate: `, error)
|
||||
console.log(`Sequelize Hook Error: EpisodeSeen.afterCreate: `, error);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -275,22 +308,24 @@ EpisodeSeen.afterUpdate(async (instance, options) => {
|
||||
// ? for the current entry
|
||||
EpisodeSeen.findAll({
|
||||
attributes: [
|
||||
[sequelize.fn('min', sequelize.col('date_seen')), 'minValue'],
|
||||
[sequelize.fn('max', sequelize.col('date_seen')), 'maxValue']
|
||||
[sequelize.fn("min", sequelize.col("date_seen")), "minValue"],
|
||||
[sequelize.fn("max", sequelize.col("date_seen")), "maxValue"],
|
||||
],
|
||||
where: {
|
||||
entry_id: instance.entry_id
|
||||
}
|
||||
}).then(result => {
|
||||
let update = {};
|
||||
entry_id: instance.entry_id,
|
||||
},
|
||||
})
|
||||
.then((result) => {
|
||||
let update = {};
|
||||
|
||||
update.date_first_seen = result[0].dataValues.minValue;
|
||||
update.date_last_seen = result[0].dataValues.maxValue;
|
||||
update.date_first_seen = result[0].dataValues.minValue;
|
||||
update.date_last_seen = result[0].dataValues.maxValue;
|
||||
|
||||
entry.update(update);
|
||||
}).catch(err => {
|
||||
console.error('Error:', err);
|
||||
});
|
||||
entry.update(update);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("Error:", err);
|
||||
});
|
||||
|
||||
// ! updating the episode
|
||||
// ? getting the episode that we just created the episode-seen for
|
||||
@@ -300,22 +335,24 @@ EpisodeSeen.afterUpdate(async (instance, options) => {
|
||||
// ? for the current episode
|
||||
EpisodeSeen.findAll({
|
||||
attributes: [
|
||||
[sequelize.fn('min', sequelize.col('date_seen')), 'minValue'],
|
||||
[sequelize.fn('max', sequelize.col('date_seen')), 'maxValue']
|
||||
[sequelize.fn("min", sequelize.col("date_seen")), "minValue"],
|
||||
[sequelize.fn("max", sequelize.col("date_seen")), "maxValue"],
|
||||
],
|
||||
where: {
|
||||
episode_id: instance.episode_id
|
||||
}
|
||||
}).then(result => {
|
||||
let update = {};
|
||||
update.date_first_seen = result[0].dataValues.minValue;
|
||||
update.date_last_seen = result[0].dataValues.maxValue;
|
||||
episode.update(update);
|
||||
}).catch(err => {
|
||||
console.error('Error:', err);
|
||||
});
|
||||
episode_id: instance.episode_id,
|
||||
},
|
||||
})
|
||||
.then((result) => {
|
||||
let update = {};
|
||||
update.date_first_seen = result[0].dataValues.minValue;
|
||||
update.date_last_seen = result[0].dataValues.maxValue;
|
||||
episode.update(update);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("Error:", err);
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(`Sequelize Hook Error: EpisodeSeen.afterUpdate: `, error)
|
||||
console.log(`Sequelize Hook Error: EpisodeSeen.afterUpdate: `, error);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -331,11 +368,9 @@ EpisodeSeen.afterDestroy(async (instance, options) => {
|
||||
// ? and the last one to: date_last_seen
|
||||
const episodeSeens = await EpisodeSeen.findAll({
|
||||
where: {
|
||||
entry_id: instance.entry_id
|
||||
entry_id: instance.entry_id,
|
||||
},
|
||||
order: [
|
||||
['date_seen', 'ASC']
|
||||
]
|
||||
order: [["date_seen", "ASC"]],
|
||||
});
|
||||
|
||||
let update = {};
|
||||
@@ -362,11 +397,9 @@ EpisodeSeen.afterDestroy(async (instance, options) => {
|
||||
// ? and the last one to: date_last_seen
|
||||
const episodeSeens2 = await EpisodeSeen.findAll({
|
||||
where: {
|
||||
episode_id: instance.episode_id
|
||||
episode_id: instance.episode_id,
|
||||
},
|
||||
order: [
|
||||
['date_seen', 'ASC']
|
||||
]
|
||||
order: [["date_seen", "ASC"]],
|
||||
});
|
||||
|
||||
let episodeUpdate = {};
|
||||
@@ -378,12 +411,13 @@ EpisodeSeen.afterDestroy(async (instance, options) => {
|
||||
episodeUpdate.date_last_seen = null;
|
||||
} else {
|
||||
episodeUpdate.date_first_seen = episodeSeens2[0].date_seen;
|
||||
episodeUpdate.date_last_seen = episodeSeens2[episodeSeens2.length - 1].date_seen;
|
||||
episodeUpdate.date_last_seen =
|
||||
episodeSeens2[episodeSeens2.length - 1].date_seen;
|
||||
}
|
||||
|
||||
// * updating the episode
|
||||
await episode.update(episodeUpdate);
|
||||
} catch (error) {
|
||||
console.log(`Sequelize Hook Error: EpisodeSeen.afterUpdate: `, error)
|
||||
console.log(`Sequelize Hook Error: EpisodeSeen.afterUpdate: `, error);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user