fix: store operator id for each service
This commit is contained in:
parent
9b28c6a3f1
commit
8884c75ffd
4 changed files with 14 additions and 9 deletions
|
|
@ -132,7 +132,7 @@ function sendRadar (data) {
|
|||
|
||||
function mapRecord (rates, settings) {
|
||||
const timestamp = new Date().toISOString()
|
||||
return Promise.all([getMachines(rates, settings), getOperatorId()])
|
||||
return Promise.all([getMachines(rates, settings), getOperatorId('coinatmradar')])
|
||||
.then(([machines, operatorId]) => {
|
||||
return {
|
||||
operatorId: operatorId,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
const { getOperatorId } = require('../operator')
|
||||
|
||||
function findOperatorId (req, res, next) {
|
||||
return getOperatorId()
|
||||
return getOperatorId('middleware')
|
||||
.then(({ id }) => {
|
||||
res.locals.operatorId = id
|
||||
return next()
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
const db = require('./db')
|
||||
|
||||
function getOperatorId () {
|
||||
const sql = `SELECT id FROM operator_ids WHERE description = 'mnemonic'`
|
||||
function getOperatorId (service) {
|
||||
const sql = `SELECT operator_id FROM operator_ids WHERE service = '${service}'`
|
||||
return db.oneOrNone(sql)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,14 +34,19 @@ exports.up = function (next) {
|
|||
const sql =
|
||||
[
|
||||
`CREATE TABLE operator_ids (
|
||||
id TEXT PRIMARY KEY,
|
||||
description TEXT NOT NULL)`
|
||||
id serial PRIMARY KEY,
|
||||
operator_id TEXT NOT NULL,
|
||||
service TEXT NOT NULL
|
||||
)`
|
||||
]
|
||||
generateOperatorId()
|
||||
.then(operatorId => {
|
||||
const sql2 = `INSERT INTO operator_ids (id, description) VALUES ('${operatorId}','mnemonic' )`
|
||||
sql.push(sql2)
|
||||
db.multi(sql, next)
|
||||
const sql2 = [
|
||||
`INSERT INTO operator_ids (operator_id, service) VALUES ('${operatorId}','middleware')`,
|
||||
`INSERT INTO operator_ids (operator_id, service) VALUES ('${operatorId}','coinatmradar')`,
|
||||
`INSERT INTO operator_ids (operator_id, service) VALUES ('${operatorId}','authentication')`
|
||||
]
|
||||
db.multi(sql.concat(sql2), next)
|
||||
.then(() => next())
|
||||
})
|
||||
.catch(e => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue