diff --git a/lib/coinatmradar/coinatmradar.js b/lib/coinatmradar/coinatmradar.js index 55fbf5c6..64660f4e 100644 --- a/lib/coinatmradar/coinatmradar.js +++ b/lib/coinatmradar/coinatmradar.js @@ -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, diff --git a/lib/middlewares/operatorId.js b/lib/middlewares/operatorId.js index 04548aaf..663b7527 100644 --- a/lib/middlewares/operatorId.js +++ b/lib/middlewares/operatorId.js @@ -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() diff --git a/lib/operator.js b/lib/operator.js index a39eaeed..52e64217 100644 --- a/lib/operator.js +++ b/lib/operator.js @@ -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) } diff --git a/migrations/1623413776161-create-operator-ids.js b/migrations/1623413776161-create-operator-ids.js index d48fcb1e..b7f27830 100644 --- a/migrations/1623413776161-create-operator-ids.js +++ b/migrations/1623413776161-create-operator-ids.js @@ -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 => {