-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
67 lines (61 loc) · 2.11 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const express = require('express')
const app = express()
const path = require('path')
const bodyParser = require('body-parser')
const GoogleSpreadsheet = require('google-spreadsheet')
const credentials = require('./bugtracker.json')
const { promisify } = require('util')
const sgMail = require('@sendgrid/mail')
require('dotenv/config')
app.set('view engine', 'ejs')
app.set('views', path.resolve(__dirname, 'views'))
app.use(bodyParser.urlencoded({ extended: true }))
app.get('/', (req, res)=> {
res.render('home')
})
app.post('/', async(req, res) => {
try {
const doc = new GoogleSpreadsheet(process.env.docId)
await promisify(doc.useServiceAccountAuth)(credentials)
console.log('planilha aberta')
const info = await promisify(doc.getInfo)()
const worksheet = info.worksheets[process.env.worksheetIndex]
await promisify(worksheet.addRow)({
name: req.body.name,
email: req.body.email,
classificacao: req.body.issueType,
source: req.body.source || 'direct',
reproduzirError: req.body.howToReproduce,
saidaEsperada: req.body.expectedOuput,
saidaRecebida: req.body.receiveOuput,
userAgent: req.body.userAgent,
userDate: req.body.userDate,
userSo: req.body.userSo
})
// se for critico
if(req.body.issueType === 'CRITICAL') {
sgMail.setApiKey(process.env.sendGridKey);
const msg = {
to: '[email protected]',
from: '[email protected]',
subject: 'BUG Critico reportado',
text: `
O usário ${req.body.name} reportou um problema.
`,
html: `O usário ${req.body.name} reportou um problema.`,
};
await sgMail.send(msg);
}
res.render('sucesso')
} catch(err){
res.render('erro')
console.log(err)
}
})
app.listen(3000, (err)=> {
if (err) {
console.log('aconteceu um erro', err)
} else {
console.log('bugtracker rodando na porta 3000')
}
})