generated from Technigo/express-api-starter
-
Notifications
You must be signed in to change notification settings - Fork 31
API Project - Jonny HIcks #10
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
KidFromCalifornia
wants to merge
24
commits into
Technigo:master
Choose a base branch
from
KidFromCalifornia: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
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
879db5f
Update package.json with project details and structure
KidFromCalifornia dcbf71b
.get added and workiing with data.json
KidFromCalifornia 87e3876
Add new endpoints for filtering, searching, pagination, and posting t…
KidFromCalifornia a772d40
Refactor server to use mongoose for database operations and update th…
KidFromCalifornia bc18d2a
d add like functionality to increment hearts
KidFromCalifornia 7f552ec
Refactor server routes to return thoughts and improve error handling;…
KidFromCalifornia 1608043
Add @babel/cli dependency to package.json
KidFromCalifornia 725bcec
Fix start script in package.json to use npx for babel-node
KidFromCalifornia 07afc42
Fix start script in package.json to remove npx for babel-node
KidFromCalifornia 74a52af
Remove unused dependencies and clean up package.json scripts
KidFromCalifornia 63c74e4
Remove empty devDependencies section from package.json
KidFromCalifornia 9088efa
Implement user authentication and enhance thoughts management features
KidFromCalifornia 3b58a19
Add user authentication and thoughts management routes, models, and m…
KidFromCalifornia cfe0327
Refactor thoughts and users routes for improved structure and clarity
KidFromCalifornia c60b78c
Refactor authentication middleware and update thoughts route for cons…
KidFromCalifornia 140ad0f
Add user reference to Thought model and enforce ownership in delete r…
KidFromCalifornia c3d3204
Refactor post and delete routes in thoughts.js for improved organizat…
KidFromCalifornia 98c5af0
Fix typo in user reference when creating a new thought
KidFromCalifornia 1432255
Fix typo in user property assignment in post route
KidFromCalifornia 85cb5d3
Fix typo in user property assignment in post route
KidFromCalifornia 9431c53
Fix user property assignment in post route
KidFromCalifornia 31110d1
fixed route for delete and patch
KidFromCalifornia c8ae688
Return success status with updated thought in patch route response
KidFromCalifornia b632444
Add express-list-endpoints dependency and update root endpoint response
KidFromCalifornia 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,25 @@ | ||
| import User from "../models/User.js"; | ||
|
|
||
| const authenticationUser = async (req, res, next) => { | ||
| try { | ||
| const authHeader = req.headers && req.headers.authorization; | ||
| const accessToken = | ||
| authHeader && authHeader.startsWith("Bearer ") | ||
| ? authHeader.split(" ")[1] | ||
| : null; | ||
| if (!accessToken) { | ||
| return res.status(401).json({ error: "Access token required" }); | ||
| } | ||
| const user = await User.findOne({ accessToken }); | ||
| if (user) { | ||
| req.user = user; | ||
| return next(); | ||
| } else { | ||
| return res.status(401).json({ loggedout: true, error: "Unauthorized" }); | ||
| } | ||
| } catch (error) { | ||
| return res.status(500).json({ error: "Internal server error" }); | ||
| } | ||
| }; | ||
|
|
||
| export default authenticationUser; |
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 @@ | ||
| import mongoose from "mongoose"; | ||
|
|
||
| const thoughtSchema = new mongoose.Schema({ | ||
| message: { | ||
| type: String, | ||
| trim: true, | ||
| required: true, | ||
| minlength: 5, | ||
| maxlength: 140, | ||
| }, | ||
| hearts: { | ||
| type: Number, | ||
| default: 0, | ||
| }, | ||
| createdAt: { | ||
| type: Date, | ||
| default: Date.now, | ||
| }, | ||
| username: { | ||
| type: String, | ||
| required: true, | ||
| trim: true, | ||
| }, | ||
| }); | ||
|
|
||
| const Thought = mongoose.model("Thought", thoughtSchema); | ||
|
|
||
| export default Thought; |
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 @@ | ||
| import mongoose from "mongoose"; | ||
| import crypto from "crypto"; | ||
|
|
||
| const userSchema = new mongoose.Schema({ | ||
| username: { | ||
| type: String, | ||
| required: true, | ||
| unique: true, | ||
| index: true, // Add index for optimization | ||
| }, | ||
| email: { | ||
| type: String, | ||
| required: true, | ||
| unique: true, | ||
| index: true, // Add index for optimization | ||
| }, | ||
| password: { | ||
| type: String, | ||
| required: true, | ||
| }, | ||
| accessToken: { | ||
| type: String, | ||
| default: () => crypto.randomBytes(37).toString("hex"), | ||
| }, | ||
| }); | ||
|
|
||
| const User = mongoose.models.User || mongoose.model("User", userSchema); | ||
|
|
||
| export default User; | ||
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,19 +1,35 @@ | ||
| { | ||
| "name": "project-api", | ||
| "name": "js-project-api", | ||
| "version": "1.0.0", | ||
| "description": "Project API", | ||
| "description": " JS Project API", | ||
| "homepage": "https://github.com/KidFromCalifornia/js-project-api#readme", | ||
| "bugs": { | ||
| "url": "https://github.com/KidFromCalifornia/js-project-api/issues" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/KidFromCalifornia/js-project-api.git" | ||
| }, | ||
| "license": "ISC", | ||
| "author": "", | ||
| "type": "commonjs", | ||
| "main": "server.js", | ||
| "scripts": { | ||
| "start": "babel-node server.js", | ||
| "dev": "nodemon server.js --exec babel-node" | ||
| }, | ||
| "author": "", | ||
| "license": "ISC", | ||
| "dependencies": { | ||
| "@babel/core": "^7.17.9", | ||
| "@babel/node": "^7.16.8", | ||
| "@babel/preset-env": "^7.16.11", | ||
| "bcrypt-nodejs": "^0.0.3", | ||
| "bcryptjs": "^3.0.2", | ||
| "cors": "^2.8.5", | ||
| "express": "^4.17.3", | ||
| "nodemon": "^3.0.1" | ||
| "dotenv": "^16.5.0", | ||
| "express": "^4.21.2", | ||
| "express-list-endpoints": "^7.1.1", | ||
| "mongoose": "^8.15.1", | ||
| "nodemon": "^3.0.1", | ||
| "validator": "^13.15.15" | ||
| } | ||
| } |
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.
⭐