GroganBurners /
ferveo
| 1 | const nodemailer = require('nodemailer') |
||
|
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
| 2 | const Router = require('express') |
||
|
0 ignored issues
–
show
|
|||
| 3 | const config = require('../config') |
||
|
0 ignored issues
–
show
|
|||
| 4 | const logger = require('winston') |
||
|
0 ignored issues
–
show
|
|||
| 5 | var rp = require('request-promise') |
||
| 6 | var ok = require('./utils').ok |
||
| 7 | var fail = require('./utils').fail |
||
| 8 | |||
| 9 | module.exports = class MessageController { |
||
| 10 | constructor () { |
||
| 11 | this.smtpConfig = { |
||
| 12 | host: config.mail.server, |
||
|
0 ignored issues
–
show
The variable
config seems to be never declared. If this is a global, consider adding a /** global: config */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 13 | port: config.mail.port, |
||
| 14 | secure: true, // use SSL |
||
| 15 | auth: { |
||
| 16 | user: config.mail.username, |
||
| 17 | pass: config.mail.password |
||
| 18 | } |
||
| 19 | } |
||
| 20 | } |
||
| 21 | |||
| 22 | sendSMS (sms) { |
||
| 23 | var data = { |
||
| 24 | 'username': config.sms.username, |
||
|
0 ignored issues
–
show
The variable
config seems to be never declared. If this is a global, consider adding a /** global: config */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 25 | 'password': config.sms.password, |
||
| 26 | 'function': 'sendSms', |
||
| 27 | 'number': sms.number, |
||
| 28 | 'message': sms.message, |
||
| 29 | 'senderid': 'GrogBurners' |
||
| 30 | } |
||
| 31 | |||
| 32 | return rp('https://www.my-cool-sms.com/api-socket.php', { json: true, body: data }) |
||
| 33 | .then((resp) => { |
||
| 34 | if (resp.hasOwnProperty('errorcode')) { |
||
| 35 | logger.error('Send SMS failed: ' + resp.description) |
||
|
0 ignored issues
–
show
The variable
logger seems to be never declared. If this is a global, consider adding a /** global: logger */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 36 | throw new Error('SMS Send failed!') |
||
| 37 | } else { |
||
| 38 | logger.info('SMS Sent to: ' + JSON.Stringify(resp)) |
||
| 39 | logger.debug('SMS Sent: ' + JSON.Stringify(resp)) |
||
| 40 | return { message: 'Message sent' } |
||
| 41 | } |
||
| 42 | }) |
||
| 43 | /* .catch((err) => { |
||
| 44 | return new Error('Error creating message: ' + err) |
||
| 45 | }); */ |
||
| 46 | } |
||
| 47 | |||
| 48 | sendTestEmail (body) { |
||
| 49 | const mailOptions = { |
||
| 50 | from: '"' + config.mail.from.name + '" <' + config.mail.from.address + '>', // sender address |
||
|
0 ignored issues
–
show
The variable
config seems to be never declared. If this is a global, consider adding a /** global: config */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 51 | to: body.to, // list of receivers |
||
| 52 | subject: body.subject, // Subject line |
||
| 53 | text: body.text, // plaintext body |
||
| 54 | html: body.html // html body |
||
| 55 | } |
||
| 56 | return this.send(mailOptions) |
||
| 57 | } |
||
| 58 | |||
| 59 | sendEmail (email) { |
||
| 60 | const transporter = nodemailer.createTransport(this.smtpConfig) |
||
|
0 ignored issues
–
show
The variable
nodemailer seems to be never declared. If this is a global, consider adding a /** global: nodemailer */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 61 | return transporter.sendMail(email) |
||
| 62 | .then(() => { |
||
| 63 | return { message: 'Message sent' } |
||
| 64 | }) |
||
| 65 | /* .catch((err) => { |
||
| 66 | return new Error('Error creating message: ' + err) |
||
| 67 | }); */ |
||
| 68 | } |
||
| 69 | |||
| 70 | routeAPI () { |
||
| 71 | const router = new Router() |
||
|
0 ignored issues
–
show
The variable
Router seems to be never declared. If this is a global, consider adding a /** global: Router */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 72 | router.post('/email', (req, res) => { |
||
| 73 | this |
||
| 74 | .sendEmail(req.body) |
||
| 75 | .then(ok(res)) |
||
| 76 | .then(null, fail(res)) |
||
| 77 | }) |
||
| 78 | |||
| 79 | router.post('/sms', (req, res) => { |
||
| 80 | this |
||
| 81 | .sendSMS(req.body) |
||
| 82 | .then(ok(res)) |
||
| 83 | .then(null, fail(res)) |
||
| 84 | }) |
||
| 85 | |||
| 86 | return router |
||
| 87 | } |
||
| 88 | } |
||
| 89 |