Skip to content
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

Final Project: OMC Book Club - Ji, Maja, Viktoria #50

Open
wants to merge 198 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
198 commits
Select commit Hold shift + click to select a range
d277512
Co-authored-by: Maja Schouenke <[email protected]>
viktoria-olo May 28, 2024
df62453
refactor server.js
jyy009 May 28, 2024
58d0c96
Merge pull request #1 from viktoria-olo/break-server-file
jyy009 May 29, 2024
9de3687
added forms
viktoria-olo May 29, 2024
dc83569
Co-authored-by: jyy009 <[email protected]>
viktoria-olo May 29, 2024
65662da
Co-authored-by: jyy009 <[email protected]>
viktoria-olo May 29, 2024
638d52c
user backend added
viktoria-olo May 29, 2024
0486d0e
changed images
schouenkes May 30, 2024
67385ba
create landing page
jyy009 May 30, 2024
e86c52a
wishlist database added
viktoria-olo May 30, 2024
d74606d
pulled pictures to public
viktoria-olo May 30, 2024
64a59cd
added password validation
viktoria-olo May 30, 2024
0a56e6e
Merge branch 'main' into backend
viktoria-olo May 30, 2024
f921724
Merge pull request #2 from viktoria-olo/backend
viktoria-olo May 30, 2024
c3c9cad
Merge pull request #3 from viktoria-olo/landing-page
viktoria-olo May 30, 2024
b1c93b1
about us section added, styled mobile
viktoria-olo May 30, 2024
51149ae
carousel added
viktoria-olo May 31, 2024
2589167
changed arrows
viktoria-olo May 31, 2024
ebd84f8
create input form
jyy009 May 31, 2024
926f9fb
added contact part
viktoria-olo May 31, 2024
e91c884
fixed width
viktoria-olo May 31, 2024
25d01b4
styling
viktoria-olo May 31, 2024
85b3368
testing some hamburger menu
schouenkes Jun 2, 2024
77b9a36
Merge branch 'main' into header
schouenkes Jun 2, 2024
4988a6e
fixed a hamburger menu
schouenkes Jun 2, 2024
8b1c429
added some header responsiveness
schouenkes Jun 2, 2024
eb08c7b
wishlist card
jyy009 Jun 3, 2024
b171107
added isLoggedIn
viktoria-olo Jun 3, 2024
f675dec
Merge branch 'main' into wishlist-page
jyy009 Jun 3, 2024
a89be72
added dots to carousel
viktoria-olo Jun 3, 2024
5c8b070
Merge pull request #4 from viktoria-olo/about-us
viktoria-olo Jun 3, 2024
552371d
wishlist card
jyy009 Jun 3, 2024
b4e1338
Merge branch 'main' into wishlist-page
jyy009 Jun 3, 2024
ee620ac
start implementing hearts
jyy009 Jun 3, 2024
3be418e
Merge branch 'main' into header
schouenkes Jun 3, 2024
6e9abbb
added liked function
viktoria-olo Jun 4, 2024
541136b
Merge pull request #5 from viktoria-olo/backend
viktoria-olo Jun 4, 2024
60ec715
likes feature
jyy009 Jun 4, 2024
a44d8d4
Merge branch 'main' into wishlist-page
jyy009 Jun 4, 2024
2d087aa
added footer
viktoria-olo Jun 4, 2024
8e49ecd
Merge pull request #6 from viktoria-olo/footer
viktoria-olo Jun 4, 2024
6688bc2
Co-authored-by: Maja Schouenke <[email protected]>
viktoria-olo Jun 4, 2024
2f120e6
Merge pull request #7 from viktoria-olo/backend
viktoria-olo Jun 4, 2024
e1de759
changed some styling
viktoria-olo Jun 4, 2024
0151ffe
initial layout done
viktoria-olo Jun 4, 2024
b0dec84
started on sign out functionality
schouenkes Jun 4, 2024
7c6013d
Merge branch 'main' into header
schouenkes Jun 4, 2024
2032a64
work on handle like
jyy009 Jun 4, 2024
e455774
Merge branch 'main' into wishlist-page
jyy009 Jun 4, 2024
7ec2662
added InfoCard
viktoria-olo Jun 4, 2024
d8ae87b
created the sign in functionality
schouenkes Jun 4, 2024
3ba4d44
fixed a bug regarding the loading of landing page when a user isn't s…
schouenkes Jun 4, 2024
5f5051b
handle likes for wishlist
jyy009 Jun 5, 2024
c3319e6
sign out functionality
schouenkes Jun 5, 2024
fbc94b7
made wishlist only accessable when logged in
schouenkes Jun 5, 2024
711d494
Merge pull request #8 from viktoria-olo/header
schouenkes Jun 5, 2024
c90ee41
add anonymous input to wishlist
jyy009 Jun 5, 2024
f86c67a
styling
viktoria-olo Jun 5, 2024
569c884
Merge pull request #9 from viktoria-olo/bookclub
viktoria-olo Jun 5, 2024
4f2a336
start adding username to wishlist
jyy009 Jun 5, 2024
9f402a0
anonymous and username
jyy009 Jun 6, 2024
6250cbe
add picture
jyy009 Jun 6, 2024
dcb625c
Merge branch 'main' into wishlist-page
jyy009 Jun 6, 2024
d455a2d
Merge pull request #10 from viktoria-olo/wishlist-page
jyy009 Jun 6, 2024
c93d5a3
small fixes
jyy009 Jun 6, 2024
f89c6d2
solved header issue
viktoria-olo Jun 6, 2024
e1b72a1
not found page
viktoria-olo Jun 6, 2024
65cedc4
Merge pull request #11 from viktoria-olo/not-found
viktoria-olo Jun 6, 2024
2130735
added loading animation
viktoria-olo Jun 6, 2024
a0019f6
submission type debugging
jyy009 Jun 6, 2024
036fec1
Merge pull request #12 from viktoria-olo/loading
viktoria-olo Jun 7, 2024
ec5abeb
Merge remote-tracking branch 'origin' into wishlist
jyy009 Jun 7, 2024
dccf407
changed user type
viktoria-olo Jun 7, 2024
81eb1bd
create username and anonymous submission
jyy009 Jun 7, 2024
ed7c417
Merge branch 'main' into wishlist
jyy009 Jun 7, 2024
23dee5d
Merge pull request #13 from viktoria-olo/wishlist
jyy009 Jun 7, 2024
d57e5d0
fix width for founder card
jyy009 Jun 7, 2024
0055ac5
address registration update
viktoria-olo Jun 7, 2024
adb2a71
added different text for logged in user
viktoria-olo Jun 7, 2024
c2037bc
Merge pull request #14 from viktoria-olo/bookclub
viktoria-olo Jun 7, 2024
def1d9e
created a reverse card due to Tailwind acting up
viktoria-olo Jun 7, 2024
b3f445d
Merge pull request #15 from viktoria-olo/bookclub
viktoria-olo Jun 7, 2024
797942f
potential other solution to Tailwind added
viktoria-olo Jun 7, 2024
c51a24e
fixed row direction
viktoria-olo Jun 8, 2024
8d24030
Merge pull request #16 from viktoria-olo/bookclub
viktoria-olo Jun 8, 2024
0eaec8e
pagination
viktoria-olo Jun 8, 2024
d967022
style landing page
jyy009 Jun 8, 2024
7b14c37
style wishlist page
jyy009 Jun 8, 2024
ef83bc8
style wishlistForm, add loading animation
jyy009 Jun 9, 2024
7036c1f
added sorting by likes
viktoria-olo Jun 9, 2024
964b939
style wishlistCard
jyy009 Jun 9, 2024
a89ec2d
Merge pull request #17 from viktoria-olo/stylewish
jyy009 Jun 9, 2024
980f0c5
added wishlist nav component
viktoria-olo Jun 9, 2024
82674fe
styling picture
viktoria-olo Jun 9, 2024
7a0e427
fsdf
viktoria-olo Jun 9, 2024
b406e18
trying out userId
viktoria-olo Jun 9, 2024
34593a8
Merge branch 'profile-page' into profile
viktoria-olo Jun 9, 2024
e965f63
Merge pull request #18 from viktoria-olo/profile
viktoria-olo Jun 9, 2024
677364c
fixed typo
viktoria-olo Jun 9, 2024
d595874
fixed signed out bug
schouenkes Jun 9, 2024
5c9f7ac
hid the sign in form when the loading animation shows
schouenkes Jun 9, 2024
cacc7aa
basic profile page added
viktoria-olo Jun 9, 2024
5d198a3
added error handling for sign in and sign up
schouenkes Jun 9, 2024
07229b2
added error messages in frontend to sign up and sing in
schouenkes Jun 9, 2024
e03b969
changes error messages when the backend is down
schouenkes Jun 9, 2024
f952e3d
added env for backend_url
schouenkes Jun 9, 2024
120838f
added patch to backend
viktoria-olo Jun 9, 2024
3861b52
styling header
schouenkes Jun 9, 2024
1ffdde4
styled sign in
schouenkes Jun 9, 2024
33e88a5
fixed a small styling on sign in
schouenkes Jun 9, 2024
a13e73c
styled sign up
schouenkes Jun 10, 2024
05350c3
sign up button styling
schouenkes Jun 10, 2024
da8ba43
Merge pull request #19 from viktoria-olo/headerLogic
schouenkes Jun 10, 2024
3808f46
changed url
viktoria-olo Jun 10, 2024
5d3a2d0
Merge branch 'main' into backend
viktoria-olo Jun 10, 2024
81a05ff
Merge pull request #20 from viktoria-olo/backend
viktoria-olo Jun 10, 2024
c8f50ed
fixed a bug
schouenkes Jun 10, 2024
7550e62
fixed a bug in wishlist
schouenkes Jun 10, 2024
218aec3
fixing bugs
viktoria-olo Jun 10, 2024
f24018b
Co-authored-by: jyy009 <[email protected]>
viktoria-olo Jun 10, 2024
7c6ed21
Merge branch 'main' into profile-page
viktoria-olo Jun 10, 2024
138d5dd
Merge pull request #21 from viktoria-olo/profile-page
viktoria-olo Jun 10, 2024
9d55239
Co-authored-by: jyy009 <[email protected]>
viktoria-olo Jun 10, 2024
4e3e9ac
reverted to earlier useUserStore
viktoria-olo Jun 10, 2024
62fc6ae
fixed race condition in /users on the backend and fixed fetchProfile
schouenkes Jun 10, 2024
4bbe0d3
Merge pull request #22 from viktoria-olo/testing
schouenkes Jun 10, 2024
124b530
updating info added to frontend
viktoria-olo Jun 10, 2024
9b38d7e
style wishlist
jyy009 Jun 10, 2024
f1f6c2b
continue styling
jyy009 Jun 11, 2024
4cec3ad
finish most styling
jyy009 Jun 11, 2024
636b14e
Merge pull request #23 from viktoria-olo/stylingwishlist
jyy009 Jun 11, 2024
f328f2f
create delete route
jyy009 Jun 11, 2024
5476203
updating address works
viktoria-olo Jun 11, 2024
489426e
small update
viktoria-olo Jun 11, 2024
fd4d645
small update
viktoria-olo Jun 11, 2024
212203f
Merge pull request #24 from viktoria-olo/my-profile
viktoria-olo Jun 11, 2024
6a580e7
handle delete
jyy009 Jun 11, 2024
f50a299
Merge branch 'main' into deleteuser
jyy009 Jun 11, 2024
97cb694
able to delete user
jyy009 Jun 11, 2024
45f0522
add delete functionality
jyy009 Jun 12, 2024
78249d3
Merge pull request #25 from viktoria-olo/deleteuser
jyy009 Jun 12, 2024
9e0f9c6
fixed sticky header
schouenkes Jun 12, 2024
2d76d78
merge main
schouenkes Jun 12, 2024
e2e5fb1
style profile page
jyy009 Jun 12, 2024
b68af52
Merge pull request #26 from viktoria-olo/style-profile
jyy009 Jun 12, 2024
67b6638
fixed some padding and margin
schouenkes Jun 12, 2024
119da03
Merge branch 'main' into checking
schouenkes Jun 12, 2024
8f92635
changed place of sign up button at register
schouenkes Jun 12, 2024
2932323
Merge pull request #27 from viktoria-olo/checking
schouenkes Jun 12, 2024
fb44a41
fix styling and loading
jyy009 Jun 12, 2024
9a5efea
save user likes
viktoria-olo Jun 12, 2024
43d908c
Merge pull request #28 from viktoria-olo/like-btn
viktoria-olo Jun 12, 2024
ad8dfa0
small fix
viktoria-olo Jun 12, 2024
711a48c
style profile responsive
jyy009 Jun 12, 2024
a27ea53
On mobile the navbar will close when the logo is clicked
schouenkes Jun 13, 2024
f8a4e4c
fixed signed out problem
schouenkes Jun 13, 2024
5a07748
moved text input styling to textinput.jsx
schouenkes Jun 13, 2024
b0f069a
started to move the styling for every button to the button component
schouenkes Jun 13, 2024
808999d
style profile page
jyy009 Jun 13, 2024
344dca2
style about us
jyy009 Jun 13, 2024
8259fcd
continued to move the button styling to button component
schouenkes Jun 13, 2024
cf1c6c3
changed the landing page text when signed in
schouenkes Jun 13, 2024
413db5e
changed the apperance of the contact image
schouenkes Jun 13, 2024
b665c74
style profile page
jyy009 Jun 13, 2024
e5220aa
Merge pull request #29 from viktoria-olo/style-profile
jyy009 Jun 13, 2024
3975966
merged
schouenkes Jun 13, 2024
92cad65
Merge pull request #30 from viktoria-olo/mobilemenu
schouenkes Jun 13, 2024
9734c8f
styling profile page
schouenkes Jun 13, 2024
ef245ff
using text component in sign up
schouenkes Jun 13, 2024
19900d9
update like icon for wishlist
jyy009 Jun 13, 2024
42fdec7
Merge pull request #31 from viktoria-olo/wishlist-icon
jyy009 Jun 13, 2024
e354a31
updated book info
viktoria-olo Jun 13, 2024
38a86a3
Merge pull request #32 from viktoria-olo/bookclub
viktoria-olo Jun 13, 2024
8409803
style margins
jyy009 Jun 13, 2024
e4b6def
Merge pull request #33 from viktoria-olo/style-landing
jyy009 Jun 13, 2024
2e12304
added dislike backend
viktoria-olo Jun 15, 2024
ffeba18
finish styling
jyy009 Jun 17, 2024
3770365
Merge branch 'main' into style-landing-2
jyy009 Jun 17, 2024
c656a73
Merge pull request #34 from viktoria-olo/style-landing-2
jyy009 Jun 17, 2024
3a04c7e
add button hover bg
jyy009 Jun 17, 2024
68eb03d
Merge pull request #35 from viktoria-olo/style-register
jyy009 Jun 17, 2024
fe28cf1
create readme info
jyy009 Jun 17, 2024
6ea57ac
Merge pull request #36 from viktoria-olo/readme
jyy009 Jun 17, 2024
d9406d6
move readme to correct file
jyy009 Jun 17, 2024
e458061
Merge pull request #37 from viktoria-olo/readme-2
jyy009 Jun 17, 2024
084fe40
add loading animation to profile and sign up page
jyy009 Jun 17, 2024
5b08166
Merge pull request #38 from viktoria-olo/loading-profile
jyy009 Jun 17, 2024
b4eba17
Merge branch 'main' into like-btn
viktoria-olo Jun 17, 2024
67f2da1
solved toggle like
viktoria-olo Jun 17, 2024
70be3db
resolved toggle likes
viktoria-olo Jun 17, 2024
6159431
debug navbar popup
jyy009 Jun 18, 2024
d56cc12
cleaned up code
viktoria-olo Jun 18, 2024
aa6705a
small fix
viktoria-olo Jun 18, 2024
3345476
Merge pull request #40 from viktoria-olo/like-btn
viktoria-olo Jun 18, 2024
241750d
Merge pull request #41 from viktoria-olo/navbar-issue
jyy009 Jun 18, 2024
069fce4
Co-authored-by: Maja Schouenke <[email protected]>
viktoria-olo Jun 18, 2024
4216b28
small fix
viktoria-olo Jun 18, 2024
7d986eb
added netlify link to readme
viktoria-olo Jun 18, 2024
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
47 changes: 41 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,48 @@
# Final Project
# One More Chapter Bookclub

Replace this readme with your own information about your project.
## Project Introduction

Start by briefly describing the assignment in a sentence or two. Keep it short and to the point.
Our application, built with React + Vite, Node.js and MongoDB database, delivers a bookclub where people can sign up to become a subscribed member, receive a monthly book, and post books that they would like to read to a interactive feed.

## The problem
## Table of Contents

Describe how you approached to problem, and what tools and techniques you used to solve it. How did you plan? What technologies did you use? If you had more time, what would be next?
- [Technologies](#technologies)
- [How to use the application](#how-to-use-the-application)
- [View it live](#view-it-live)
- [Contact Us](#contact-us)

## Technologies

### Frontend

Our app provides:

- Tailwind CSS for styling
- Zustand for state management
- Navigation using React Router
- Intuitive and accessibility approved interface
- Responsive design (320-1600px) across different browsers

### Backend

Our backend handles:

- One database with two synced collections using MongoDB
- Two RESTful API models using Express.js to handle the bookclub users and to post a book to the feed

## How to use the app

You can use our app as a bookclub member or non-member. As a non-member, you can read about the bookclub founders, the bookclub details, and register to become a member at the "Sign up" page.

Once you become a member, you will have access to the "Wishlist" page where you can submit book suggestions to a feed, like/unlike other posts, and sort the posts. You can also go to your "Profile" page and update your contact information as well as delete your subscription.

## 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.
[Frontend](https://main--omc-book-club.netlify.app/)
[Backend](https://project-final-rvhj.onrender.com)

## Contact Us

- Ji Yoo- [LinkedIn](https://www.linkedin.com/in/jyy/), [Github](https://github.com/jyy009)
- Maja Schouenke- [LinkedIn](https://www.linkedin.com/in/maja-schouenke-0a09842a7/), [Github](https://github.com/schouenkes)
- Viktoria Olofsson- [LinkedIn](https://www.linkedin.com/in/viktoria-olofsson-%E7%BE%85%E8%96%87-81462bb6/), [Github](https://github.com/viktoria-olo)
8 changes: 0 additions & 8 deletions backend/README.md

This file was deleted.

19 changes: 19 additions & 0 deletions backend/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import cors from "cors";
import express from "express";
import expressListEndpoints from "express-list-endpoints";
import usersRoutes from "./routes/users.js";
import wishlistRoutes from "./routes/wishlist.js";

const app = express();

app.use(cors());
app.use(express.json());
app.use("/", usersRoutes);
app.use("/", wishlistRoutes);

app.get("/", (req, res) => {
const endpoints = expressListEndpoints(app);
res.json(endpoints);
});

export default app;
25 changes: 25 additions & 0 deletions backend/authMiddleware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import User from "./models/User";

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: "Unauthorized, user not found" });
}
} catch (error) {
res.status(400).json({
success: false,
message: "Bad request, user not found",
response: error,
});
}
};

export default authenticateUser;
7 changes: 7 additions & 0 deletions backend/config/databases.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import mongoose from "mongoose";

const mongoUrl = process.env.MONGO_URL || "mongodb://localhost/OMC";
mongoose.connect(mongoUrl);
mongoose.Promise = Promise;

export default mongoose;
39 changes: 39 additions & 0 deletions backend/models/BookWish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import mongoose from "../config/databases.js";

const { Schema, model } = mongoose;

// Schema
const bookWishSchema = new Schema({
title: {
type: String,
required: true,
},
author: {
type: String,
required: false,
},
message: {
type: String,
required: true,
minlength: 5,
maxlength: 140,
},
likes: {
type: Number,
default: 0,
},
createdAt: {
type: Date,
default: () => new Date(),
},
user: {
type: String,
required: true,
},
likedBy: [{ type: mongoose.Schema.Types.ObjectId, ref: "User" }],
});

// Model
const BookWish = model("BookWish", bookWishSchema);

export default BookWish;
39 changes: 39 additions & 0 deletions backend/models/User.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import bcrypt from "bcrypt";
import mongoose from "../config/databases.js";

const { Schema, model } = mongoose;

// Schema
const userSchema = new Schema({
name: {
type: String,
required: true,
},
username: {
type: String,
unique: true,
required: true,
},
email: {
type: String,
unique: true,
required: true,
},
password: {
type: String,
required: true,
},
address: {
type: String,
required: true,
},
accessToken: {
type: String,
default: () => bcrypt.genSaltSync(),
},
});

// Model
const User = model("User", userSchema);

export default User;
9 changes: 6 additions & 3 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
"@babel/core": "^7.17.9",
"@babel/node": "^7.16.8",
"@babel/preset-env": "^7.16.11",
"bcrypt": "^5.1.1",
"cors": "^2.8.5",
"express": "^4.17.3",
"express": "^4.19.2",
"express-list-endpoints": "^7.1.0",
"mongodb": "^6.6.2",
"mongoose": "^8.4.0",
"nodemon": "^3.0.1"
"nodemon": "^3.1.3"
}
}
}
165 changes: 165 additions & 0 deletions backend/routes/users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
import express, { response } from "express";
import bcrypt from "bcrypt";
import User from "../models/User";
import authenticateUser from "../authMiddleware";
const mongoose = require("mongoose");

const router = express.Router();

router.get("/users", async (req, res) => {
const allUsers = await User.find().exec();
if (allUsers.length > 0) {
res.json(allUsers);
} else {
res.status(404).send("No users found");
}
});

router.post("/users", async (req, res) => {
try {
const { name, username, email, password, address } = req.body;
if (!password || password.length < 8) {
return res.status(400).json({
success: false,
errorType: "password",
message: "Password must be at least 8 characters long",
});
}
const salt = bcrypt.genSaltSync();
const user = new User({
name,
username,
email,
password: bcrypt.hashSync(password, salt),
address,
});
await user.save();
res.status(201).json({
success: true,
userId: user._id,
accessToken: user.accessToken,
message: "User created",
});
} catch (error) {
// Check if the error is due to a duplicate key (e.g., username or email)
if (error.code === 11000) {
return res.status(400).json({
success: false,
errorType: "duplication",
message: Object.keys(error.keyValue)[0],
});
}
// For other types of errors, just send the error message
return res.status(500).json({
success: false,
errorType: "general",
message: error.message,
});
}
});

router.get("/users/membership", authenticateUser, (req, res) => {
res.json({ isLoggedIn: true, userId: req.user._id });
});

router.post("/users/sessions", async (req, res) => {
const user = await User.findOne({ username: req.body.username });
if (user) {
if (bcrypt.compareSync(req.body.password, user.password)) {
res.json({ userId: user._id, accessToken: user.accessToken });
} else {
return res.status(400).json({
success: false,
errorType: "login",
message: "Login failed. Incorrect username or password",
});
}
} else {
return res.status(400).json({
success: false,
errorType: "login",
message: "Login failed. Incorrect username or password",
});
}
});

router.get("/users/:userId", async (req, res) => {
const { userId } = req.params;
try {
const user = await User.findById(userId);
if (user) {
res.json(user);
} else {
res.status(404).send("Could not find user");
}
} catch (error) {
res.status(400).json({
success: false,
response: error,
message: "Bad request, user not found",
});
}
});

router.patch("/users/:userId/update", async (req, res) => {
const { userId } = req.params;
const { address } = req.body;
try {
const user = await User.findById(userId);
if (!user) {
return res.status(404).json({
success: false,
message: "User not found",
});
}
const updateAddress = await User.findByIdAndUpdate(
userId,
{ address },
{ new: true }
);
res.json({ success: true, address: updateAddress.address });
} catch (error) {
res.status(400).json({
success: false,
response: error,
message: "Could not update email",
});
}
});

router.delete("/users/delete/:userId", async (req, res) => {
const { userId } = req.params;

if (!mongoose.Types.ObjectId.isValid(userId)) {
return res.status(400).json({
success: false,
message: "Invalid user ID",
});
}
try {
console.log(req.params);

const deletedUser = await User.findByIdAndDelete({ _id: userId });
console.log(deletedUser);
if (!deletedUser) {
return res.status(400).json({
success: false,
message: "could not find user",
});
} else {
res.status(200).json({
success: true,
message: `User with ID ${userId} has been deleted`,
});
}
} catch (error) {
console.error("Error deleting user:", error);
res.status(500).json({
success: false,
response: error,
message: "Could not delete username",
});
}
});

export default router;
Loading