Fix: Plex errors (#141)
* inPlex function returns promise for more consistent return types * plexUserId should default to null on falsey
This commit is contained in:
@@ -16,11 +16,6 @@ const queries = {
|
||||
const getByStatus = () =>
|
||||
establishedDatabase.all(queries.getRequestsNotYetInPlex);
|
||||
|
||||
const checkIfRequestExistInPlex = async request => {
|
||||
request.existsInPlex = await plex.existsInPlex(request);
|
||||
return request;
|
||||
};
|
||||
|
||||
const commitNewStatus = (status, id, type, title) => {
|
||||
console.log(type, title, "updated to:", status);
|
||||
return establishedDatabase.run(queries.saveNewStatus, [status, id, type]);
|
||||
@@ -29,12 +24,12 @@ const commitNewStatus = (status, id, type, title) => {
|
||||
const getNewRequestMatchesInPlex = async () => {
|
||||
const requests = await getByStatus();
|
||||
|
||||
return Promise.all(requests.map(checkIfRequestExistInPlex))
|
||||
return Promise.all(requests.map(plex.inPlex))
|
||||
.catch(error =>
|
||||
console.log("error from checking plex for existance:", error)
|
||||
)
|
||||
.then(matchedRequests =>
|
||||
matchedRequests.filter(request => request.existsInPlex)
|
||||
matchedRequests.filter(request => request.matchedInPlex)
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -41,9 +41,12 @@ class PlexRepository {
|
||||
|
||||
inPlex(_tmdbResult) {
|
||||
const tmdbResult = { ..._tmdbResult };
|
||||
this.search(tmdbResult.title)
|
||||
|
||||
return this.search(tmdbResult.title)
|
||||
.then(plexResult => addAttributeIfTmdbInPlex(tmdbResult, plexResult))
|
||||
.catch(() => {
|
||||
// log("some error here::", error);
|
||||
|
||||
/**
|
||||
* If something crashes with search from this function it probably
|
||||
* fine to set the `matchedInPlex` attribute to false and return
|
||||
|
||||
@@ -14,7 +14,7 @@ function readRequestController(req, res) {
|
||||
requestRepository
|
||||
.lookup(mediaId, type)
|
||||
.then(movies => {
|
||||
res.send(movies);
|
||||
res.send(movies || {});
|
||||
})
|
||||
.catch(error => {
|
||||
res.status(404).send({ success: false, message: error.message });
|
||||
|
||||
@@ -18,7 +18,8 @@ const mustHaveAccountLinkedToPlex = (req, res, next) => {
|
||||
req.loggedInUser.username
|
||||
)
|
||||
.then(row => {
|
||||
const plexUserId = row.plex_userid;
|
||||
const plexUserId = row?.plex_userid || null;
|
||||
|
||||
if (plexUserId === null) {
|
||||
return res.status(403).send({
|
||||
success: false,
|
||||
|
||||
Reference in New Issue
Block a user