Skip to content

Commit

Permalink
userdetails are completed today
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhil-dev-395 committed Jun 9, 2024
1 parent eb64478 commit 3598ed8
Show file tree
Hide file tree
Showing 10 changed files with 252 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"cSpell.words": ["Cloudinary"]
}
15 changes: 9 additions & 6 deletions client/src/components/user/userDetails.jsx/UserDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,18 @@ const UserDetails = () => {
{ label: "Phone Number", placeholder: "Phone Number", name: "phone", type: "tel" },
{ label: "Email", placeholder: "Email", name: "email", type: "email" },
{ label: "Address", placeholder: "Address", name: "address", type: "textarea" },
{ label: "Height", placeholder: "Height", name: "height", type: "text" },
{ label: "Height", placeholder: "Height in cm eg. 170cm", name: "height", type: "text" },
{ label: "Weight", placeholder: "Weight (e.g., 70kg)", name: "weight", type: "text" },
{ label: "Complexion", placeholder: "Complexion", name: "complexion", type: "text" },
{ label: "Education", placeholder: "Education", name: "education", type: "text" },
{ label: "Education", placeholder: "Education", name: "education", type: "text" },
{ label: "Religion", placeholder: "Religion", name: "religion", type: "text" },
{ label: "Occupation", placeholder: "Occupation", name: "occupation", type: "text" },
{ label: "Annual Income", placeholder: "Annual Income", name: "income", type: "text" },
{ label: "Preferred Age Range", placeholder: "Preferred Age Range", name: "preferredAge", type: "text" },
{ label: "Preferred Height Range", placeholder: "in feet", name: "preferredHeight", type: "text" },
{ label: "Preferred Education", placeholder: "Preferred Education", name: "preferredEducation", type: "text" },
{ label: "Preferred Age Range", placeholder: "Preferred Age Range", name: "preferredAge", type: "select", options: ["18-25", "26-35", "36-45", "46+"], },
{ label: "Preferred Height Range", placeholder: "Preferred Height Range", name: "preferredHeight", type: "select", options: ["Short", "Average", "Tall"], },
{ label: "Preferred Education", placeholder: "Preferred Education", name: "preferredEducation", type: "select", options: ["High School", "Bachelor's Degree", "Master's Degree", "PhD"], },
{ label: "Preferred Religion", placeholder: "Preferred Religion", name: "preferredReligion", type: "select", options: ["Islam", "Christianity", "Hinduism", "Buddhism", "Judaism", "Other"], },
{ label: "Preferred Complexion", placeholder: "Preferred Complexion", name: "preferredComplexion", type: "select", options: ["Fair", "Medium", "Dark"], },

{ label: "Preferred Profession", placeholder: "Preferred Profession", name: "preferredProfession", type: "text" },
];

Expand Down
23 changes: 15 additions & 8 deletions server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@ import express from "express";
import cors from "cors";
import session from "express-session";
import passport from "passport";
import fileUpload from "express-fileupload";
import errorHandler from "./src/middleware/errorHandling.middleware.js";
import { AuthRouter } from "./src/routes/auth.routes.js";
import { AuthRouter } from "./src/routes/auth.routes.js";
import { userDetailsRouter } from "./src/routes/user.routes.js";
import "./src/utils/auth.utils.js"; // Initialize Passport.js

const app = express();

/* MIDDLEWARE */
app.use(cors())
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(
fileUpload({
useTempFiles: true,
tempFileDir: "/tmp/",
})
);

// Configure express-session middleware
app.use(
Expand All @@ -26,12 +34,11 @@ app.use(
app.use(passport.initialize());
app.use(passport.session());

/* ERROR HANDLER */
app.use(errorHandler);


/* ROUTES */
app.use("/auth", AuthRouter); //we added here google auth
app.use("/auth", AuthRouter);
app.use("/user", userDetailsRouter);

/* ERROR HANDLER */
app.use(errorHandler);

export default app;
31 changes: 31 additions & 0 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.19.2",
"express-fileupload": "^1.5.0",
"express-session": "^1.18.0",
"jsonwebtoken": "^9.0.2",
"mongoose": "^8.4.0",
Expand Down
4 changes: 1 addition & 3 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import { connectDB } from "./src/db/connectDB.js";
app.get("/home", (req, res) => {
res.send("hello world");
});




const startServer = async () => {
try {
await connectDB();
Expand Down
89 changes: 89 additions & 0 deletions server/src/controllers/userDetails.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import UserDetails from "../models/userDetails.models.js";
import { v2 as cloudinary } from "cloudinary";

cloudinary.config({
cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
api_key: process.env.CLOUDINARY_API_KEY,
api_secret: process.env.CLOUDINARY_API_SECRET,
});

const createUserDetails = async (req, res, next) => {
const {
firstName,
fathersName,
surname,
mothersName,
age,
gender,
address,
dob,
phoneNumber,
email,
education,
religion,
martialStatus,
occupation,
annualIncome,
preferredAgeRange,
preferredHeightRange,
preferredEducation,
preferredComplexion,
preferredProfession,
preferredLocation,
} = req.body;

try {
let profileUrl = "";

// Check if a file is uploaded
if (req.files && req.files.profileImage) {
const file = req.files.profileImage;

// Upload file to Cloudinary
const uploadResult = await cloudinary.uploader.upload(file.tempFilePath, {
public_id: `user_profiles/${file.name}`,
});

profileUrl = uploadResult.secure_url;
}

// Ensure profileUrl is not empty
if (!profileUrl) {
throw new Error("Profile image upload failed or not provided");
}

// Create new user details
const newUserDetails = new UserDetails({
yourProfileUrl: profileUrl,
firstName,
fathersName,
surname,
mothersName,
age,
gender,
address,
dob,
phoneNumber,
email,
education,
religion,
martialStatus,
occupation,
annualIncome,
preferredAgeRange,
preferredHeightRange,
preferredEducation,
preferredComplexion,
preferredProfession,
preferredLocation,
});

await newUserDetails.save();

res.status(201).json(newUserDetails);
} catch (error) {
next(error);
}
};

export { createUserDetails };
4 changes: 2 additions & 2 deletions server/src/middleware/auth.middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export const authenticateGoogle = passport.authenticate("google", {
});

export const googleCallback = passport.authenticate("google", {
failureRedirect: "/",
successRedirect: "/dashboard", // Adjust the redirect URL as needed
failureRedirect: "/login",
successRedirect: "/home", //adjust based on success
});
92 changes: 92 additions & 0 deletions server/src/models/userDetails.models.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import mongoose from "mongoose";

const userDetailsSchema = new mongoose.Schema(
{
yourProfileUrl: {
type: String,
required: true,
},
firstName: {
type: String,
required: true,
},
fathersName: {
type: String,
required: true,
},
surname: String,
mothersName: String,
age: {
type: Number,
min: 18,
max: 120,
},
gender: {
type: String,
enum: ["Male", "Female", "Other"],
},
dob: {
type: Date,
required: true,
},
phoneNumber: {
type: String,
match: /^\d{10}$/,
required: true,
},
email: {
type: String,
required: true,
unique: true,
lowercase: true,
match: /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/,
},
address: String,
height: String,
weight: String,
education: {
type: String,
enum: [
"High School",
"Bachelor's Degree",
"Master's Degree",
"PhD",
"Other",
],
},
religion: String,
martialStatus: {
type: String,
enum: ["unmarried", "divorced"],
},
occupation: String,
annualIncome: String,
preferredAgeRange: {
type: String,
enum: ["18-25", "26-35", "36-45", "46+"],
},
preferredHeightRange: String,
preferredEducation: {
type: String,
enum: [
"High School",
"Bachelor's Degree",
"Master's Degree",
"PhD",
"Other",
],
},
preferredReligion: String,
preferredComplexion: {
type: String,
enum: ["Fair", "Medium", "Dark"],
},
preferredProfession: String,
preferredLocation: String,
},
{ timestamps: true }
);

const UserDetails = mongoose.model("UserDetails", userDetailsSchema);

export default UserDetails;
9 changes: 9 additions & 0 deletions server/src/routes/user.routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import express from "express";
import { createUserDetails } from "../controllers/userDetails.controller.js";

const router = express.Router();

// Define your routes here
router.post("/createUserDetails", createUserDetails);

export const userDetailsRouter = router;

0 comments on commit 3598ed8

Please sign in to comment.