inPlex function returns promise for more consistent return types

This commit is contained in:
2022-08-25 16:12:57 +02:00
parent 463b48a84f
commit 14da4d0c72
3 changed files with 7 additions and 9 deletions

View File

@@ -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)
);
};

View File

@@ -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

View File

@@ -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 });