Removed unused mail conf and added a function for getting all requested elements by loggedInUser.
This commit is contained in:
@@ -17,17 +17,21 @@ class RequestRepository {
|
|||||||
this.database = database || establishedDatabase;
|
this.database = database || establishedDatabase;
|
||||||
this.queries = {
|
this.queries = {
|
||||||
insertRequest: "INSERT INTO requests VALUES (?, ?, ?, ?, ?, ?, ?, CURRENT_DATE, 'requested', ?, ?)",
|
insertRequest: "INSERT INTO requests VALUES (?, ?, ?, ?, ?, ?, ?, CURRENT_DATE, 'requested', ?, ?)",
|
||||||
fetchRequestedItems: 'SELECT * FROM requests',
|
fetchRequestedItems: 'SELECT * FROM requests ORDER BY name ASC',
|
||||||
fetchRequestedItemsByStatus: 'SELECT * FROM requests WHERE status is ?',
|
fetchRequestedItemsByStatus: 'SELECT * FROM requests WHERE status IS ? AND type LIKE ?',
|
||||||
updateRequestedById: 'UPDATE requests SET status = ? WHERE id is ? AND type is ?',
|
updateRequestedById: 'UPDATE requests SET status = ? WHERE id is ? AND type is ?',
|
||||||
checkIfIdRequested: 'SELECT * FROM requests WHERE id IS ? AND type IS ?',
|
checkIfIdRequested: 'SELECT * FROM requests WHERE id IS ? AND type IS ?',
|
||||||
|
userRequests: 'SELECT * FROM requests WHERE requested_by IS ?'
|
||||||
|
};
|
||||||
|
this.cacheTags = {
|
||||||
|
search: 'se',
|
||||||
|
lookup: 'i',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
search(query, type, page) {
|
search(query, type, page) {
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
.then(() => tmdb.search(query, type, page))
|
.then(() => tmdb.search(query, type, page))
|
||||||
// .then((tmdbResult) => plexRepository.multipleInPlex(tmdbResult))
|
|
||||||
.then(result => result)
|
.then(result => result)
|
||||||
.catch(error => `error in the house${error}`);
|
.catch(error => `error in the house${error}`);
|
||||||
}
|
}
|
||||||
@@ -65,52 +69,24 @@ class RequestRepository {
|
|||||||
if (user === 'false') { user = 'NULL'; }
|
if (user === 'false') { user = 'NULL'; }
|
||||||
// Add request to database
|
// Add request to database
|
||||||
this.database.run(this.queries.insertRequest, [movie.id, movie.title, movie.year, movie.poster_path, movie.background_path, user, ip, user_agent, movie.type]);
|
this.database.run(this.queries.insertRequest, [movie.id, movie.title, movie.year, movie.poster_path, movie.background_path, user, ip, user_agent, movie.type]);
|
||||||
|
|
||||||
|
|
||||||
// create reusable transporter object using the default SMTP transport
|
|
||||||
const transporter = nodemailer.createTransport({
|
|
||||||
service: 'gmail',
|
|
||||||
auth: {
|
|
||||||
user: configuration.get('mail', 'user_pi'),
|
|
||||||
pass: configuration.get('mail', 'password_pi'),
|
|
||||||
},
|
|
||||||
// host: configuration.get('mail', 'host'),
|
|
||||||
// port: 26,
|
|
||||||
// ignoreTLS: true,
|
|
||||||
// tls :{rejectUnauthorized: false},
|
|
||||||
// secure: false, // secure:true for port 465, secure:false for port 587
|
|
||||||
});
|
|
||||||
|
|
||||||
const mailTemplate = new MailTemplate(movie);
|
|
||||||
|
|
||||||
// setup email data with unicode symbols
|
|
||||||
const mailOptions = {
|
|
||||||
// TODO get the mail adr from global location (easy to add)
|
|
||||||
from: 'MovieRequester <pi.midboe@gmail.com>', // sender address
|
|
||||||
to: 'kevin.midboe@gmail.com', // list of receivers
|
|
||||||
subject: 'Download request', // Subject line
|
|
||||||
text: mailTemplate.toText(),
|
|
||||||
html: mailTemplate.toHTML(),
|
|
||||||
};
|
|
||||||
|
|
||||||
// send mail with defined transport object
|
|
||||||
transporter.sendMail(mailOptions, (error, info) => {
|
|
||||||
if (error) {
|
|
||||||
return console.log(error);
|
|
||||||
}
|
|
||||||
console.log('Message %s sent: %s', info.messageId, info.response);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO add better response when done.
|
|
||||||
return Promise.resolve();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchRequested(status) {
|
fetchRequested(status, type = '%') {
|
||||||
if (status === 'requested' || status === 'downloading' || status === 'downloaded')
|
return Promise.resolve()
|
||||||
return this.database.all(this.queries.fetchRequestedItemsByStatus, status);
|
.then(() => {
|
||||||
else
|
return this.database.all(this.queries.fetchRequestedItems);
|
||||||
return this.database.all(this.queries.fetchRequestedItems);
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
userRequests(user) {
|
||||||
|
return Promise.resolve()
|
||||||
|
.then(() => this.database.all(this.queries.userRequests, user.username))
|
||||||
|
.catch((error) => {
|
||||||
|
if (String(error).includes('no such column')) { throw new Error('Username not found'); }
|
||||||
|
else { throw new Error('Unable to fetch your requests')}
|
||||||
|
})
|
||||||
|
.then((result) => { return result })
|
||||||
}
|
}
|
||||||
|
|
||||||
updateRequestedById(id, type, status) {
|
updateRequestedById(id, type, status) {
|
||||||
|
|||||||
Reference in New Issue
Block a user