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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ npm-debug.log*
*.dump
*.sh
*.ignore
*.log
586 changes: 285 additions & 301 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
"passport": "^0.6.0",
"passport-local": "^1.0.0",
"path": "^0.12.7",
"pg": "^8.7.3",
"pg": "^7.11.0",
"pug": "^3.0.1",
"querystring": "^0.2.0",
"request": "^2.88.2",
"sequelize": "^6.20.1",
"sequelize": "^5.21.1",
"swagger-jsdoc": "^6.2.5",
"swagger-ui-express": "^4.5.0",
"tonegenerator": "^0.3.2",
Expand Down
5 changes: 2 additions & 3 deletions src/appInitializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ class AppInitializer {
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use("/other_route", require("./other_route").router);
//todo: re-enable this session code? or outsource session management to a SaaS like firebase?
//app.use(session({ secret: process.env.SESSION_SECRET }));
app.use(session({ secret: process.env.SESSION_SECRET }));
app.use(passport.initialize());
//app.use(passport.session());
app.use(passport.session());
app.use(flash());
app.use("/public", express.static(process.cwd() + "/public"));
app.set("views", path.join(__dirname, "../public", "views"));
Expand Down
124 changes: 58 additions & 66 deletions src/config/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ require("env2")(".env");
const Sequelize = require("sequelize");

class Database {

sequelize;
sequelize_ssl;

constructor() {
if (Database._instance) {
throw new Error(
Expand All @@ -24,7 +26,7 @@ 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);
}
Expand Down Expand Up @@ -58,7 +60,7 @@ class Database {
const attributes = JSON.parse(worker.attributes);
const contact_uri = attributes.contact_uri;
console.log("createWorker: now attempting sequelize insert worker");
return this.sequelize.query(
return sequelize.query(
"insert into worker (contact_uri,sid) values ('" +
contact_uri +
"','" +
Expand All @@ -69,11 +71,11 @@ class Database {

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

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

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

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

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

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

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

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

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

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

//todo: this will need to get updated after we establish the 'canceled' unique constraint
async getPasswordHash(workerId, adminTaskId) {
var selectResult = await this.sequelize.query(
var selectResult = await sequelize.query(
"select * from adminPassword " + "where workerId=? and adminTaskId=?",
{
replacements: [workerId, adminTaskId],
type: this.sequelize.QueryTypes.SELECT,
type: sequelize.QueryTypes.SELECT,
}
);
if (selectResult.length == 0) {
Expand All @@ -280,7 +281,7 @@ class Database {
if (id == null) {
throw workerSid + " does not exist in worker table";
} else {
return this.sequelize.query(
return sequelize.query(
"update available_notification_request set notification_sent=true" +
" where worker_id=" +
id +
Expand All @@ -292,12 +293,12 @@ class Database {
//we pass in workerSid here because we don't want the worker who just went to Idle to get
//a notification of an available worker (since calling themselves isn't an option)
iterateThroughUnsentNotificationsForMessaging(callback, workerSid) {
this.sequelize
sequelize
.query(
"select * from available_notification_request_worker where notification_sent=false and sid!='" +
workerSid +
"'",
{ type: this.sequelize.QueryTypes.SELECT }
{ type: sequelize.QueryTypes.SELECT }
)
.then(function (result) {
console.log(result);
Expand All @@ -319,11 +320,11 @@ class Database {
}

async getWorkerSidFromCallSid(callSid) {
var selectResult = await this.sequelize.query(
var selectResult = await sequelize.query(
"select * from callsid_workersid where callsid=?",
{
replacements: [callSid],
type: this.sequelize.QueryTypes.SELECT,
type: sequelize.QueryTypes.SELECT,
}
);
console.log(
Expand All @@ -345,13 +346,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 this.sequelize.query(
var selectResult = await sequelize.query(
"select * from conference_participant " +
"where conferenceSid=? and " +
"callSid!=?",
{
replacements: [conferenceSid, callSid],
type: this.sequelize.QueryTypes.SELECT,
type: sequelize.QueryTypes.SELECT,
}
);
console.log(
Expand All @@ -375,34 +376,25 @@ class Database {
}
}

//todo: I'm getting the error:
// SequelizeDatabaseError: relation "event" does not exist
//verify whether the schema I gave Mina has this relation in it
async insertEvent(reqBody) {
try{
let result = await this.sequelize.query(
"insert into event " +
"(eventType,eventDescription,timestamp,resourceType,resourceSid,workerSid,data) " +
"values " +
"(?,?,?,?,?,?,?)",
{
replacements: [
reqBody.EventType || "",
reqBody.EventDescription || "",
reqBody.Timestamp || "",
reqBody.ResourceType || "",
reqBody.ResourceSid || "",
reqBody.WorkerSid || "",
reqBody.Data || JSON.stringify({data:null}),
],
type: this.sequelize.QueryTypes.INSERT,
}
);
return result;
}
catch(err){
console.log(`error: ${err}`);
}
insertEvent(reqBody) {
return sequelize.query(
"insert into event " +
"(eventType,eventDescription,timestamp,resourceType,resourceSid,workerSid,data) " +
"values " +
"(?,?,?,?,?,?,?)",
{
replacements: [
reqBody.EventType,
reqBody.EventDescription,
reqBody.Timestamp,
reqBody.ResourceType,
reqBody.ResourceSid,
reqBody.WorkerSid,
reqBody.Data,
],
type: sequelize.QueryTypes.INSERT,
}
);
}

insertConference(
Expand All @@ -412,7 +404,7 @@ class Database {
outboundWorkerSid,
conferenceSid
) {
return this.sequelize.query(
return sequelize.query(
"insert into conference " +
"(inboundCallSid,outboundCallSid,inboundWorkerId,outboundWorkerId,conferenceSid) " +
"values " +
Expand All @@ -428,20 +420,20 @@ class Database {
outboundWorkerSid,
conferenceSid,
],
type: this.sequelize.QueryTypes.INSERT,
type: sequelize.QueryTypes.INSERT,
}
);
}

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

async updateMembershipRequestToComplete(contact_uri) {
return this.sequelize.query(
return sequelize.query(
"update workerapply " + "set status='complete' " + "where contact_uri=?",
{
replacements: [contact_uri],
type: this.sequelize.QueryTypes.UPDATE,
type: sequelize.QueryTypes.UPDATE,
}
);
}
Expand Down
9 changes: 4 additions & 5 deletions src/lib/availableNotifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,19 @@ var database = Database.getInstance();
class AvailableNotifier {
constructor() {
this.phoneNumberRegex = new RegExp("^\\+\\d+$");
this.database = Database.getInstance();
}
async create(workerSid) {
var result = await this.database.createAvailableNotificationRequest(workerSid);
var result = await database.createAvailableNotificationRequest(workerSid);
return result;
}

async updateToSent(workerSid) {
var result = await this.database.updateNotificationToSent(workerSid);
var result = await database.updateNotificationToSent(workerSid);
return result;
}

iterateSend(workerSid) {
var result = this.database.iterateThroughUnsentNotificationsForMessaging(
var result = database.iterateThroughUnsentNotificationsForMessaging(
this.send.bind(this),
workerSid
);
Expand All @@ -49,7 +48,7 @@ class AvailableNotifier {
})
.then((message) => {
console.log("send: message.sid: " + message.sid);
this.database.updateNotificationToSent(callbackParam.sid);
database.updateNotificationToSent(callbackParam.sid);
});
} else {
console.log(contact_uri + " is not a valid phone number.");
Expand Down
Loading