Update script for updating all plex statuses of requestes.

This commit is contained in:
2019-07-16 18:50:27 +02:00
parent 3a9131a022
commit 3f04d9bc56
2 changed files with 42 additions and 1 deletions

View File

@@ -0,0 +1,41 @@
const PlexRepository = require('src/plex/plexRepository');
const configuration = require('src/config/configuration').getInstance();
const establishedDatabase = require('src/database/database');
const plexRepository = new PlexRepository();
class UpdateRequestsInPlex {
constructor() {
this.database = establishedDatabase;
this.queries = {
getRequests: `SELECT * FROM requests WHERE status IS 'requested' OR 'downloaded'`,
saveNewStatus: `UPDATE requests SET status = ? WHERE id IS ? and type IS ?`,
}
}
getRequests() {
return this.database.all(this.queries.getRequests);
}
scrub() {
return this.getRequests()
.then((requests) => Promise.all(requests.map(async (movie) => {
return plexRepository.inPlex(movie)
})))
.then((requests_checkInPlex) => requests_checkInPlex.filter((movie) => movie.matchedInPlex))
}
updateStatus(status) {
this.scrub().then((newInPlex) =>
newInPlex.map((movie) => {
console.log('updated', movie.title, 'to', status)
// this.database.run(this.queries.saveNewStatus, [status, movie.id, movie.type])
})
)
}
}
var requestsUpdater = new UpdateRequestsInPlex();
requestsUpdater.updateStatus('downloaded')
module.exports = UpdateRequestsInPlex