From 270a4e845f3e373821b26877a0258b39fed6ecc5 Mon Sep 17 00:00:00 2001 From: Cleop Date: Fri, 2 Dec 2016 13:00:20 +0000 Subject: [PATCH 1/2] Adds template literals to sql request on reviews.js --- server/database/queries/reviews.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/server/database/queries/reviews.js b/server/database/queries/reviews.js index 5b49408..471a3e0 100644 --- a/server/database/queries/reviews.js +++ b/server/database/queries/reviews.js @@ -1,9 +1,9 @@ const db_conn = require('../db_connection'); const getAll = cb => { - db_conn.query('SELECT user_reviews.user_id, reviews.review_id, user_reviews.resource_id, reviews.title, \ + db_conn.query('SELECT ur.user_id, reviews.review_id, ur.resource_id, reviews.title, \ reviews.rating, reviews.content, reviews.created_at \ - FROM user_reviews \ + FROM user_reviews AS ur\ INNER JOIN reviews \ ON user_reviews.review_id=reviews.review_id;', (error, data) => { @@ -12,9 +12,9 @@ const getAll = cb => { ); }; const getAllByUserId = (user_id, cb) => { - db_conn.query('SELECT user_reviews.user_id, reviews.review_id, user_reviews.resource_id, reviews.title, \ + db_conn.query('SELECT ur.user_id, reviews.review_id, ur.resource_id, reviews.title, \ reviews.rating, reviews.content, reviews.created_at \ - FROM user_reviews \ + FROM user_reviews AS ur\ INNER JOIN reviews \ ON user_reviews.review_id=reviews.review_id \ WHERE user_reviews.user_id = $1;', @@ -43,7 +43,7 @@ const insert = (review, user_id, cb) => { INSERT INTO user_reviews (review_id, user_id, resource_id) \ VALUES ((SELECT review_id FROM new_review), $4, $5);', [review.title, review.rating, review.content, user_id, review.resource_id], - error => { + error => { return cb(error || null); } ); From 41f1c01fe8dc94d81afd226d109ac866a1b92b31 Mon Sep 17 00:00:00 2001 From: Cleop Date: Fri, 2 Dec 2016 14:09:12 +0000 Subject: [PATCH 2/2] Adds as for other table variables --- server/database/queries/reviews.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/server/database/queries/reviews.js b/server/database/queries/reviews.js index 471a3e0..82e69b0 100644 --- a/server/database/queries/reviews.js +++ b/server/database/queries/reviews.js @@ -1,10 +1,10 @@ const db_conn = require('../db_connection'); const getAll = cb => { - db_conn.query('SELECT ur.user_id, reviews.review_id, ur.resource_id, reviews.title, \ - reviews.rating, reviews.content, reviews.created_at \ + db_conn.query('SELECT ur.user_id, r.review_id, ur.resource_id, r.title, \ + r.rating, r.content, r.created_at \ FROM user_reviews AS ur\ - INNER JOIN reviews \ + INNER JOIN reviews AS r \ ON user_reviews.review_id=reviews.review_id;', (error, data) => { return (error ? cb(error) : cb(null, data.rows)); @@ -12,10 +12,10 @@ const getAll = cb => { ); }; const getAllByUserId = (user_id, cb) => { - db_conn.query('SELECT ur.user_id, reviews.review_id, ur.resource_id, reviews.title, \ - reviews.rating, reviews.content, reviews.created_at \ + db_conn.query('SELECT ur.user_id, r.review_id, ur.resource_id, r.title, \ + r.rating, r.content, r.created_at \ FROM user_reviews AS ur\ - INNER JOIN reviews \ + INNER JOIN reviews AS r\ ON user_reviews.review_id=reviews.review_id \ WHERE user_reviews.user_id = $1;', [user_id],