Fix: Linter warnings (#137)

* Automaticly fixable eslint issues, mostly 3 -> 2 space indentation

* fix: updated plex_userid to camelcase

* Linted and some consistency refactor on middleware

* eslint uses ecmaversion 2020 & allow empty catch rule

* Started linting source files

* Fixed eslint errors & improved a lot of error handling

* Set 2 eslint rules as warning temporarly
This commit is contained in:
2022-08-20 17:21:25 +02:00
committed by GitHub
parent cfbd4965db
commit 1815a429b0
83 changed files with 1625 additions and 1294 deletions

View File

@@ -28,15 +28,15 @@ class RequestRepository {
};
}
search(query, type, page) {
return Promise.resolve()
.then(() => tmdb.search(query, type, page))
static search(query, type, page) {
return tmdb
.search(query, type, page)
.catch(error => Error(`error in the house${error}`));
}
lookup(identifier, type = "movie") {
return Promise.resolve()
.then(() => tmdb.lookup(identifier, type))
return tmdb
.lookup(identifier, type)
.then(tmdbMovie => this.checkID(tmdbMovie))
.then(tmdbMovie => plexRepository.inPlex(tmdbMovie))
.catch(error => {
@@ -44,19 +44,17 @@ class RequestRepository {
});
}
checkID(tmdbMovie) {
return Promise.resolve()
.then(() =>
this.database.get(this.queries.checkIfIdRequested, [
tmdbMovie.id,
tmdbMovie.type
])
)
checkID(_tmdbMovie) {
const tmdbMovie = _tmdbMovie;
return this.database
.get(this.queries.checkIfIdRequested, [tmdbMovie.id, tmdbMovie.type])
.then((result, error) => {
if (error) {
throw new Error(error);
}
tmdbMovie.requested = result ? true : false;
tmdbMovie.requested = !!result;
return tmdbMovie;
});
}
@@ -66,45 +64,42 @@ class RequestRepository {
* @param {identifier, type} the id of the media object and type of media must be defined
* @returns {Promise} If nothing has gone wrong.
*/
sendRequest(identifier, type, ip, user_agent, user) {
return Promise.resolve()
.then(() => tmdb.lookup(identifier, type))
.then(movie => {
const username = user === undefined ? undefined : user.username;
// Add request to database
return this.database.run(this.queries.insertRequest, [
movie.id,
movie.title,
movie.year,
movie.poster_path,
movie.background_path,
username,
ip,
user_agent,
movie.type
]);
});
}
fetchRequested(status, page = "1", type = "%") {
return Promise.resolve().then(() => {
if (
status === "requested" ||
status === "downloading" ||
status === "downloaded"
)
return this.database.all(this.queries.fetchRequestedItemsByStatus, [
status,
type,
page
]);
else return this.database.all(this.queries.fetchRequestedItems, page);
sendRequest(identifier, type, ip, userAgent, user) {
return tmdb.lookup(identifier, type).then(movie => {
const username = user === undefined ? undefined : user.username;
// Add request to database
return this.database.run(this.queries.insertRequest, [
movie.id,
movie.title,
movie.year,
movie.poster_path,
movie.background_path,
username,
ip,
userAgent,
movie.type
]);
});
}
fetchRequested(status, page = "1", type = "%") {
if (
status === "requested" ||
status === "downloading" ||
status === "downloaded"
)
return this.database.all(this.queries.fetchRequestedItemsByStatus, [
status,
type,
page
]);
return this.database.all(this.queries.fetchRequestedItems, page);
}
userRequests(username) {
return Promise.resolve()
.then(() => this.database.all(this.queries.userRequests, username))
return this.database
.all(this.queries.userRequests, username)
.catch(error => {
if (String(error).includes("no such column")) {
throw new Error("Username not found");
@@ -113,8 +108,11 @@ class RequestRepository {
})
.then(result => {
// TODO do a correct mapping before sending, not just a dump of the database
result.map(item => (item.poster = item.poster_path));
return result;
return result.map(_item => {
const item = { ..._item };
item.poster = item.poster_path;
return item;
});
});
}