Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
updated token saving to update on conflict
  • Loading branch information
bmccann36 committed Mar 21, 2022
commit ed02f8ea5fe058df9662a4c0beeeee072807f167
23 changes: 18 additions & 5 deletions sample/TokenSaver.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,24 @@ module.exports = class TokenSaver {
const client = new Client()
await client.connect()

const query = `INSERT INTO erp_tool_credentials
(qb_company_id, qb_access_token, qb_refresh_token, qb_expires_in,
qb_refresh_token_expires_in, qb_created_at, yard_id)
VALUES ($1, $2, $3, $4, $5, to_timestamp($6), $7) RETURNING *`
const values = [tokenData.realmId, tokenData.access_token, tokenData.refresh_token, tokenData.expires_in, tokenData.x_refresh_token_expires_in, tokenData.createdAt/1000, yardId]
const query = `
INSERT INTO erp_tool_credentials
(qb_company_id, qb_access_token, qb_refresh_token, qb_expires_in,
qb_refresh_token_expires_in, qb_created_at, yard_id)
VALUES ($1, $2, $3, $4, $5, to_timestamp($6), $7)
ON CONFLICT
ON CONSTRAINT erp_tool_credentials_pkey
DO UPDATE
SET qb_company_id = $1,
qb_access_token = $2,
qb_refresh_token = $3,
qb_expires_in = $4,
qb_refresh_token_expires_in = $5,
qb_created_at = to_timestamp($6),
yard_id = $7
RETURNING *
`
const values = [tokenData.realmId, tokenData.access_token, tokenData.refresh_token, tokenData.expires_in, tokenData.x_refresh_token_expires_in, tokenData.createdAt / 1000, yardId]

try {
const res = await client.query(query, values)
Expand Down
6 changes: 4 additions & 2 deletions sample/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ app.get('/', function (req, res) {
*/
app.get('/authUri', urlencodedParser, function (req, res) {


yardId = req.query.json.yardId
console.log('yardId is ', yardId)

Expand All @@ -83,7 +82,10 @@ app.get('/callback', function (req, res) {
oauthClient
.createToken(req.url)
.then(function (authResponse) {
console.log("got auth response")
console.log("got auth response. raw QB token is: \n")
console.log(JSON.stringify(authResponse.token))
console.log('-------')
console.log('-------')
oauth2_token_json = JSON.stringify(authResponse.getJson(), null, 2);
return authResponse
})
Expand Down