Skip to content

Commit

Permalink
Add doesCustomerExistInDB function
Browse files Browse the repository at this point in the history
Relates #25 #37 #60
  • Loading branch information
joeylouise committed May 10, 2017
1 parent 538b87b commit 1c3863d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/lib/doesCustomerExistInDB.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const connect = require('../../database/db_connection.js');

const doesCustomerExistInDB = (userCredentials, callback) => {
// query the database
const databaseQuery = 'SELECT * FROM users WHERE stripe_id IS NOT NULL AND github_username = $1';
const databaseParams = [userCredentials.username];
connect.query(databaseQuery, databaseParams, (err, result) => {
if (err) {
callback(err);
} else if (result.rows.length === 0) {
callback(null, false);
} else {
callback(null, result.rows[0]);
}
});
// if user has stripe id then return it
// otherwise return false
};

module.exports = doesCustomerExistInDB;

0 comments on commit 1c3863d

Please sign in to comment.