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