Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
07c4574
added dependencies, imports and js code
Jul 29, 2025
ee05b6a
added comment
Aug 3, 2025
21ba718
removed flowers data
Aug 6, 2025
8dbed54
added type and installed devdependencies
Aug 6, 2025
508cd8d
removed flowerdata import
Aug 6, 2025
1a6ea13
added mongoose import and connection to mongo db database
Aug 6, 2025
1f77e01
addded gotenv import and config
Aug 6, 2025
3a639bd
added seed database
Aug 6, 2025
f5f7fb3
changed json message
Aug 6, 2025
4a6899e
Added thought and user routes
Aug 6, 2025
f769b97
moved code to thoughtRoutes file
Aug 6, 2025
836630b
added user and thought models
Aug 6, 2025
5ca0e0f
Created thought model
Aug 6, 2025
14100f9
Created user model with access token
Aug 6, 2025
a3d98c5
Set up Express router
Aug 6, 2025
83f2a43
Add GET /thoughts endpoint with query filtering
Aug 6, 2025
b764be3
Add GET /thoughts/:id endpoint
Aug 6, 2025
c635810
fixed mispellings and removed unnecessary code
Aug 6, 2025
0e9b9f0
Add PATCH /thoughts/:id/like endpoint
Aug 6, 2025
3b08714
Added POST /thoughts endpoint with authentication
Aug 6, 2025
0cb7f84
Added PATCH /thoughts/:id endpoint with authentication
Aug 6, 2025
bed460a
Added DELETE /thoughts/:id endpoint with authentication and authoriza…
Aug 6, 2025
c9330ed
Set up Express router
Aug 6, 2025
4ca7048
Added POST /register endpoint with password hashing
Aug 6, 2025
9b7f6bb
Added POST /login endpoint with password verification
Aug 6, 2025
0fdcdd5
Added authentication middleware to verify accessToken
Aug 6, 2025
6ae4f52
Imported thought model
Aug 6, 2025
c9ae7d7
Added .js to imports
Aug 6, 2025
d7b7425
Fixed import path for thought model
Aug 6, 2025
b6ce6ab
Changed thought and user imports
Aug 6, 2025
75ccb2d
Changed imported routes
Aug 7, 2025
b86b25b
Moved devDependencies to dependencies
Aug 7, 2025
f26ade7
test relative path
Aug 7, 2025
37e6bbb
Changed start path
Aug 7, 2025
64ac6f0
Changed path
Aug 7, 2025
24dc313
Changed path
Aug 7, 2025
b2a2c4c
Changed thought import
Aug 7, 2025
8f48432
Use single quotations
Aug 7, 2025
d140a02
Test run
Aug 7, 2025
904f898
Rename Thought.js to thought.js
T-Thiry Aug 7, 2025
a56f463
Rename User.js to user.js
T-Thiry Aug 7, 2025
b8a4939
changed backend routes
Aug 10, 2025
34ed377
Changed more routes
Aug 10, 2025
27ad894
Changed URL
Aug 10, 2025
b4d4743
Replaced catch block
Aug 12, 2025
e381298
Added name to post
Aug 12, 2025
a2c4766
Removed space
Aug 12, 2025
cded4db
Removed req.user and moved user to req.body
Aug 12, 2025
f2296d5
Added brackets
Aug 12, 2025
5518431
removed user and extracted and extracted user from middleware
Aug 12, 2025
0049405
Added user to req.body and changed user.Id to user._id
Aug 12, 2025
ac4008c
Added user to req.body and changed user.Id to user._
Aug 12, 2025
4708a08
Added id to userschema
Aug 12, 2025
2d66c8c
Added id to thoughtschema
Aug 12, 2025
01aee36
Updated id definition
Aug 12, 2025
fff34ac
Added return on response
Aug 12, 2025
fc2d780
Pull user from req instead of req.body
Aug 12, 2025
9fb887e
Removed id from thougt schema and user schema
Aug 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ Install dependencies with `npm install`, then start the server by running `npm r
## View it live

Every project should be deployed somewhere. Be sure to include the link to the deployed project so that the viewer can click around and see what it's all about.

121 changes: 0 additions & 121 deletions data.json

This file was deleted.

26 changes: 26 additions & 0 deletions middleware/authenticateUser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { User } from '../models/user.js'


export const authenticateUser = async (req, res, next) => {
try {
const user = await User.findOne({ accessToken: req.header("Authorization") })

if (user) {
req.user = user
next()

} else {
res.status(401).json({
success: false,
message: "Authorization missing or invalid",
loggedOut: true
})
}

} catch (error) {
res.status(500).json({
message: "Internal server error",
error: error.message
})
}
}
26 changes: 26 additions & 0 deletions models/thought.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import mongoose from 'mongoose'

const thoughtSchema = new mongoose.Schema({
message: {
type: String,
required: true,
minlength: 5,
maxlength: 140
},
hearts: {
type: Number,
default: 0
},
user: {
type: mongoose.Schema.Types.ObjectId,
ref: "User",
required: true
},
Comment on lines +14 to +18

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great connection to the user collection here

createdAt: {
type: Date,
default: Date.now
},
});


export const Thought = mongoose.model("Thought", thoughtSchema)
26 changes: 26 additions & 0 deletions models/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import mongoose from 'mongoose'
import crypto from 'crypto'


const userSchema = new mongoose.Schema({
name: {
type: String,
required: true,
},
email: {
type: String,
required: true,
unique: true
},
password: {
type: String,
required: true,
},
accessToken: {
type: String,
default: () => crypto.randomBytes(128).toString('hex')
}
});


export const User = mongoose.model("User", userSchema);
16 changes: 12 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,26 @@
"name": "project-api",
"version": "1.0.0",
"description": "Project API",
"type": "module",
"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": "^6.0.0",
"cors": "^2.8.5",
"dotenv": "^16.5.0",
"express": "^4.17.3",
"nodemon": "^3.0.1"
"express-list-endpoints": "^7.1.1",
"jsonwebtoken": "^9.0.2",
"mongoose": "^8.17.0",
"@babel/core": "^7.28.0",
"@babel/node": "^7.28.0",
"@babel/preset-env": "^7.28.0"
},
"devDependencies": {
"nodemon": "^3.1.10"
}
}
Loading