Update script for updating all plex statuses of requestes.
This commit is contained in:
41
seasoned_api/src/plex/updateRequestsInPlex.js
Normal file
41
seasoned_api/src/plex/updateRequestsInPlex.js
Normal 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
|
||||
Reference in New Issue
Block a user