Passed
Pull Request — master (#125)
by
unknown
02:45
created

sample/TokenSaver.js   A

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 39
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 16
mnd 1
bc 1
fnc 1
dl 0
loc 39
bpm 1
cpm 2
noi 2
c 0
b 0
f 0
rs 10

1 Function

Rating   Name   Duplication   Size   Complexity  
A TokenSaver.js ➔ saveAuthToken 0 34 2
1
const {Client} = require('pg')
2
const {v4: uuidv4} = require('uuid');
3
4
module.exports = class TokenSaver {
5
    async saveAuthToken(tokenData, yardId) {
6
        console.log('saving auth token')
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
7
8
        const client = new Client()
0 ignored issues
show
Bug introduced by
The variable Client seems to be never declared. If this is a global, consider adding a /** global: Client */ 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...
9
        await client.connect()
10
11
        const query = `
12
            INSERT INTO erp_tool_credentials
13
            (erp_system_id, qb_access_token, qb_refresh_token, qb_expires_in,
14
             qb_refresh_token_expires_in, created_at, yard_id)
15
            VALUES ($1, $2, $3, $4, $5, to_timestamp($6), $7)
16
            ON CONFLICT
17
                ON CONSTRAINT erp_tool_credentials_pkey
18
                DO UPDATE
19
                SET erp_system_id               = $1,
20
                    qb_access_token             = $2,
21
                    qb_refresh_token            = $3,
22
                    qb_expires_in               = $4,
23
                    qb_refresh_token_expires_in = $5,
24
                    created_at               = to_timestamp($6),
25
                    yard_id                     = $7
26
            RETURNING *
27
        `
28
        const values = [tokenData.realmId, tokenData.access_token, tokenData.refresh_token, tokenData.expires_in, tokenData.x_refresh_token_expires_in, tokenData.createdAt / 1000, yardId]
29
30
        try {
31
            const res = await client.query(query, values)
32
            console.log('saved credentials')
33
            console.log(res.rows[0])
34
        } catch (err) {
35
            console.log(err.stack)
36
        }
37
        await client.end()
38
    }
39
}
40