larvituser
Advanced tools
Comparing version 0.8.2 to 0.8.3
@@ -87,3 +87,3 @@ 'use strict'; | ||
name = params.name, | ||
sql = 'REPLACE INTO user_data_fields (uuid, name) VALUES(?,?)'; | ||
sql = 'INSERT IGNORE INTO user_data_fields (uuid, name) VALUES(?,?)'; | ||
@@ -95,5 +95,6 @@ if (typeof cb !== 'function') { | ||
db.query(sql, [lUtils.uuidToBuffer(uuid), name], function(err) { | ||
if (err) log.warn(logPrefix + 'addUserField - ' + err.message); | ||
if (err) log.warn(logPrefix + 'addUserField() - ' + err.message); | ||
exports.emitter.emit(msgUuid, err); | ||
exports.emitter.emit('addedField_' + name, err); | ||
cb(err); | ||
@@ -112,5 +113,2 @@ }); | ||
function run() { | ||
const options = {'exchange': exports.exchangeName}, | ||
sendObj = {}; | ||
if (exports.addUserFieldReqRunning === true) { | ||
@@ -123,18 +121,31 @@ setTimeout(run, 10); | ||
sendObj.action = 'addUserField'; | ||
sendObj.params = {}; | ||
sendObj.params.name = fieldName; | ||
sendObj.params.uuid = uuidLib.v1(); | ||
// Check if this is already set in the database | ||
db.query('SELECT uuid FROM user_data_fields WHERE name = ?', [fieldName], function(err, rows) { | ||
const options = {'exchange': exports.exchangeName}, | ||
sendObj = {}; | ||
intercom.send(sendObj, options, function(err, msgUuid2) { | ||
if (err) { cb(err); return; } | ||
exports.emitter.once(msgUuid2, function(err) { | ||
sendObj.action = 'addUserField'; | ||
sendObj.params = {}; | ||
sendObj.params.name = fieldName; | ||
sendObj.params.uuid = (rows.length) ? lUtils.formatUuid(rows[0].uuid) : uuidLib.v1(); | ||
exports.emitter.once('addedField_' + fieldName, function(err) { | ||
if (err) { cb(err); return; } | ||
exports.addUserFieldReqRunning = false; | ||
exports.emitter.emit(msgUuid, err); | ||
}); | ||
cb(err); | ||
intercom.send(sendObj, options, function(err, msgUuid2) { | ||
if (err) { cb(err); return; } | ||
exports.emitter.once(msgUuid2, function(err) { | ||
if (err) { cb(err); return; } | ||
exports.emitter.emit(msgUuid, err); | ||
cb(err); | ||
}); | ||
}); | ||
}); | ||
@@ -144,3 +155,3 @@ } | ||
} else { | ||
log.debug(logPrefix + 'Ignoring addUserFieldReq() since we are not master'); | ||
log.debug(logPrefix + 'addUserFieldReq() - Ignoring since we are not master'); | ||
} | ||
@@ -147,0 +158,0 @@ } |
@@ -65,8 +65,7 @@ 'use strict'; | ||
intercom.send(sendObj, options, function(err, msgUuid) { | ||
intercom.send(sendObj, options, function(err) { | ||
if (err) { cb(err); return; } | ||
dataWriter.emitter.once(msgUuid, function(err) { | ||
dataWriter.emitter.once('addedField_' + fieldName, function(err) { | ||
if (err) { cb(err); return; } | ||
getFieldUuid(fieldName, cb); | ||
@@ -73,0 +72,0 @@ }); |
{ | ||
"name": "larvituser", | ||
"version": "0.8.2", | ||
"version": "0.8.3", | ||
"author": { | ||
@@ -5,0 +5,0 @@ "name": "Mikael 'Lilleman' Göransson", |
74919
1950