Merge pull request #100 from KevinMidboe/linting

Linting
This commit is contained in:
2018-05-09 11:00:02 +02:00
committed by GitHub
10 changed files with 36 additions and 32 deletions

View File

@@ -7,6 +7,8 @@
"prefer-destructuring": 0,
"camelcase": 0,
"import/no-unresolved": 0,
"import/no-extraneous-dependencies": 0
"import/no-extraneous-dependencies": 0,
"object-shorthand": 0,
"comma-dangle": 0
}
}

View File

@@ -15,6 +15,7 @@ class PlexRepository {
}
search(query) {
console.log('searching:', query)
const options = {
uri: `http://10.0.0.44:32400/search?query=${query}`,
headers: {
@@ -39,7 +40,8 @@ class PlexRepository {
}
else {
plexResult.results.map((plexItem) => {
if (tmdb.title === plexItem.title && tmdb.year === plexItem.year) { tmdb.matchedInPlex = true; }
if (tmdb.title === plexItem.title && tmdb.year === plexItem.year)
tmdb.matchedInPlex = true;
return tmdb;
});
}
@@ -50,6 +52,7 @@ class PlexRepository {
mapResults(response) {
return Promise.resolve()
.then(() => {
console.log('plexResponse:', response)
if (!response.MediaContainer.hasOwnProperty('Metadata')) return [[], 0];
const mappedResults = response.MediaContainer.Metadata.filter((element) => {

View File

@@ -8,7 +8,7 @@ const TMDB_METHODS = {
nowplaying: { movie: 'miscNowPlayingMovies', show: 'tvOnTheAir' },
similar: { movie: 'movieSimilar', show: 'tvSimilar' },
search: { movie: 'searchMovie', show: 'searchTv', multi: 'searchMulti' },
info: { movie: 'movieInfo', show: 'tvInfo' },
info: { movie: 'movieInfo', show: 'tvInfo' }
};
class TMDB {
@@ -65,7 +65,7 @@ class TMDB {
.catch(() => this.tmdb(TMDB_METHODS['search'][type], query))
.catch(() => { throw new Error('Could not search for movies/shows at tmdb.'); })
.then(response => this.cache.set(cacheKey, response))
.then(response => this.mapResults(response))
.then(response => this.mapResults(response));
}
/**
@@ -76,15 +76,15 @@ class TMDB {
* @returns {Promise} dict with query results, current page and total_pages
*/
listSearch(listName, type = 'movie', page = '1') {
const query = { page: page }
console.log(query)
const query = { page: page };
console.log(query);
const cacheKey = `${this.cacheTags[listName]}:${type}:${page}`;
return Promise.resolve()
.then(() => this.cache.get(cacheKey))
.catch(() => this.tmdb(TMDB_METHODS[listName][type], query))
.catch(() => { throw new Error('Error fetching list from tmdb.')})
.catch(() => { throw new Error('Error fetching list from tmdb.'); })
.then(response => this.cache.set(cacheKey, response))
.then(response => this.mapResults(response, type))
.then(response => this.mapResults(response, type));
}
/**
@@ -94,13 +94,18 @@ class TMDB {
* @returns {Promise} dict with tmdb results, mapped as movie/show objects.
*/
mapResults(response, type) {
console.log(response.page)
console.log(response.page);
return Promise.resolve()
.then(() => {
const mappedResults = response.results.filter((element) => {
return (element.media_type === 'movie' || element.media_type === 'tv' || element.media_type === undefined);
}).map((element) => convertTmdbToSeasoned(element, type));
return {results: mappedResults, page: response.page, total_pages: response.total_pages, total_results: response.total_results}
return {
results: mappedResults,
page: response.page,
total_pages: response.total_pages,
total_results: response.total_results
}
})
.catch((error) => { throw new Error(error); });
}

View File

@@ -41,7 +41,7 @@ class UserRepository {
assert(row, 'The user does not exist.');
return row.password;
})
.catch((err) => console.log('there was a error when getting hash', err));
.catch((err) => { console.log(error); throw new Error('Unable to find your user.'); });
}
/**
@@ -57,7 +57,7 @@ class UserRepository {
checkAdmin(user) {
return this.database.get(this.queries.getAdminStateByUser, user.username).then((row) => {
return row.admin;
})
});
}
}

View File

@@ -17,9 +17,6 @@ app.use(bodyParser.json());
// router.use(bodyParser.urlencoded({ extended: true }));
/* Decode the Authorization header if provided */
// router.use(tokenToUser);
const router = express.Router();
const allowedOrigins = ['https://kevinmidboe.com', 'http://localhost:8080'];
@@ -27,9 +24,7 @@ const allowedOrigins = ['https://kevinmidboe.com', 'http://localhost:8080'];
// router.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// This is probably a correct middleware/router setup
/* Translate the user token to a user name */
/* Decode the Authorization header if provided */
router.use(tokenToUser);
// TODO: Should have a separate middleware/router for handling headers.

File diff suppressed because one or more lines are too long

View File

@@ -10,7 +10,7 @@ const searchHistory = new SearchHistory();
function searchRequestController(req, res) {
const user = req.loggedInUser;
const { query, page, type } = req.query;
const username = user == undefined ? undefined : user.username;
const username = user === undefined ? undefined : user.username;
Promise.resolve()
.then(() => searchHistory.create(username, query))

View File

@@ -10,7 +10,7 @@ const searchHistory = new SearchHistory();
*/
function historyController(req, res) {
const user = req.loggedInUser;
const username = user == undefined ? undefined : user.username;
const username = user === undefined ? undefined : user.username;
searchHistory.read(username)
.then((searchQueries) => {

View File

@@ -22,7 +22,7 @@ function loginController(req, res) {
.then(() => userRepository.checkAdmin(user))
.then((checkAdmin) => {
const token = new Token(user).toString(secret);
const admin_state = checkAdmin == 1 ? true : false;
const admin_state = checkAdmin === 1 ? true : false;
res.send({ success: true, token, admin: admin_state });
})
.catch((error) => {

View File

@@ -22,8 +22,10 @@ function registerController(req, res) {
.then(() => userRepository.checkAdmin(user))
.then((checkAdmin) => {
const token = new Token(user).toString(secret);
const admin_state = checkAdmin == 1 ? true : false;
res.send({ success: true, message: 'Welcome to Seasoned!', token, admin: admin_state });
const admin_state = checkAdmin === 1 ? true : false;
res.send({
success: true, message: 'Welcome to Seasoned!', token, admin: admin_state,
});
})
.catch((error) => {
res.status(401).send({ success: false, error: error.message });