Skip to content

Commit

Permalink
added functionality for pg create
Browse files Browse the repository at this point in the history
  • Loading branch information
iangeckeler committed Jul 8, 2019
1 parent 510f720 commit fc4d25c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
14 changes: 14 additions & 0 deletions __tests__/functions/databases/postgresql/send.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// const client = require("../../../../index")(process.env.SID, process.env.AUTH, {
// isPostgres: true,
// connectionURI: "postgres://student:ilovetesting@localhost/twoauthtests"
// });

// // client.create("ian", "+17604207520");

// client
// .send("ian")
// .then(res => console.log(res))
// .catch(err => console.log(err));
// // describe("Tests for Postgres Send", () => {

// // });
41 changes: 34 additions & 7 deletions functions/databases/postgres/send.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,42 @@
module.exports = function(userID, phone) {
module.exports = function(userID) {
const { pgConnect, client } = this;
return new Promise((resolve, reject) => {
this.pgConnect()
pgConnect()
.then(({ database, done }) => {
// pgClient.query... blah blah logic
//invoke done before your resolve this promise
done();
const query = "SELECT * FROM twoauthusers WHERE userID=$1";
const values = [String(userID)];
database.query(query, values, (err, res) => {
if (err) reject(err);
const { sid, phone } = res.rows[0];
if (!sid)
reject(new Error("SID Error: No SID exists for this user."));
if (!phone)
reject(
new Error(
"Phone Number Error: No phone number exists for this user."
)
);
//invoke done before your resolve this promise
client.verify
.services(sid)
.verifications.create({
to: phone,
channel: "sms"
})
.then(verification => {
done();
resolve(verification);
})
.catch(err => {
done();
reject(err);
});
});
})
.catch((err, done) => {
//invoke done before you reject
.catch(err => {
done();
reject(err);
//"userID Error: This userID has not been created yet."
});
});
};

0 comments on commit fc4d25c

Please sign in to comment.