lint: Fix some straightforward ESLint errors

This commit is contained in:
Richard Hansen 2020-12-08 03:20:59 -05:00
parent ac086c7925
commit ff19181cd1
10 changed files with 154 additions and 153 deletions

View file

@ -1,3 +1,5 @@
'use strict';
/**
* The DB Module provides a database initalized with the settings
* provided by the settings module
@ -25,7 +27,8 @@ const log4js = require('log4js');
const util = require('util');
// set database settings
const db = new ueberDB.database(settings.dbType, settings.dbSettings, null, log4js.getLogger('ueberDB'));
const db =
new ueberDB.database(settings.dbType, settings.dbSettings, null, log4js.getLogger('ueberDB'));
/**
* The UeberDB Object that provides the database functions
@ -36,41 +39,38 @@ exports.db = null;
* Initalizes the database with the settings provided by the settings module
* @param {Function} callback
*/
exports.init = function () {
// initalize the database async
return new Promise((resolve, reject) => {
db.init((err) => {
if (err) {
// there was an error while initializing the database, output it and stop
console.error('ERROR: Problem while initalizing the database');
console.error(err.stack ? err.stack : err);
process.exit(1);
}
exports.init = async () => await new Promise((resolve, reject) => {
db.init((err) => {
if (err) {
// there was an error while initializing the database, output it and stop
console.error('ERROR: Problem while initalizing the database');
console.error(err.stack ? err.stack : err);
process.exit(1);
}
// everything ok, set up Promise-based methods
['get', 'set', 'findKeys', 'getSub', 'setSub', 'remove', 'doShutdown'].forEach((fn) => {
exports[fn] = util.promisify(db[fn].bind(db));
});
// set up wrappers for get and getSub that can't return "undefined"
const get = exports.get;
exports.get = async function (key) {
const result = await get(key);
return (result === undefined) ? null : result;
};
const getSub = exports.getSub;
exports.getSub = async function (key, sub) {
const result = await getSub(key, sub);
return (result === undefined) ? null : result;
};
// exposed for those callers that need the underlying raw API
exports.db = db;
resolve();
// everything ok, set up Promise-based methods
['get', 'set', 'findKeys', 'getSub', 'setSub', 'remove', 'doShutdown'].forEach((fn) => {
exports[fn] = util.promisify(db[fn].bind(db));
});
// set up wrappers for get and getSub that can't return "undefined"
const get = exports.get;
exports.get = async (key) => {
const result = await get(key);
return (result === undefined) ? null : result;
};
const getSub = exports.getSub;
exports.getSub = async (key, sub) => {
const result = await getSub(key, sub);
return (result === undefined) ? null : result;
};
// exposed for those callers that need the underlying raw API
exports.db = db;
resolve();
});
};
});
exports.shutdown = async (hookName, context) => {
await exports.doShutdown();