Skip to content

Commit aa6f710

Browse files
committed
Added furnimart backend made with nodeJS and mongoDB
1 parent be807f1 commit aa6f710

File tree

6 files changed

+743
-0
lines changed

6 files changed

+743
-0
lines changed

Diff for: DailyCode/furnimart-backend/Utils/helpers.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { User, Product } from "./models.js";
2+
3+
export const getAllUsers = async () => {
4+
let users = await User.find().exec();
5+
console.log(users);
6+
};
7+
8+
export const getUserByEmailAndPassword = async (email, password) => {
9+
let user = await User.findOne({ email: email, password: password }).exec();
10+
if (user) {
11+
return user;
12+
} else {
13+
return null;
14+
}
15+
};
16+
17+
export const getUserByEmail = async (email) => {
18+
let user = await User.findOne({ email: email }).exec();
19+
20+
if (user) {
21+
return user;
22+
} else {
23+
return null;
24+
}
25+
};
26+
27+
export const addUser = async (name, email, password) => {
28+
const user = new User({
29+
name: name,
30+
email: email,
31+
password: password,
32+
});
33+
return await user.save();
34+
};
35+
36+
export const checkIfUserExists = async (email) => {
37+
const user = await getUserByEmail(email);
38+
return user ? true : false;
39+
};
40+
41+
export const getProducts = async () => {
42+
return await Product.find().exec();
43+
};

Diff for: DailyCode/furnimart-backend/Utils/models.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import mongoose from "mongoose";
2+
3+
export const User = mongoose.model("users", {
4+
name: String,
5+
email: String,
6+
password: String,
7+
});
8+
9+
export const Product = mongoose.model("products", {
10+
productId: Number,
11+
productName: String,
12+
productPrice: Number,
13+
productImage: String,
14+
});

Diff for: DailyCode/furnimart-backend/data/products.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
export const products = [
2+
{
3+
productId: 1,
4+
productName: "Furniture 1",
5+
productPrice: 250,
6+
productImage: "/sample-image-1.jpg",
7+
},
8+
{
9+
productId: 2,
10+
productName: "Furniture 2",
11+
productPrice: 500,
12+
productImage: "/sample-image-2.jpg",
13+
},
14+
{
15+
productId: 3,
16+
productName: "Furniture 3",
17+
productPrice: 200,
18+
productImage: "/sample-image-3.jpg",
19+
},
20+
{
21+
productId: 4,
22+
productName: "Furniture 4",
23+
productPrice: 500,
24+
productImage: "/sample-image-4.jpg",
25+
},
26+
{
27+
productId: 5,
28+
productName: "Furniture 5",
29+
productPrice: 400,
30+
productImage: "/sample-image-5.jpg",
31+
},
32+
];

0 commit comments

Comments
 (0)