-
Notifications
You must be signed in to change notification settings - Fork 8
Added project_reviews migration #181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ryanbuui
wants to merge
11
commits into
master
Choose a base branch
from
project_reviews
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
58f0b08
Added project_reviews migration
ryanbuui e7404b5
Fixed typo and changed campaign id to skilled_impact_request_id
ryanbuui a8b71dd
Merge branch 'development' of https://github.com/Lambda-School-Labs/k…
ryanbuui c512c86
fixed seeds
sumeet-bansal 767ac2f
Merge branch 'project_reviews' of https://github.com/Lambda-School-La…
sumeet-bansal 34ad1f9
Added get/post routes for project_reviews API, Added total_reviews an…
ryanbuui c8d6f21
Merge branch 'master' into project_reviews
ryanbuui 0f9883b
Merge branch 'master' into project_reviews
ryanbuui c1e7a28
Reorganized files to match master's, added checks for ratings, implem…
ryanbuui f36de1c
Added users_review migration, also deleted total_reviews/total_stars …
ryanbuui 78b82d1
Made revisions to code to make cleaner and more efficient
ryanbuui File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,30 @@ | ||
| const express = require('express'); | ||
|
|
||
| const router = express.Router(); | ||
|
|
||
| const ProjectReviews = require('../../database/models/projectReviewsModel'); | ||
|
|
||
| router.post('/', async (req, res) => { | ||
| try { | ||
| const reviews = [req.body.likely_to_recommend, req.body.supporter_communication, req.body.provided_value]; | ||
| const validMetrics = reviews.filter((r) => !r.isInteger() || r < 1 || r > 5).length === 0; | ||
| if (!constantBool) return res.status(400).json({ message: "Incorrect input for review" }); | ||
| const [projectReview] = await ProjectReviews.insert(req.body); | ||
| return res.status(201).json({ projectReview }); | ||
| } catch (error) { | ||
| res.status(500).json({ error, message: 'Unable to add review' }); | ||
| } | ||
| }); | ||
|
|
||
| router.get('/:id', async (req, res) => { | ||
| try { | ||
| const { id } = req.params; | ||
| const projectReview = await ProjectReviews.findById(id); | ||
| if (!projectReview) return res.status(404).json({ message: 'Review not found in the database' }); | ||
| return res.status(200).json({ projectReview, msg: 'Review was found' }); | ||
| } catch (error) { | ||
| res.status(500).json({ error, message: 'Unable to make request to server' }); | ||
| } | ||
| }); | ||
|
|
||
| module.exports = router; |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -31,7 +31,7 @@ router.get('/', restricted, async (req, res) => { | |
| } | ||
| }); | ||
|
|
||
| router.get('/:id', restricted, async (req, res) => { | ||
| router.get('/:id'/* , restricted */, async (req, res) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you uncomment this please? |
||
| const { id } = req.params; | ||
|
|
||
| try { | ||
|
|
@@ -58,7 +58,7 @@ router.get('/:id', restricted, async (req, res) => { | |
| .json({ message: 'This account has been deactivated' }); | ||
| } | ||
| } | ||
|
|
||
| user.average_rating = user.total_stars / user.total_reviews; | ||
| return res.status(200).json({ user, message: 'The user was found' }); | ||
| } catch (err) { | ||
| log.error(err); | ||
|
|
@@ -85,6 +85,10 @@ router.get('/sub/:sub', restricted, async (req, res) => { | |
| .status(401) | ||
| .json({ message: 'This account has been deactivated' }); | ||
| } | ||
|
|
||
| user.average_rating = user.total_stars / user.total_reviews; | ||
| delete user.total_stars; | ||
| delete user.total_reviews; | ||
| return res.status(200).json({ user, message: 'The user was found' }); | ||
| } | ||
| return res.status(404).json({ message: 'User not found in the database' }); | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -5,7 +5,8 @@ exports.up = function (knex) { | |
| .references('campaigns.camp_id') | ||
| .onDelete('CASCADE') | ||
| .onUpdate('CASCADE'); | ||
| table.enum('skill', null, { useNative: true, enumName: 'enum_skills', existingType: true }).notNullable(); | ||
| table.enum('skill', null, { useNative: true, enumName: 'enum_skills', existingType: true }) | ||
| .notNullable(); | ||
|
Comment on lines
+8
to
+9
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Nothing was really changed here but can you please revert? Nice to keep the git history clean on migrations. |
||
| table.text('point_of_contact').notNullable(); | ||
| table.text('welcome_message').notNullable(); | ||
| table.text('our_contribution').notNullable(); | ||
|
|
||
This file contains hidden or 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,27 @@ | ||
|
|
||
| exports.up = function(knex) { | ||
| return knex.schema.createTable('project_reviews', table => { | ||
| table.increments('id').notNullable().unique(); | ||
| table.text("review").notNullable(); | ||
| table.integer("likely_to_recommend").notNullable(); | ||
| table.integer("supporter_communication").notNullable(); | ||
| table.integer("provided_value").notNullable(); | ||
| table.integer("supporter_user_id") | ||
| .references("supporters.sup_id") | ||
| .onDelete("CASCADE") | ||
| .onUpdate("CASCADE"); | ||
| table.integer("conservationist_user_id") | ||
| .notNullable() | ||
| .references("conservationists.cons_id") | ||
| .onDelete("CASCADE") | ||
| .onUpdate("CASCADE"); | ||
| table.integer("skilled_impact_request_id") | ||
| .references("skilled_impact_requests.id") | ||
| .onDelete("CASCADE") | ||
| .onUpdate("CASCADE"); | ||
| }); | ||
| }; | ||
|
|
||
| exports.down = function(knex) { | ||
| return knex.schema.dropTableIfExists('project_reviews'); | ||
| }; |
This file contains hidden or 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,14 @@ | ||
|
|
||
| exports.up = function (knex) { | ||
| return knex.schema.alterTable('users', (tbl) => { | ||
| tbl.integer('total_stars'); | ||
| tbl.integer('total_reviews'); | ||
| }); | ||
| }; | ||
|
|
||
| exports.down = function (knex) { | ||
| return knex.schema.alterTable('users', (tbl) => { | ||
| tbl.dropColumn('total_stars'); | ||
| tbl.dropColumn('total_reviews'); | ||
| }); | ||
| }; |
This file contains hidden or 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,15 @@ | ||
| const db = require('../dbConfig'); | ||
|
|
||
| async function insert(review) { | ||
| return db('project_reviews') | ||
| .insert(review) | ||
| .returning('*'); | ||
| } | ||
|
|
||
| async function findById(id) { | ||
| return db('project_reviews') | ||
| .where({ id }) | ||
| .first(); | ||
| } | ||
|
|
||
| module.exports = { insert, findById }; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move the
letinto the loop body here? Otherwise it doesn't really help with scoping.for (let i = 0; i < users.length; i++)