Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 40 additions & 41 deletions src/config/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ require("env2")(".env");
const Sequelize = require("sequelize");

class Database {
sequelize;
sequelize_ssl;

constructor() {
if (Database._instance) {
Expand All @@ -30,12 +28,13 @@ class Database {
} catch (error) {
console.error("Unable to connect to the database:", error);
}

Database._instance = this;
}

static getInstance() {
return Database._instance;
if (!this._instance){
this._instance = new Database();
}
return this._instance;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure how this would work in theory - static methods don’t have access to this, they’re class methods. this refers to instance methods...

}

parseSSLEnvVar() {
Expand All @@ -60,7 +59,7 @@ class Database {
const attributes = JSON.parse(worker.attributes);
const contact_uri = attributes.contact_uri;
console.log("createWorker: now attempting sequelize insert worker");
return sequelize.query(
return this.sequelize.query(
"insert into worker (contact_uri,sid) values ('" +
contact_uri +
"','" +
Expand All @@ -71,11 +70,11 @@ class Database {

createWorkerApply(contact_uri, friendlyName, authenticateCode) {
console.log("createWorkerApply: now attempting sequelize insert row");
return sequelize.query(
return this.sequelize.query(
"insert into workerapply (contact_uri,friendlyName,authenticateCode,status) values(?,?,?,'incomplete')",
{
replacements: [contact_uri, friendlyName, authenticateCode],
type: sequelize.QueryTypes.INSERT,
type: this.sequelize.QueryTypes.INSERT,
}
);
}
Expand All @@ -93,14 +92,14 @@ class Database {
}

getRowFromWorkerTable(contact_uri) {
return sequelize.query(
return this.sequelize.query(
"select * from worker where contact_uri='" + contact_uri + "'",
{ type: sequelize.QueryTypes.SELECT }
{ type: this.sequelize.QueryTypes.SELECT }
);
}

async updateWorkerContact_uri(oldContact_uri, newContact_uri) {
var result = await sequelize.query(
var result = await this.sequelize.query(
"update worker set contact_uri='" +
newContact_uri +
"' where contact_uri='" +
Expand Down Expand Up @@ -129,9 +128,9 @@ class Database {
}

async getWorkerIdFromSid(workerSid) {
var selectResult = await sequelize.query(
var selectResult = await this.sequelize.query(
"select * from worker where sid='" + workerSid + "'",
{ type: sequelize.QueryTypes.SELECT }
{ type: this.sequelize.QueryTypes.SELECT }
);
console.log(
"getWorkerIdFromSid: selectResult: " + JSON.stringify(selectResult)
Expand All @@ -147,11 +146,11 @@ class Database {
}

async getFunctionalityStatus(functionality) {
var selectResult = await sequelize.query(
var selectResult = await this.sequelize.query(
"select * from systemstatus where function=?",
{
replacements: [functionality],
type: sequelize.QueryTypes.SELECT,
type: this.sequelize.QueryTypes.SELECT,
}
);
if (selectResult.length == 0) {
Expand Down Expand Up @@ -193,59 +192,59 @@ class Database {

insertConferenceParticipant(workerSid, callSid, conferenceSid) {
console.log("insertConferenceParticipant");
return sequelize.query(
return this.sequelize.query(
"insert into conference_participant (workerSid,callSid,conferenceSid) " +
"values(?,?,?)",
{
replacements: [workerSid, callSid, conferenceSid],
type: sequelize.QueryTypes.INSERT,
type: this.sequelize.QueryTypes.INSERT,
}
);
}

insertCallSidWorkerSid(callSid, workerSid) {
console.log("insertCallSidWorkerSid");
return sequelize.query(
return this.sequelize.query(
"insert into callsid_workersid (callsid,workersid) " + "values(?,?)",
{
replacements: [callSid, workerSid],
type: sequelize.QueryTypes.INSERT,
type: this.sequelize.QueryTypes.INSERT,
}
);
}

insertAdminPassword(workerId, passwordHash, adminTaskId) {
return sequelize.query(
return this.sequelize.query(
"insert into adminPassword " +
"(workerId,passwordHash,adminTaskId) " +
"values " +
"(?,?,?)",
{
replacements: [workerId, passwordHash, adminTaskId],
type: sequelize.QueryTypes.INSERT,
type: this.sequelize.QueryTypes.INSERT,
}
);
}

updateAdminPassword(workerId, passwordHash, adminTaskId) {
return sequelize.query(
return this.sequelize.query(
"update adminPassword " +
"set passwordHash=? " +
"where workerId=? " +
"and adminTaskId=?",
{
replacements: [passwordHash, workerId, adminTaskId],
type: sequelize.QueryTypes.UPDATE,
type: this.sequelize.QueryTypes.UPDATE,
}
);
}

async getAdminTaskId(adminTask) {
var selectResult = await sequelize.query(
var selectResult = await this.sequelize.query(
"select * from adminTask " + "where adminTask=?",
{
replacements: [adminTask],
type: sequelize.QueryTypes.SELECT,
type: this.sequelize.QueryTypes.SELECT,
}
);
if (selectResult.length == 0) {
Expand All @@ -260,11 +259,11 @@ class Database {

//todo: this will need to get updated after we establish the 'canceled' unique constraint
async getPasswordHash(workerId, adminTaskId) {
var selectResult = await sequelize.query(
var selectResult = await this.sequelize.query(
"select * from adminPassword " + "where workerId=? and adminTaskId=?",
{
replacements: [workerId, adminTaskId],
type: sequelize.QueryTypes.SELECT,
type: this.sequelize.QueryTypes.SELECT,
}
);
if (selectResult.length == 0) {
Expand All @@ -281,7 +280,7 @@ class Database {
if (id == null) {
throw workerSid + " does not exist in worker table";
} else {
return sequelize.query(
return this.sequelize.query(
"update available_notification_request set notification_sent=true" +
" where worker_id=" +
id +
Expand All @@ -298,7 +297,7 @@ class Database {
"select * from available_notification_request_worker where notification_sent=false and sid!='" +
workerSid +
"'",
{ type: sequelize.QueryTypes.SELECT }
{ type: this.sequelize.QueryTypes.SELECT }
)
.then(function (result) {
console.log(result);
Expand All @@ -320,11 +319,11 @@ class Database {
}

async getWorkerSidFromCallSid(callSid) {
var selectResult = await sequelize.query(
var selectResult = await this.sequelize.query(
"select * from callsid_workersid where callsid=?",
{
replacements: [callSid],
type: sequelize.QueryTypes.SELECT,
type: this.sequelize.QueryTypes.SELECT,
}
);
console.log(
Expand All @@ -346,13 +345,13 @@ class Database {
//or array of workerSids for multiple participants
//eventually it should just have a single return type of array
async getOtherParticipantWorkerSid(conferenceSid, callSid) {
var selectResult = await sequelize.query(
var selectResult = await this.sequelize.query(
"select * from conference_participant " +
"where conferenceSid=? and " +
"callSid!=?",
{
replacements: [conferenceSid, callSid],
type: sequelize.QueryTypes.SELECT,
type: this.sequelize.QueryTypes.SELECT,
}
);
console.log(
Expand All @@ -377,7 +376,7 @@ class Database {
}

insertEvent(reqBody) {
return sequelize.query(
return this.sequelize.query(
"insert into event " +
"(eventType,eventDescription,timestamp,resourceType,resourceSid,workerSid,data) " +
"values " +
Expand All @@ -392,7 +391,7 @@ class Database {
reqBody.WorkerSid,
reqBody.Data,
],
type: sequelize.QueryTypes.INSERT,
type: this.sequelize.QueryTypes.INSERT,
}
);
}
Expand All @@ -404,7 +403,7 @@ class Database {
outboundWorkerSid,
conferenceSid
) {
return sequelize.query(
return this.sequelize.query(
"insert into conference " +
"(inboundCallSid,outboundCallSid,inboundWorkerId,outboundWorkerId,conferenceSid) " +
"values " +
Expand All @@ -420,20 +419,20 @@ class Database {
outboundWorkerSid,
conferenceSid,
],
type: sequelize.QueryTypes.INSERT,
type:this.sequelize.QueryTypes.INSERT,
}
);
}

async getMembershipRequest(contact_uri, authenticateCode) {
var selectResult = await sequelize.query(
var selectResult = await this.sequelize.query(
"select * from workerapply where contact_uri='" +
contact_uri +
"' and status='incomplete' " +
"and authenticatecode='" +
authenticateCode +
"'",
{ type: sequelize.QueryTypes.SELECT }
{ type: this.sequelize.QueryTypes.SELECT }
);
console.log(
"getMembershipRequest: selectResult: " + JSON.stringify(selectResult)
Expand All @@ -446,11 +445,11 @@ class Database {
}

async updateMembershipRequestToComplete(contact_uri) {
return sequelize.query(
return this.sequelize.query(
"update workerapply " + "set status='complete' " + "where contact_uri=?",
{
replacements: [contact_uri],
type: sequelize.QueryTypes.UPDATE,
type: this.sequelize.QueryTypes.UPDATE,
}
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/sms.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ class Sms {
if (!this.parameterCountMatch(command, parameterObj)) {
responseValue =
"Incorrect syntax for '" +
command.commandName +
command.name +
"':\n" +
command.parameterUsage;
return responseValue;
Expand Down
3 changes: 2 additions & 1 deletion src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ app.post("/submit_newuser", async function (req, res) {
app.post("/sms", twilio.webhook(), async function (req, res) {
var body = req.body.Body;
var parameterObj;
console.log("/sms: message SID " + req.body.sid);
console.log(`/sms: req.body: ${JSON.stringify(req.body)}`);
console.log("/sms: message SID " + req.body.SmsSid);
console.log(body);
//replace multiple spaces with single space

Expand Down