diff --git a/src/model/queries/index.js b/src/model/queries/index.js index d077e2a..5c0a1e0 100644 --- a/src/model/queries/index.js +++ b/src/model/queries/index.js @@ -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'); @@ -21,6 +22,7 @@ module.exports = { getUserChallenges, postChallenge, postMessage, + postReport, postUserChallenge, postNewUser, updateUserChallenge, diff --git a/src/model/queries/post_report.js b/src/model/queries/post_report.js new file mode 100644 index 0000000..3e0ba39 --- /dev/null +++ b/src/model/queries/post_report.js @@ -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; diff --git a/src/test/model/post_report.test.js b/src/test/model/post_report.test.js index a2b8e33..578b9cd 100644 --- a/src/test/model/post_report.test.js +++ b/src/test/model/post_report.test.js @@ -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(); })