Skip to content

Commit

Permalink
add post report query test, query and index route ✅
Browse files Browse the repository at this point in the history
Relates #33 #34 #35
  • Loading branch information
haydnba committed May 19, 2018
1 parent ab2583b commit 3a8b486
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/model/queries/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const getUserChallenges = require('./get_user_challenges');

const postChallenge = require('./post_challenge');
const postMessage = require('./post_message');
const postReport = require('./post_report');
const postUserChallenge = require('./post_user_challenge');
const postNewUser = require('./post_new_user');

Expand All @@ -21,6 +22,7 @@ module.exports = {
getUserChallenges,
postChallenge,
postMessage,
postReport,
postUserChallenge,
postNewUser,
updateUserChallenge,
Expand Down
13 changes: 13 additions & 0 deletions src/model/queries/post_report.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const db = require('../database/db_connection');

const postReport = (userId, challengeId, report) =>
db.query(
`
INSERT INTO chg_report (user_id, challenge_id, body)
VALUES ($1, $2, $3)
RETURNING id;
`,
[userId, challengeId, report],
);

module.exports = postReport;
3 changes: 2 additions & 1 deletion src/test/model/post_report.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ test('Test postChallenge query', (t) => {
runDbBuild()
.then((res) => {
t.ok(res);
return postReport(3, 3, 'This is a new test report');
return postReport(2, 3, 'This is a test report');
})
.then((id) => {
console.log(id);
t.ok(id, 'postReport returns new report id');
t.end();
})
Expand Down

0 comments on commit 3a8b486

Please sign in to comment.