From 9a6b88195fecfab2ce68aebfcdadc29d142658f3 Mon Sep 17 00:00:00 2001 From: joshua sorkin Date: Wed, 12 Oct 2022 09:13:17 -0700 Subject: [PATCH 1/3] implement ES6 singleton in database.js per https://code.tutsplus.com/tutorials/how-to-implement-the-singleton-pattern-in-javascript-es6--cms-39927 --- src/config/database.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/config/database.js b/src/config/database.js index 09f9791..47fc687 100644 --- a/src/config/database.js +++ b/src/config/database.js @@ -2,7 +2,7 @@ require("env2")(".env"); const Sequelize = require("sequelize"); class Database { - + constructor() { if (Database._instance) { throw new Error( @@ -24,17 +24,18 @@ class Database { try { this.sequelize.authenticate(); - console.log("Database connection has been established successfully."); + console.log("Database onnection has been established successfully."); } catch (error) { console.error("Unable to connect to the database:", error); } +} - Database._instance = this; - } - - static getInstance() { - return Database._instance; +static getInstance() { + if (!this._instance){ + this._instance = new Database(); } + return this._instance; +} parseSSLEnvVar() { this.sequelize_ssl = process.env.SEQUELIZE_SSL.toLowerCase(); From 543b4c82de9c9430d51cdcb6e13f5f9f09de078e Mon Sep 17 00:00:00 2001 From: joshua sorkin Date: Wed, 12 Oct 2022 09:14:04 -0700 Subject: [PATCH 2/3] edit connection success console log --- src/config/database.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/database.js b/src/config/database.js index 47fc687..9853bed 100644 --- a/src/config/database.js +++ b/src/config/database.js @@ -24,7 +24,7 @@ class Database { try { this.sequelize.authenticate(); - console.log("Database onnection has been established successfully."); + console.log("Database connection has been established successfully."); } catch (error) { console.error("Unable to connect to the database:", error); } From 5ee6e4e71c352b771578cf974bee97fa73fa6dd9 Mon Sep 17 00:00:00 2001 From: joshua sorkin Date: Wed, 12 Oct 2022 09:21:08 -0700 Subject: [PATCH 3/3] change .commandName to .name to agree with command-config.json --- src/config/database.js | 1 + src/lib/sms.js | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/config/database.js b/src/config/database.js index 9853bed..209d0f0 100644 --- a/src/config/database.js +++ b/src/config/database.js @@ -399,6 +399,7 @@ static getInstance() { type: this.sequelize.QueryTypes.INSERT, } ); + console.log({result}); return result; } catch(err){ diff --git a/src/lib/sms.js b/src/lib/sms.js index a021874..506559e 100644 --- a/src/lib/sms.js +++ b/src/lib/sms.js @@ -416,7 +416,7 @@ class Sms { parameterCountMatch(command, parameterObj) { if ( parameterObj.commandArray.length == 1 && - command.commandName == "manual" + command.name == "manual" ) { return true; } else { @@ -436,7 +436,7 @@ class Sms { if (!this.parameterCountMatch(command, parameterObj)) { responseValue = "Incorrect syntax for '" + - command.commandName + + command.name + "':\n" + command.parameterUsage; return responseValue;