larvituser 0.18.1 → 0.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dataWriter.js DELETED
@@ -1,715 +0,0 @@
1
- 'use strict';
2
-
3
- const EventEmitter = require('events').EventEmitter,
4
- topLogPrefix = 'larvituser: dataWriter.js - ',
5
- DbMigration = require('larvitdbmigration'),
6
- Helpers = require(__dirname + '/helpers.js'),
7
- uuidLib = require('uuid'),
8
- LUtils = require('larvitutils'),
9
- amsync = require('larvitamsync'),
10
- async = require('async');
11
-
12
- function DataWriter(options, cb) {
13
- const that = this;
14
-
15
- that.readyInProgress = false;
16
- that.isReady = false;
17
-
18
- if ( ! options.log) {
19
- const tmpLUtils = new LUtils();
20
- options.log = new tmpLUtils.Log();
21
- }
22
-
23
- that.options = options;
24
-
25
- for (const key of Object.keys(options)) {
26
- that[key] = options[key];
27
- }
28
-
29
- that.lUtils = new LUtils({'log': that.log});
30
-
31
- that.emitter = new EventEmitter();
32
-
33
- that.listenToQueue(function (err) {
34
- if (err) return cb(err);
35
-
36
- that.helpers = new Helpers({
37
- 'dataWriter': that,
38
- 'log': that.log,
39
- 'db': that.db
40
- });
41
-
42
- cb();
43
- });
44
- }
45
-
46
- DataWriter.prototype.addUserDataFields = function addUserDataFields(params, deliveryTag, msgUuid, cb) {
47
- const userUuidBuffer = this.lUtils.uuidToBuffer(params.userUuid),
48
- logPrefix = topLogPrefix + 'addUserDataFields() - ',
49
- dbValues = [],
50
- tasks = [],
51
- that = this;
52
-
53
- let sql = 'INSERT INTO user_users_data (userUuid, fieldUuid, data) VALUES';
54
-
55
- if (typeof deliveryTag === 'function') {
56
- cb = deliveryTag;
57
- deliveryTag = false;
58
- msgUuid = false;
59
- }
60
-
61
- if (cb === undefined || typeof cb !== 'function') {
62
- cb = function () {};
63
- }
64
-
65
- if (userUuidBuffer === false) {
66
- const err = new Error('Invalid userUuid');
67
- that.log.warn(logPrefix + err.message);
68
- if (msgUuid !== false) that.emitter.emit(msgUuid, err);
69
- return cb(err);
70
- }
71
-
72
- for (let key in params.fields) {
73
- tasks.push(function (cb) {
74
- that.helpers.getFieldUuid(key, function (err, fieldUuid) {
75
- const fieldUuidBuffer = that.lUtils.uuidToBuffer(fieldUuid);
76
-
77
- if (err) {
78
- that.log.warn(logPrefix + err.message);
79
- return cb(err);
80
- }
81
-
82
- if (fieldUuidBuffer === false) {
83
- const err = new Error('Invalid fieldUuid');
84
- that.log.warn(logPrefix + err.message);
85
- return cb(err);
86
- }
87
-
88
- if (params.fields[key] === null || params.fields[key] === undefined) {
89
- sql += '(?,?,\'\'),';
90
- dbValues.push(userUuidBuffer, fieldUuidBuffer);
91
- } else {
92
- if (Array.isArray(params.fields[key])) {
93
- for (let i = 0; i < params.fields[key].length; i ++) {
94
- sql += '(?,?,?),';
95
- dbValues.push(userUuidBuffer, fieldUuidBuffer, params.fields[key][i]);
96
- }
97
- } else {
98
- sql += '(?,?,?),';
99
- dbValues.push(userUuidBuffer, fieldUuidBuffer, params.fields[key]);
100
- }
101
- }
102
-
103
- cb(err);
104
- });
105
- });
106
- }
107
-
108
- async.parallel(tasks, function (err) {
109
- if (err) {
110
- that.log.warn(logPrefix + err.message);
111
- if (msgUuid !== false) that.emitter.emit(msgUuid, err);
112
- return cb(err);
113
- }
114
-
115
- sql = sql.substring(0, sql.length - 1);
116
-
117
- if (dbValues.length === 0) {
118
- that.log.info(logPrefix + 'No fields or field data specifed');
119
-
120
- // We need to setImmediate here since a listener on the other side must be done async to obtain a msgUuid
121
- setImmediate(function () {
122
- if (msgUuid !== false) that.emitter.emit(msgUuid);
123
- return cb();
124
- });
125
- return; // Make sure no more execution is taking place
126
- }
127
-
128
- that.db.query(sql, dbValues, function (err) {
129
- if (err) {
130
- that.log.warn(topLogPrefix + 'addUserDataFields() - ' + err.message);
131
- }
132
- if (msgUuid !== false) that.emitter.emit(msgUuid, err);
133
- cb(err);
134
- });
135
- });
136
- };
137
-
138
- DataWriter.prototype.addUserField = function addUserField(params, deliveryTag, msgUuid, cb) {
139
- const uuidBuffer = this.lUtils.uuidToBuffer(params.uuid),
140
- logPrefix = topLogPrefix + 'addUserField() - ',
141
- that = this,
142
- name = params.name,
143
- sql = 'INSERT IGNORE INTO user_data_fields (uuid, name) VALUES(?,?)';
144
-
145
- if (typeof cb !== 'function') {
146
- cb = function () {};
147
- }
148
-
149
- if (uuidBuffer === false) {
150
- const err = new Error('Invalid field uuid');
151
- that.log.warn(logPrefix + err.message);
152
-
153
- that.emitter.emit(msgUuid, err);
154
- that.emitter.emit('addedField_' + name, err);
155
- return cb(err);
156
- }
157
-
158
- that.db.query(sql, [uuidBuffer, name], function (err) {
159
- if (err) that.log.warn(logPrefix + err.message);
160
-
161
- that.emitter.emit(msgUuid, err);
162
- that.emitter.emit('addedField_' + name, err);
163
- cb(err);
164
- });
165
- };
166
-
167
- DataWriter.prototype.addUserFieldReq = function addUserFieldReq(params, deliveryTag, msgUuid, cb) {
168
- const logPrefix = topLogPrefix + 'addUserFieldReq() - ',
169
- fieldName = params.name,
170
- that = this;
171
-
172
- if (typeof cb !== 'function') {
173
- cb = function () {};
174
- }
175
-
176
- if (that.mode === 'master' || that.mode === 'noSync') {
177
- function run() {
178
- if (that.addUserFieldReqRunning === true) {
179
- setTimeout(run, 10);
180
- return;
181
- }
182
-
183
- that.addUserFieldReqRunning = true;
184
-
185
- // Check if this is already set in the database
186
- that.db.query('SELECT uuid FROM user_data_fields WHERE name = ?', [fieldName], function (err, rows) {
187
- const options = {'exchange': that.exchangeName},
188
- sendObj = {};
189
-
190
- if (err) return cb(err);
191
-
192
- sendObj.action = 'addUserField';
193
- sendObj.params = {};
194
- sendObj.params.name = fieldName;
195
- sendObj.params.uuid = (rows.length) ? that.lUtils.formatUuid(rows[0].uuid) : uuidLib.v1();
196
-
197
- that.emitter.once('addedField_' + fieldName, function (err) {
198
- if (err) return cb(err);
199
- that.addUserFieldReqRunning = false;
200
- });
201
-
202
- that.intercom.send(sendObj, options, function (err, msgUuid2) {
203
- if (err) return cb(err);
204
-
205
- that.emitter.once(msgUuid2, function (err) {
206
- if (err) return cb(err);
207
-
208
- that.emitter.emit(msgUuid, err);
209
-
210
- cb(err);
211
- });
212
- });
213
- });
214
- }
215
- run();
216
- } else {
217
- that.log.debug(logPrefix + 'Ignoring since we are not master or noSync');
218
- }
219
- };
220
-
221
- DataWriter.prototype.create = function create(params, deliveryTag, msgUuid, cb) {
222
- const uuidBuffer = this.lUtils.uuidToBuffer(params.uuid),
223
- logPrefix = topLogPrefix + 'create() - ',
224
- dbFields = [],
225
- that = this,
226
- sql = 'INSERT IGNORE INTO user_users (uuid, username, password) VALUES(?,?,?);';
227
-
228
- if (cb === undefined || typeof cb !== 'function') {
229
- cb = function () {};
230
- }
231
-
232
- dbFields.push(uuidBuffer);
233
- dbFields.push(params.username);
234
- dbFields.push(params.password);
235
-
236
- if (uuidBuffer === false) {
237
- const err = new Error('Invalid user uuid supplied: "' + params.uuid + '", deliveryTag: "' + deliveryTag + '", msgUuid: "' + msgUuid + '"');
238
-
239
- that.log.warn(logPrefix + err.message);
240
- that.emitter.emit(msgUuid, err);
241
- return cb(err);
242
- }
243
-
244
- that.db.query(sql, dbFields, function (err, results) {
245
- const fieldsParams = {};
246
-
247
- if (results.affectedRows === 0) {
248
- const err = new Error('No user created, duplicate key on uuid: "' + params.uuid + '" or username: "' + params.username + '"');
249
- that.log.warn(logPrefix + err.message);
250
- return cb(err);
251
- }
252
-
253
- if (err) {
254
- that.log.warn(logPrefix + err.message);
255
- that.emitter.emit(msgUuid, err);
256
- return cb(err);
257
- }
258
-
259
- fieldsParams.userUuid = params.uuid;
260
- fieldsParams.fields = params.fields;
261
-
262
- that.addUserDataFields(fieldsParams, function (err) {
263
- if (err) {
264
- that.log.warn(logPrefix + err.message);
265
- }
266
-
267
- that.emitter.emit(msgUuid, err);
268
- cb(err);
269
- });
270
- });
271
- };
272
-
273
- DataWriter.prototype.listenToQueue = function listenToQueue(cb) {
274
- const logPrefix = topLogPrefix + 'listenToQueue() - ',
275
- options = {'exchange': this.exchangeName},
276
- tasks = [],
277
- that = this;
278
-
279
- let listenMethod;
280
-
281
- if (typeof cb !== 'function') {
282
- cb = function () {};
283
- }
284
-
285
- tasks.push(function (cb) {
286
- if (that.mode === 'master') {
287
- listenMethod = 'consume';
288
- options.exclusive = true; // It is important no other client tries to sneak
289
- // // out messages from us, and we want "consume"
290
- // // since we want the queue to persist even if this
291
- // // minion goes offline.
292
- } else if (that.mode === 'slave' || that.mode === 'noSync') {
293
- listenMethod = 'subscribe';
294
- } else {
295
- const err = new Error('Invalid that.mode. Must be either "master", "slave" or "noSync"');
296
- that.log.error(logPrefix + err.message);
297
- return cb(err);
298
- }
299
-
300
- that.log.info(logPrefix + 'listenMethod: ' + listenMethod);
301
- cb();
302
- });
303
-
304
- tasks.push(function (cb) {
305
- that.intercom.ready(function (err) {
306
- if (err) {
307
- that.log.error(logPrefix + 'intercom.ready() err: ' + err.message);
308
- return;
309
- }
310
-
311
- that.intercom[listenMethod](options, function (message, ack, deliveryTag) {
312
- that.ready(function (err) {
313
- ack(err); // Ack first, if something goes wrong we log it and handle it manually
314
-
315
- if (err) {
316
- that.log.error(logPrefix + 'intercom.' + listenMethod + '() - that.ready() returned err: ' + err.message);
317
- return;
318
- }
319
-
320
- if (typeof message !== 'object') {
321
- that.log.error(logPrefix + 'intercom.' + listenMethod + '() - Invalid message received, is not an object! deliveryTag: "' + deliveryTag + '"');
322
- return;
323
- }
324
-
325
- if (typeof that[message.action] === 'function') {
326
- that[message.action](message.params, deliveryTag, message.uuid);
327
- } else {
328
- that.log.warn(logPrefix + 'intercom.' + listenMethod + '() - Unknown message.action received: "' + message.action + '"');
329
- }
330
- });
331
- }, cb);
332
- });
333
- });
334
-
335
- // Run the ready function
336
- tasks.push(function (cb) {
337
- that.ready(cb);
338
- });
339
-
340
- async.series(tasks, cb);
341
- };
342
-
343
- DataWriter.prototype.ready = function ready(cb) {
344
- const that = this,
345
- logPrefix = topLogPrefix + 'ready() - ',
346
- tasks = [];
347
-
348
- if (typeof cb !== 'function') {
349
- cb = function () {};
350
- }
351
-
352
- if (that.isReady === true) return cb();
353
-
354
- if (that.readyInProgress === true) {
355
- that.emitter.on('ready', cb);
356
- return;
357
- }
358
-
359
- that.readyInProgress = true;
360
-
361
- tasks.push(function (cb) {
362
- that.log.debug(logPrefix + 'Waiting for intercom.ready()');
363
- that.intercom.ready(cb);
364
- });
365
-
366
- tasks.push(function (cb) {
367
- that.log.debug(logPrefix + 'Waiting for db.ready()');
368
- that.db.ready(cb);
369
- });
370
-
371
- tasks.push(function (cb) {
372
- if (that.mode === 'slave') {
373
- that.log.verbose(logPrefix + 'that.mode: "' + that.mode + '", so read');
374
- amsync.mariadb({
375
- 'exchange': that.exchangeName + '_dataDump',
376
- 'intercom': that.intercom,
377
- 'log': that.log,
378
- 'db': that.db
379
- }, cb);
380
- } else {
381
- cb();
382
- }
383
- });
384
-
385
- // Change tablename from larvituser_db_version to users_db_version
386
- // In case larvituser_db_version exists, that is.
387
- // This is due to a breaking change in 0.17.0 and this was added as
388
- // a patch in 0.17.1 to make applications not crash
389
- tasks.push(function (cb) {
390
- that.db.query('SHOW TABLES LIKE \'larvituser_db_version\'', function (err, rows) {
391
- if (err) return cb(err);
392
-
393
- if (rows.length) {
394
- that.db.query('RENAME TABLE larvituser_db_version TO users_db_version', cb);
395
- return;
396
- }
397
-
398
- cb();
399
- });
400
- });
401
-
402
- // Migrate database
403
- tasks.push(function (cb) {
404
- const options = {};
405
-
406
- let dbMigration;
407
-
408
- options.dbType = 'mariadb';
409
- options.dbDriver = that.db;
410
- options.tableName = 'users_db_version';
411
- options.migrationScriptsPath = __dirname + '/dbmigration';
412
- options.log = that.log;
413
- dbMigration = new DbMigration(options);
414
-
415
- dbMigration.run(function (err) {
416
- if (err) {
417
- that.log.error(logPrefix + 'Database error: ' + err.message);
418
- }
419
-
420
- cb(err);
421
- });
422
- });
423
-
424
- async.series(tasks, function (err) {
425
- if (err) return cb(err);
426
-
427
- that.isReady = true;
428
- that.emitter.emit('ready');
429
-
430
- if (that.mode === 'master') {
431
- that.runDumpServer(cb);
432
- } else {
433
- cb();
434
- }
435
- });
436
- };
437
-
438
- DataWriter.prototype.replaceFields = function replaceFields(params, deliveryTag, msgUuid, cb) {
439
- const fieldNamesToUuidBufs = {},
440
- userUuidBuf = this.lUtils.uuidToBuffer(params.userUuid),
441
- logPrefix = topLogPrefix + 'replaceFields() - ',
442
- tasks = [],
443
- that = this;
444
-
445
- if (cb === undefined || typeof cb !== 'function') {
446
- cb = function () {};
447
- }
448
-
449
- if (userUuidBuf === false) {
450
- const err = new Error('Invalid user uuid supplied: "' + params.userUuid + '", deliveryTag: "' + deliveryTag + '", msgUuid: "' + msgUuid + '"');
451
-
452
- that.log.warn(logPrefix + err.message);
453
- that.emitter.emit(msgUuid, err);
454
- return cb(err);
455
- }
456
-
457
- // Check so the user uuid is valid
458
- tasks.push(function (cb) {
459
- that.db.query('SELECT * FROM user_users WHERE uuid = ?', userUuidBuf, function (err, rows) {
460
- if (err) return cb(err);
461
-
462
- if (rows.length === 0) {
463
- const err = new Error('Invalid user uuid: "' + params.userUuid + '", no records found in database of this user');
464
- that.log.warn(logPrefix + err.message);
465
- return cb(err);
466
- }
467
-
468
- return cb();
469
- });
470
- });
471
-
472
- // Clean out previous data
473
- tasks.push(function (cb) {
474
- that.db.query('DELETE FROM user_users_data WHERE userUuid = ?', [userUuidBuf], cb);
475
- });
476
-
477
- // Get field uuids
478
- tasks.push(function (cb) {
479
- const tasks = [];
480
-
481
- for (const fieldName of Object.keys(params.fields)) {
482
- tasks.push(function (cb) {
483
- that.helpers.getFieldUuid(fieldName, function (err, fieldUuid) {
484
- fieldNamesToUuidBufs[fieldName] = that.lUtils.uuidToBuffer(fieldUuid);
485
-
486
- if (fieldNamesToUuidBufs[fieldName] === false) {
487
- const err = new Error('Invalid field uuid');
488
- that.log.warn(logPrefix + err.message);
489
- return cb(err);
490
- }
491
-
492
- cb(err);
493
- });
494
- });
495
- }
496
-
497
- async.parallel(tasks, cb);
498
- });
499
-
500
- // Add new data
501
- tasks.push(function (cb) {
502
- const dbFields = [];
503
-
504
- let sql = 'INSERT INTO user_users_data (userUuid, fieldUuid, data) VALUES';
505
-
506
- if ( ! params.fields) return cb();
507
-
508
- for (const fieldName of Object.keys(params.fields)) {
509
- if ( ! (params.fields[fieldName] instanceof Array)) {
510
- params.fields[fieldName] = [params.fields[fieldName]];
511
- }
512
-
513
- for (let i = 0; params.fields[fieldName][i] !== undefined; i ++) {
514
- const fieldValue = params.fields[fieldName][i];
515
-
516
- sql += '(?,?,?),';
517
- dbFields.push(userUuidBuf);
518
- dbFields.push(fieldNamesToUuidBufs[fieldName]);
519
- dbFields.push(fieldValue);
520
- }
521
- }
522
-
523
- sql = sql.substring(0, sql.length - 1) + ';';
524
-
525
- if (dbFields.length === 0) return cb();
526
-
527
- that.db.query(sql, dbFields, cb);
528
- });
529
-
530
- async.series(tasks, function (err) {
531
- if (err) that.log.warn(logPrefix + err.message);
532
- that.emitter.emit(msgUuid, err);
533
- cb(err);
534
- });
535
- };
536
-
537
- DataWriter.prototype.rmUser = function rmUser(params, deliveryTag, msgUuid, cb) {
538
- const uuidBuffer = this.lUtils.uuidToBuffer(params.userUuid),
539
- logPrefix = topLogPrefix + 'rmUser() - ',
540
- tasks = [],
541
- that = this;
542
-
543
- if (cb === undefined || typeof cb !== 'function') {
544
- cb = function () {};
545
- }
546
-
547
- if (uuidBuffer === false) {
548
- const err = new Error('Invalid user uuid');
549
- that.log.warn(logPrefix + err.message);
550
- that.emitter.emit(msgUuid, err);
551
- return cb(err);
552
- }
553
-
554
- tasks.push(function (cb) {
555
- const sql = 'DELETE FROM user_users_data WHERE userUuid = ?;';
556
-
557
- that.db.query(sql, [uuidBuffer], cb);
558
- });
559
-
560
- tasks.push(function (cb) {
561
- const sql = 'DELETE FROM user_users WHERE uuid = ?;';
562
-
563
- that.db.query(sql, [uuidBuffer], cb);
564
- });
565
-
566
- async.series(tasks, function (err) {
567
- if (err) that.log.warn(logPrefix + err.message);
568
- that.emitter.emit(msgUuid, err);
569
- cb(err);
570
- });
571
- };
572
-
573
- DataWriter.prototype.rmUserField = function rmUserField(params, deliveryTag, msgUuid, cb) {
574
- const logPrefix = topLogPrefix + 'rmUserField() - ',
575
- that = this;
576
-
577
- if (cb === undefined || typeof cb !== 'function') {
578
- cb = function () {};
579
- }
580
-
581
- that.helpers.getFieldUuid(params.fieldName, function (err, fieldUuid) {
582
- const userUuidBuffer = that.lUtils.uuidToBuffer(params.userUuid),
583
- fieldUuidBuffer = that.lUtils.uuidToBuffer(fieldUuid),
584
- sql = 'DELETE FROM user_users_data WHERE userUuid = ? AND fieldUuid = ?';
585
-
586
- if (err) {
587
- that.emitter.emit(msgUuid, err);
588
- return;
589
- }
590
-
591
- if (userUuidBuffer === false) {
592
- const err = new Error('Invalid user uuid');
593
- that.log.warn(logPrefix + err.message);
594
- that.emitter.emit(msgUuid, err);
595
- return cb(err);
596
- }
597
-
598
- if (fieldUuidBuffer === false) {
599
- const err = new Error('Invalid field uuid');
600
- that.log.warn(logPrefix + err.message);
601
- that.emitter.emit(msgUuid, err);
602
- return cb(err);
603
- }
604
-
605
- that.db.query(sql, [userUuidBuffer, fieldUuidBuffer], function (err) {
606
- if (err) that.log.warn(logPrefix + err.message);
607
- that.emitter.emit(msgUuid, err);
608
- cb(err);
609
- });
610
- });
611
- };
612
-
613
- DataWriter.prototype.runDumpServer = function runDumpServer(cb) {
614
- const that = this,
615
- args = [],
616
- options = {
617
- 'Content-Type': 'application/sql',
618
- 'exchange': that.exchangeName + '_dataDump',
619
- 'intercom': that.intercom,
620
- 'minPort': (that.amsync && that.amsync.minPort) ? that.amsync.minPort : null,
621
- 'maxPort': (that.amsync && that.amsync.maxPort) ? that.amsync.maxPort : null,
622
- 'host': (that.amsync && that.amsync.host) ? that.amsync.host : null,
623
- 'log': that.log,
624
- };
625
-
626
- if (that.db.conf.host) {
627
- args.push('-h');
628
- args.push(that.db.conf.host);
629
- }
630
-
631
- args.push('-u');
632
- args.push(that.db.conf.user);
633
-
634
- if (that.db.conf.password) {
635
- args.push('-p' + that.db.conf.password);
636
- }
637
-
638
- args.push('--single-transaction');
639
- args.push('--hex-blob');
640
- args.push(that.db.conf.database);
641
-
642
- // Tables
643
- args.push('users_db_version');
644
- args.push('user_data_fields');
645
- args.push('user_roles_rights');
646
- args.push('user_users');
647
- args.push('user_users_data');
648
-
649
- options.dataDumpCmd = {
650
- 'command': 'mysqldump',
651
- 'args': args,
652
- 'log': that.log
653
- };
654
-
655
- new amsync.SyncServer(options, cb);
656
- };
657
-
658
- DataWriter.prototype.setPassword = function setPassword(params, deliveryTag, msgUuid, cb) {
659
- const logPrefix = topLogPrefix + 'setPassword() - ',
660
- dbFields = [],
661
- userUuidBuffer = this.lUtils.uuidToBuffer(params.userUuid),
662
- that = this,
663
- sql = 'UPDATE user_users SET password = ? WHERE uuid = ?;';
664
-
665
- if (cb === undefined || typeof cb !== 'function') {
666
- cb = function () {};
667
- }
668
-
669
- if (userUuidBuffer === false) {
670
- const err = new Error('Invalid user uuid');
671
- that.log.warn(logPrefix + err.message);
672
- that.emitter.emit(msgUuid, err);
673
- return cb(err);
674
- }
675
-
676
- if (params.password === false) {
677
- dbFields.push('');
678
- } else {
679
- dbFields.push(params.password);
680
- }
681
-
682
- dbFields.push(userUuidBuffer);
683
- that.db.query(sql, dbFields, function (err) {
684
- if (err) that.log.warn(logPrefix + err.message);
685
- that.emitter.emit(msgUuid, err);
686
- cb(err);
687
- });
688
- };
689
-
690
- DataWriter.prototype.setUsername = function setUsername(params, deliveryTag, msgUuid, cb) {
691
- const logPrefix = topLogPrefix + 'setUsername() - ',
692
- userUuidBuffer = this.lUtils.uuidToBuffer(params.userUuid),
693
- dbFields = [params.username, userUuidBuffer],
694
- that = this,
695
- sql = 'UPDATE user_users SET username = ? WHERE uuid = ?;';
696
-
697
- if (cb === undefined || typeof cb !== 'function') {
698
- cb = function () {};
699
- }
700
-
701
- if (userUuidBuffer === false) {
702
- const err = new Error('Invalid user uuid');
703
- that.log.warn(logPrefix + err.message);
704
- that.emitter.emit(msgUuid, err);
705
- return cb(err);
706
- }
707
-
708
- that.db.query(sql, dbFields, function (err) {
709
- if (err) that.log.warn(logPrefix + err.message);
710
- that.emitter.emit(msgUuid, err);
711
- cb(err);
712
- });
713
- };
714
-
715
- exports = module.exports = DataWriter;