-
Notifications
You must be signed in to change notification settings - Fork 446
Abdiel Fernandez #491
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
CBMR
wants to merge
51
commits into
bloominstituteoftechnology:master
Choose a base branch
from
CBMR:master
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
Abdiel Fernandez #491
Changes from all commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
1b04b0b
added the trello URL
CBMR bd23360
added knex, sqlite3, dotenv, jest, supertest, nodemon
CBMR 1fc9fba
configured the knex file testing and development
CBMR da8d117
added the node modules to the gitignore
CBMR 39c36e5
added useNullAsDefault to the knex file
CBMR 19a1154
ran a migration and seed
CBMR 0e1ff4d
created the db config file and configured it
CBMR 310113a
created the index file and set the port for the server
CBMR 608c0c7
added .env file to the gitignore
CBMR e9d6bf3
created the server
CBMR 107b5f1
created tests fot the API
CBMR f384dbb
ran the migration on the main development database
CBMR 5068ac3
added cross env
CBMR a29a1c4
added the models
CBMR 48312ac
added the API endpoints
CBMR 343f9e8
added cors and moment.js
CBMR d50b424
added moment to format the timestamp
CBMR 7ef5ef5
added notes
CBMR ae6fd82
added notes
CBMR 8f3a771
added data
CBMR 9af9686
changed how the server grabs the times
CBMR 42ddfac
made a few changes to the schema of the database
CBMR 0ddf5da
added the data to the DB
CBMR 4ee6d2d
added the procfile for heroku
CBMR 7cbd4be
removed moment js from backend
CBMR f4a0f76
dropped the old table, create new notes and users
CBMR b366ba3
added bcryptjs and jwt
CBMR ed8ba7f
made a change to the getNotes
CBMR 73bd52f
started using express routes
CBMR 75a092e
added a users model
CBMR b83115f
created the routes using express router
CBMR 02b5ec5
corrected the if statement
CBMR 10f8a40
added data
CBMR 14e7800
made a change to how I get data
CBMR a2f7722
added routes
CBMR 719e5f9
added userModels
CBMR 825060b
Merge pull request #1 from CBMR/authentication
CBMR fe618a8
corrected endpoints
CBMR f6a6664
corrected the header data
CBMR 9c7d35a
removed a console log
CBMR 32b63b3
refactored the protected function
CBMR 3bfbbe3
corrected a bug
CBMR 98f1f5b
refactored
CBMR 60188d1
corrected bug
CBMR 5979820
bug fix
CBMR 021cf29
bug fix
CBMR a49ec68
bug fix
CBMR 0ac4550
bug fix
CBMR 1c8277c
refactored
CBMR 4b96f51
refactor
CBMR 2549350
bug fix
CBMR 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,5 @@ | ||
| .DS_Store | ||
|
|
||
| node_modules | ||
|
|
||
| .env |
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 @@ | ||
| web: node index.js |
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,6 @@ | ||
| const knex = require('knex') | ||
| const config = require('../knexfile') | ||
|
|
||
| const dbEnv = process.env.DB_ENV || 'development' | ||
|
|
||
| module.exports = knex(config[dbEnv]) |
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 @@ | ||
|
|
||
| exports.up = function(knex, Promise) { | ||
| return knex.schema.createTable('notes', table => { | ||
| table.increments(); | ||
|
|
||
| table.string('title', 255).notNullable(); | ||
| table.string('content', 10000).notNullable(); | ||
| table.boolean('completed').notNullable() | ||
| table.timestamp('time_posted', true).defaultTo(knex.fn.now()); | ||
| }) | ||
| }; | ||
|
|
||
| exports.down = function(knex, Promise) { | ||
| return knex.schema.dropTableIfExists('notes') | ||
| }; | ||
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,12 @@ | ||
|
|
||
| exports.up = function(knex, Promise) { | ||
| return knex.schema.table('notes', table => { | ||
| table.timestamp('time_updated', true) | ||
| }) | ||
| }; | ||
|
|
||
| exports.down = function(knex, Promise) { | ||
| return knex.schema.table('notes', table => { | ||
| table.dropColumn('time_updated') | ||
| }) | ||
| }; |
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,12 @@ | ||
|
|
||
| exports.up = function(knex, Promise) { | ||
| return knex.schema.table('notes', table => { | ||
| table.dropColumn('time_posted') | ||
| }) | ||
| }; | ||
|
|
||
| exports.down = function(knex, Promise) { | ||
| return knex.schema.table('notes', table => { | ||
| table.dropColumn('time_posted') | ||
| }) | ||
| }; |
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,12 @@ | ||
|
|
||
| exports.up = function(knex, Promise) { | ||
| return knex.schema.table('notes', table => { | ||
| table.timestamp('time_posted') | ||
| }) | ||
| }; | ||
|
|
||
| exports.down = function(knex, Promise) { | ||
| return knex.schema.table('notes', table => { | ||
| table.dropColumn('time_posted') | ||
| }) | ||
| }; |
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,10 @@ | ||
|
|
||
| exports.up = function(knex, Promise) { | ||
| return knex.schema.table('notes', table => { | ||
| table.dropColumn('time_updated') | ||
| }) | ||
| }; | ||
|
|
||
| exports.down = function(knex, Promise) { | ||
| return knex.schema.dropTableIfExists('notes') | ||
| }; |
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,12 @@ | ||
|
|
||
| exports.up = function(knex, Promise) { | ||
| return knex.schema.table('notes', table => { | ||
| table.timestamp('time_updated') | ||
| }) | ||
| }; | ||
|
|
||
| exports.down = function(knex, Promise) { | ||
| return knex.schema.table('notes', table => { | ||
| table.dropColumn('time_updated') | ||
| }) | ||
| }; |
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,13 @@ | ||
|
|
||
| exports.up = function(knex, Promise) { | ||
| return knex.schema.table('notes', table => { | ||
| table.integer('user_id').unsigned() | ||
| table.foreign('user_id').references('id').on('users') | ||
| }) | ||
| }; | ||
|
|
||
| exports.down = function(knex, Promise) { | ||
| return knex.schema.table('notes', table => { | ||
| table.dropColumn('user_id') | ||
| }) | ||
| }; |
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,8 @@ | ||
|
|
||
| exports.up = function(knex, Promise) { | ||
| return knex.schema.dropTableIfExists('notes') | ||
| }; | ||
|
|
||
| exports.down = function(knex, Promise) { | ||
| return null | ||
| }; |
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,20 @@ | ||
|
|
||
| exports.up = function(knex, Promise) { | ||
| return knex.schema.createTable('notes', table => { | ||
| table.increments() | ||
|
|
||
| table.string('title', 255).notNullable(); | ||
| table.string('content', 10000).notNullable(); | ||
| table.boolean('completed').notNullable() | ||
|
|
||
| table.timestamp('time_posted') | ||
| table.timestamp('time_updated') | ||
|
|
||
| table.integer('user_id').unsigned() | ||
| table.foreign('user_id').references('id').on('users') | ||
| }) | ||
| }; | ||
|
|
||
| exports.down = function(knex, Promise) { | ||
| return knex.schema.dropTableIfExists('notes') | ||
| }; |
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 @@ | ||
|
|
||
| exports.up = function(knex, Promise) { | ||
| return knex.schema.createTable('users', table => { | ||
| table.increments() | ||
|
|
||
| table.string('first_name').notNullable() | ||
| table.string('last_name').notNullable() | ||
| table.string('username').notNullable().unique() | ||
| table.string('password').notNullable() | ||
| }) | ||
| }; | ||
|
|
||
| exports.down = function(knex, Promise) { | ||
| return knex.schema.dropTableIfExists('users') | ||
| }; |
Binary file not shown.
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,13 @@ | ||
|
|
||
| exports.seed = function(knex, Promise) { | ||
| // Deletes ALL existing entries | ||
| return knex('notes').truncate() | ||
| .then(function () { | ||
| // Inserts seed entries | ||
| return knex('notes').insert([ | ||
| {id: 1, title: 'Test one', content: 'This is the first test'}, | ||
| {id: 2, title: 'Test Two', content: 'This is the second test'}, | ||
| {id: 3, title: 'Test Three', content: 'This is the third test'} | ||
| ]); | ||
| }); | ||
| }; |
Binary file not shown.
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,9 @@ | ||||||
| require('dotenv').config() | ||||||
|
|
||||||
| const server = require('./server/server'); | ||||||
|
|
||||||
| PORT = process.env.PORT || 4500 | ||||||
|
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. Missing a
Suggested change
|
||||||
|
|
||||||
| server.listen(PORT, () => { | ||||||
| console.log(`<<== server is running on port ${PORT} ==>>`) | ||||||
| }) | ||||||
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,32 @@ | ||
| // Update with your config settings. | ||
|
|
||
| module.exports = { | ||
|
|
||
| development: { | ||
| client: 'sqlite3', | ||
| connection: { | ||
| filename: './data/notes_dev.sqlite3' | ||
| }, | ||
| useNullAsDefault: true, | ||
| migrations: { | ||
| directory: "./data/migrations" | ||
| }, | ||
| seeds: { | ||
| directory: "./data/seeds" | ||
| }, | ||
| }, | ||
|
|
||
| testing: { | ||
| client: 'sqlite3', | ||
| connection: { | ||
| filename: './data/test.sqlite3' | ||
| }, | ||
| useNullAsDefault: true, | ||
| migrations: { | ||
| directory: './data/migrations', | ||
| }, | ||
| seeds: { | ||
| directory: './data/seeds' | ||
| }, | ||
| }, | ||
| }; |
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,29 @@ | ||
| const db = require('../data/dbConfig'); | ||
|
|
||
| const getAllNotes = (id) => { | ||
| return db('notes').where('user_id', id) | ||
| } | ||
|
|
||
| const getNoteByID = (id) => { | ||
| return db('notes').where('id', id) | ||
| } | ||
|
|
||
| const createNote = (note) => { | ||
| return db('notes').insert(note) | ||
| } | ||
|
|
||
| const updateNote = (id, change) => { | ||
| return db('notes').where('id', id).update(change) | ||
| } | ||
|
|
||
| const deleteNote = (id) => { | ||
| return db('notes').where('id', id).del() | ||
| } | ||
|
|
||
| module.exports = { | ||
| getAllNotes, | ||
| getNoteByID, | ||
| createNote, | ||
| updateNote, | ||
| deleteNote, | ||
| } |
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,28 @@ | ||
| { | ||
| "name": "back-end-project-week", | ||
| "version": "1.0.0", | ||
| "main": "index.js", | ||
| "scripts": { | ||
| "server": "nodemon", | ||
| "test": "cross-env DB_ENV=testing jest --watch --verbose" | ||
| }, | ||
| "repository": "https://github.com/CBMR/back-end-project-week.git", | ||
| "author": "Abdiel Fernandez <[email protected]>", | ||
| "license": "MIT", | ||
| "dependencies": { | ||
| "bcryptjs": "^2.4.3", | ||
| "cors": "^2.8.5", | ||
| "dotenv": "^6.2.0", | ||
| "express": "^4.16.4", | ||
| "jsonwebtoken": "^8.4.0", | ||
| "knex": "^0.16.3", | ||
| "moment": "^2.24.0", | ||
| "sqlite3": "^4.0.6" | ||
| }, | ||
| "devDependencies": { | ||
| "cross-env": "^5.2.0", | ||
| "jest": "^24.1.0", | ||
| "nodemon": "^1.18.10", | ||
| "supertest": "^3.4.2" | ||
| } | ||
| } |
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,90 @@ | ||
| const express = require('express'); | ||
| const jwt = require('jsonwebtoken') | ||
|
|
||
| const router = express.Router() | ||
|
|
||
| const notes = require('../../notes/notesModel') | ||
| const secret = process.env.SECRET ||'the-future-is-unknown' | ||
|
|
||
| function protected(req, res, next) { | ||
| const token = req.headers.authorization | ||
| if (token) { | ||
| jwt.verify(token, secret, (err, decodedToken) => { | ||
| if(err) { | ||
| res.status(401).json({errMessage: "invalid token"}) | ||
| } else { | ||
| next() | ||
| } | ||
| }) | ||
| } else { | ||
| res.status(401).json({errMessage: "no token attached"}) | ||
| } | ||
| } | ||
|
|
||
|
|
||
| router.get('/notes/:id', protected, async (req, res) => { | ||
| console.log(req.params) | ||
| const {id} = req.params | ||
| console.log(id) | ||
| try { | ||
| const allNotes = await notes.getAllNotes(id) | ||
| res.status(200).json(allNotes) | ||
| } catch (error) { | ||
| res.status(500).json({failure: 'unable to get all the notes'}) | ||
| } | ||
| }) | ||
|
|
||
| router.get('notes/:id/note/:id', protected, async (req, res) => { | ||
| const { id } = req.params; | ||
| try { | ||
| let note = await notes.getNoteByID(id) | ||
| note = note[0]; | ||
| res.status(200).json(note) | ||
| } catch (error) { | ||
| res.status(500).json({failure: 'unable to get the note'}) | ||
| } | ||
| }) | ||
|
|
||
| router.post('notes/:id/note/create', protected, async (req, res) => { | ||
| const {title, content} = req.body | ||
|
|
||
| if(title && content) { | ||
| try { | ||
| await notes.createNote(req.body) | ||
| res.status(201).json({success: "the note has been added"}) | ||
| } catch (error) { | ||
| res.status(500).json({failure: "unable to create the note"}) | ||
| } | ||
| } else { | ||
| res.status(422).json({failure: "please add the title or the content"}) | ||
| } | ||
| }) | ||
|
|
||
| router.put('notes/:id/note/:id/edit', protected, async (req, res) => { | ||
| const { id } = req.params | ||
| const { title, content } = req.body | ||
|
|
||
| if (title && content ) { | ||
| try { | ||
| await notes.updateNote(id, req.body) | ||
| res.status(201).json({success: "the note has been updated"}) | ||
| } catch (error) { | ||
| res.status(500).json({failure: 'unable to update the note'}) | ||
| } | ||
| } else { | ||
| res.status(422).json({failure: 'please make sure to add a title and content'}) | ||
| } | ||
| }) | ||
|
|
||
| router.delete('notes/:id/note/:id/delete', protected, async (req, res) => { | ||
| const { id } = req.params | ||
|
|
||
| try { | ||
| await notes.deleteNote(id) | ||
| res.status(200).json({success: "the note has been deleted"}) | ||
| } catch (error) { | ||
| res.status(500).json({failure: 'unable to delete the note'}) | ||
| } | ||
| }) | ||
|
|
||
| module.exports = router |
Oops, something went wrong.
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.
You could also do something like this