-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
260 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,16 @@ | ||
const pgp = require('pg-promise')(); | ||
const url = require('url'); | ||
require('env2')('./config.env'); | ||
|
||
let options = {}; | ||
|
||
|
||
if (process.env.TRAVIS === 'true') { | ||
options = { | ||
database: 'travis_ci_test', | ||
user: 'postgres', | ||
}; | ||
} else { | ||
let DB_URL = process.env.DB_URL; | ||
|
||
if (process.env.NODE_ENV === 'test') { | ||
DB_URL = process.env.TEST_DB_URL; | ||
} | ||
require('env2')('./config.env'); | ||
|
||
if (!DB_URL) { | ||
throw new Error('Environment variable DB_URL must be set!'); | ||
} | ||
const DB_URL = | ||
process.env.ENV === 'test' | ||
? process.env.TEST_DB_URL | ||
: process.env.DB_URL; | ||
|
||
const params = url.parse(DB_URL); | ||
const [username, password] = params.auth.split(':'); | ||
options = { | ||
host: params.hostname, | ||
port: params.port, | ||
database: params.pathname.split('/')[1], | ||
max: process.env.DB_MAX_CONNECTIONS || 2, | ||
user: username, | ||
password, | ||
ssl: params.hostname !== 'localhost', | ||
}; | ||
if (!DB_URL) { | ||
throw new Error('Environment variable DB_URL must be set!'); | ||
} | ||
|
||
|
||
module.exports = pgp(options); | ||
module.exports = pgp({ | ||
DB_URL, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,27 @@ | ||
const dbConnect = require('../database/db_connect.js'); | ||
|
||
// get username and password from users table | ||
const getUserData = username => | ||
dbConnect.query('SELECT password FROM users WHERE username=$1', [username]) | ||
.then((res) => { | ||
console.log('res0', res[0]); | ||
return res[0]; | ||
}); | ||
// .catch(err => console.log(err)); | ||
// get a symptom from symptoms table | ||
const getUserData = username => dbConnect.query('SELECT password FROM users WHERE username=$1', [username]) | ||
.then(res => res[0]); | ||
|
||
// get scale comments for symptom scale | ||
|
||
// get a factor from factors table | ||
// get all user symptoms from symptoms table | ||
const getSymptoms = username => dbConnect.query('select symptom from symptoms where user_id = (select id from users where username=$1)', [username]); | ||
// get all user factors from factor table | ||
|
||
// get scale comment for factor scale | ||
const getFactors = username => dbConnect.query('select factor from factors where user_id = (select id from users where username=$1)', [username]); | ||
|
||
// get specific symptom ratings | ||
// get scale comments for symptom scale | ||
const getSymptomScale = (symptom, username) => dbConnect.query('select * from symptom_scale where symptom_id = (select id from symptoms where symptom=$1) and user_id = (select id from users where username=$2);)', [symptom, username]); | ||
|
||
// get specific factor ratings | ||
// get scale comment for factor scale | ||
const getFactorScale = (factor, username) => dbConnect.query('select * from factor_scale where factor_id = (select id from factors where factor=$1) and user_id = (select id from users where username=$2);)', [factor, username]); | ||
|
||
// get specific symptom data | ||
const getSymptomRatings = username => dbConnect.query('select symptom_data.rating, symptom_data.date_entered, symptoms.symptom from symptom_data left join symptoms on symptoms.id = symptom_data.symptom_id where symptom_data.user_id = (select id from users where username=$1)', [username]); | ||
// get specific factor data | ||
const getFactorRatings = username => dbConnect.query('select factor_data.rating, factor_data.date_entered, factors.factor from factor_data left join factors on factors.id = factor_data.factor_id where factor_data.user_id = (select id from users where username=$1)', [username]); | ||
|
||
module.exports = { getUserData }; | ||
module.exports = { | ||
getUserData, getSymptoms, getFactors, getSymptomScale, getFactorScale, getSymptomRatings, getFactorRatings, | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,71 @@ | ||
const runDbBuild = require('../model/database/db_build.js'); | ||
const { getUserData } = require('../model/queries/getQueries'); | ||
const dbConnect = require('../model/database/db_connect'); | ||
const dbConnection = require('../model/database/db_connect'); | ||
const { getUserData, getSymptoms, getFactors } = require('../model/queries/getQueries'); | ||
// const { postUserData } = require('../model/queries/postQueries'); | ||
const test = require('tape'); | ||
|
||
runDbBuild(); | ||
|
||
test('simple test', (t) => { | ||
dbConnect.query('SELECT * FROM users') | ||
.then(res => res[0]).then((queryResult) => { | ||
t.deepEqual( | ||
Object.keys(queryResult), | ||
['id', 'username', 'password'], | ||
'three keys', | ||
// test query to get username and password from users table | ||
test('testing that getUserData returns an object with user password', (t) => { | ||
runDbBuild() | ||
.then((res) => { | ||
t.ok(res); | ||
return getUserData('eade'); | ||
}) | ||
.catch((e) => { | ||
t.error(e, 'error building'); | ||
t.end(); | ||
}) | ||
.then((queryResult) => { | ||
t.equal( | ||
queryResult.password, | ||
'passworddd', | ||
'queryResult should contain passworddd', | ||
); | ||
t.equal(queryResult.username, 'eade', 'returns eade'); | ||
t.equal(queryResult.password, 'passworddd', 'should return passworddd'); | ||
t.end(); | ||
}) | ||
.catch((e) => { | ||
t.error(e, 'error with getting user data'); | ||
t.end(); | ||
}); | ||
}); | ||
|
||
// test query to get username and password from users table | ||
test('testing that getUserData returns an object with user password', (t) => { | ||
getUserData('eade').then((queryResult) => { | ||
t.equal( | ||
queryResult.password, | ||
'passworddd', | ||
'queryResult should contain passworddd', | ||
); | ||
t.end(); | ||
}) | ||
.catch(console.log); | ||
}); | ||
|
||
|
||
// test query to get a symptom from symptoms table | ||
test('testing symptoms query returns something', (t) => { | ||
runDbBuild() | ||
.then(() => getSymptoms('eade')) | ||
.then((queryResult) => { | ||
t.ok(queryResult); | ||
t.end(); | ||
}) | ||
.catch((e) => { | ||
t.error(e, 'error with symptoms query'); | ||
t.end(); | ||
}); | ||
}); | ||
|
||
// test query to get scale comments for symptom scale | ||
|
||
// test query to get a factor from factors table | ||
test('testing factors query returns something', (t) => { | ||
runDbBuild() | ||
.then(() => getFactors('eade')) | ||
.then((queryResult) => { | ||
t.ok(queryResult); | ||
t.end(); | ||
}) | ||
.catch((e) => { | ||
t.error(e, 'error with factors query'); | ||
t.end(); | ||
}); | ||
}); | ||
|
||
// test query to get scale comment for factor scale | ||
|
||
// test query to get specific symptom ratings | ||
|
||
|
||
// test query to get specific factor ratings | ||
|
||
test.onFinish(() => { | ||
dbConnection.$pool.end(); | ||
}); |
Oops, something went wrong.