Skip to content

Commit

Permalink
feat: added user schema
Browse files Browse the repository at this point in the history
  • Loading branch information
shaikahmadnawaz committed Aug 8, 2023
1 parent c3fb6cb commit 3fe13ad
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 7 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ One of the unique features of VVIT LearnSpace is the project showcase section. T
To get started with the development of VVIT LearnSpace, follow these steps:

1. Clone this repository to your local machine.
2. Set up the backend server by navigating to the `backend` directory and running `npm install`.
3. Set up the frontend client by navigating to the `frontend` directory and running `npm install`.
4. Set up the database by following the instructions in the `database` directory.
5. Create a `.env` file in the `backend` directory with necessary environment variables (e.g., database connection details, AWS credentials).
6. Start the development server for both the backend and frontend.
2. Set up the backend server by navigating to the `server` directory and running `npm install`.
3. Set up the frontend client by navigating to the `client` directory and running `npm install`.
4. Create a `.env` file in the `server` directory with necessary environment variables (e.g., database connection details, AWS credentials).
5. Start the development server for both the backend and frontend.
2 changes: 2 additions & 0 deletions server/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PORT=5000
MONGO_URI=mongodb+srv://techxcel:[email protected]/?retryWrites=true&w=majority
6 changes: 6 additions & 0 deletions server/db/connectDB.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import mongoose from "mongoose";

export const connectDB = async (uri) => {
await mongoose.connect(uri);
console.log("connected to MongoDB!");
};
40 changes: 40 additions & 0 deletions server/models/User.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import mongoose from "mongoose";
import validator from "validator";

const userSchema = new mongoose.Schema({
name: {
type: String,
required: [true, "Please enter your name"],
},
email: {
type: String,
unique: true,
required: [true, "Please enter your email"],
validate: {
validator: validator.isEmail,
message: "Please enter a valid email",
},
},
password: {
type: String,
required: [true, "Please enter your password"],
},
role: {
type: String,
enum: ["admin", "student", "faculty"],
required: true,
},
profilePicture: {
type: String,
validate: {
validator: validator.isURL,
message: "Invalid URL",
},
},
createdAt: {
type: Date,
default: Date.now,
},
});

export default mongoose.model("User", userSchema);
11 changes: 10 additions & 1 deletion server/package-lock.json

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

3 changes: 2 additions & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"express-async-handler": "^1.2.0",
"http-status-codes": "^2.2.0",
"jsonwebtoken": "^9.0.1",
"mongoose": "^7.4.1"
"mongoose": "^7.4.1",
"validator": "^13.11.0"
},
"devDependencies": {
"nodemon": "^3.0.1"
Expand Down
23 changes: 23 additions & 0 deletions server/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import express from "express";
import cors from "cors";
import dotenv from "dotenv";
import { connectDB } from "./db/connectDB.js";

dotenv.config();
const app = express();
const port = process.env.PORT || 5000;
app.use(cors());
app.use(express.json());

const start = async () => {
try {
await connectDB(process.env.MONGO_URI);
app.listen(port, () => {
console.log(`Server is listening on port ${port}`);
});
} catch (error) {
console.log(error);
}
};

start();

0 comments on commit 3fe13ad

Please sign in to comment.