la-flowerita 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +70 -0
- package/package.json +78 -0
- package/public/favicon.ico +0 -0
- package/public/images/1.jpg +0 -0
- package/public/images/2.jpg +0 -0
- package/public/images/3.jpg +0 -0
- package/public/images/Logo.png +0 -0
- package/public/images/add-user.png +0 -0
- package/public/images/contact-us.png +0 -0
- package/public/images/flower.png +0 -0
- package/public/images/flower_shop.png +0 -0
- package/public/images/flower_shop1.png +0 -0
- package/public/images/flowers/buttercup.png +0 -0
- package/public/images/flowers/daffodil.png +0 -0
- package/public/images/flowers/daisy.png +0 -0
- package/public/images/flowers/jasmine.png +0 -0
- package/public/images/flowers/lily.png +0 -0
- package/public/images/flowers/marigold.png +0 -0
- package/public/images/flowers/orchid.png +0 -0
- package/public/images/flowers/rose.png +0 -0
- package/public/images/flowers/sunflower.png +0 -0
- package/public/images/flowers/tulip.png +0 -0
- package/public/images/garbage.png +0 -0
- package/public/images/icon1.jpg +0 -0
- package/public/images/login.png +0 -0
- package/public/images/refresh.png +0 -0
- package/public/images/transaction.png +0 -0
- package/public/index.html +41 -0
- package/public/logo192.png +0 -0
- package/public/logo512.png +0 -0
- package/public/manifest.json +26 -0
- package/public/offline.html +44 -0
- package/public/robots.txt +3 -0
- package/public/serviceworker.js +44 -0
- package/server.js +97 -0
- package/src/App.css +38 -0
- package/src/App.js +25 -0
- package/src/App.test.js +8 -0
- package/src/Config/db.js +5 -0
- package/src/Config/mail.js +7 -0
- package/src/Config/passport.js +34 -0
- package/src/Controllers/catalog.controller.js +78 -0
- package/src/Controllers/shoppinglist.controller.js +186 -0
- package/src/Controllers/user.controller.js +214 -0
- package/src/Controllers/wishlist.controller.js +150 -0
- package/src/Middleware/sendMail.js +29 -0
- package/src/Middleware/uploadImage.js +26 -0
- package/src/Models/orderProducts.js +10 -0
- package/src/Models/products.js +17 -0
- package/src/Models/shoppinglists.js +12 -0
- package/src/Models/userShoppinglists.js +9 -0
- package/src/Models/users.js +57 -0
- package/src/Models/wishlists.js +9 -0
- package/src/Routes/auth.js +21 -0
- package/src/Routes/indexRouter.js +40 -0
- package/src/Services/ProductService.js +76 -0
- package/src/Services/ShoppinglistService.js +135 -0
- package/src/Services/UserService.js +63 -0
- package/src/Services/WishlistService.js +105 -0
- package/src/components/About.js +45 -0
- package/src/components/Auth.js +15 -0
- package/src/components/Catalog.js +118 -0
- package/src/components/Chat.js +77 -0
- package/src/components/Contact.js +48 -0
- package/src/components/Dashboard.js +13 -0
- package/src/components/DetailsProductModal.js +362 -0
- package/src/components/LoginModal.js +173 -0
- package/src/components/NewProductModal.js +271 -0
- package/src/components/NoPermission.js +10 -0
- package/src/components/OrderedProduct.js +104 -0
- package/src/components/PreChat.js +51 -0
- package/src/components/Product.js +158 -0
- package/src/components/ResetPassword.js +211 -0
- package/src/components/ShoppingCart.js +198 -0
- package/src/components/SideNav.js +76 -0
- package/src/components/SignupModal.js +306 -0
- package/src/components/Spinner.js +22 -0
- package/src/components/Wishlist.js +195 -0
- package/src/components/social-config.js +17 -0
- package/src/css/about.css +12 -0
- package/src/css/catalog.css +218 -0
- package/src/css/chat.css +191 -0
- package/src/css/contact.css +404 -0
- package/src/css/index.css +129 -0
- package/src/css/newProductModal.css +69 -0
- package/src/css/noPermission.css +89 -0
- package/src/css/orderedProduct.css +0 -0
- package/src/css/resetPassword.css +44 -0
- package/src/css/shoppingCart.css +10 -0
- package/src/css/sideNav.css +68 -0
- package/src/css/spinner.css +23 -0
- package/src/images/1.jpg +0 -0
- package/src/images/2.jpg +0 -0
- package/src/images/3.jpg +0 -0
- package/src/images/Logo.png +0 -0
- package/src/images/add-user.png +0 -0
- package/src/images/buttercup.png +0 -0
- package/src/images/contact-us.png +0 -0
- package/src/images/daffodil.png +0 -0
- package/src/images/daisy.png +0 -0
- package/src/images/flower.png +0 -0
- package/src/images/flower_shop.png +0 -0
- package/src/images/flower_shop1.png +0 -0
- package/src/images/flowers/buttercup.png +0 -0
- package/src/images/flowers/daffodil.png +0 -0
- package/src/images/flowers/daisy.png +0 -0
- package/src/images/flowers/jasmine.png +0 -0
- package/src/images/flowers/lily.png +0 -0
- package/src/images/flowers/marigold.png +0 -0
- package/src/images/flowers/orchid.png +0 -0
- package/src/images/flowers/rose.png +0 -0
- package/src/images/flowers/sunflower.png +0 -0
- package/src/images/flowers/tulip.png +0 -0
- package/src/images/garbage.png +0 -0
- package/src/images/icon1.jpg +0 -0
- package/src/images/jasmine.png +0 -0
- package/src/images/lily.png +0 -0
- package/src/images/login.png +0 -0
- package/src/images/marigold.png +0 -0
- package/src/images/orchid.png +0 -0
- package/src/images/refresh.png +0 -0
- package/src/images/rose.png +0 -0
- package/src/images/sunflower.png +0 -0
- package/src/images/transaction.png +0 -0
- package/src/images/tulip.png +0 -0
- package/src/index.js +371 -0
- package/src/logo.svg +1 -0
- package/src/reportWebVitals.js +13 -0
- package/src/setupTests.js +5 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
const mongo = require("mongoose");
|
2
|
+
const { Schema } = mongo;
|
3
|
+
|
4
|
+
const ProductSchema = new Schema({
|
5
|
+
id: Number,
|
6
|
+
sellerId: String,
|
7
|
+
name: String,
|
8
|
+
color: String,
|
9
|
+
price: Number,
|
10
|
+
type: String,
|
11
|
+
isActivate: Boolean,
|
12
|
+
description: String,
|
13
|
+
image : {data: Buffer, contentType: String},
|
14
|
+
maxAmount: Number
|
15
|
+
}, { autoIndex: true });
|
16
|
+
|
17
|
+
mongo.model('Products', ProductSchema, 'Products'); // if model name as lowercase with suffix "s" === collection name: User => users
|
@@ -0,0 +1,12 @@
|
|
1
|
+
const { Double } = require("mongodb");
|
2
|
+
const mongo = require("mongoose");
|
3
|
+
const { Schema } = mongo;
|
4
|
+
|
5
|
+
const ShoppinglistSchema = new Schema({
|
6
|
+
userId: String,
|
7
|
+
products: Array,
|
8
|
+
isPaid: Boolean,
|
9
|
+
date: Date
|
10
|
+
}, { autoIndex: false });
|
11
|
+
|
12
|
+
mongo.model('Shoppinglists', ShoppinglistSchema, 'Shoppinglists'); // if model name as lowercase with suffix "s" === collection name: User => users
|
@@ -0,0 +1,9 @@
|
|
1
|
+
const mongo = require("mongoose");
|
2
|
+
const { Schema } = mongo;
|
3
|
+
|
4
|
+
const UserShoppinglistsSchema = new Schema({
|
5
|
+
userId: String,
|
6
|
+
shoppinglists: Array,
|
7
|
+
}, { autoIndex: false });
|
8
|
+
|
9
|
+
mongo.model('UserShoppinglists', UserShoppinglistsSchema, 'UserShoppinglists');
|
@@ -0,0 +1,57 @@
|
|
1
|
+
const mongo = require("mongoose");
|
2
|
+
const { Schema } = mongo;
|
3
|
+
const crypto = require('crypto');
|
4
|
+
const jwt = require('jsonwebtoken');
|
5
|
+
|
6
|
+
const UserSchema = new Schema({
|
7
|
+
id: Number,
|
8
|
+
name: String,
|
9
|
+
phone: String,
|
10
|
+
degree: String,
|
11
|
+
address: String,
|
12
|
+
isActivate: Boolean,
|
13
|
+
email: String,
|
14
|
+
hash: String,
|
15
|
+
salt: String,
|
16
|
+
profileImage: {data: Buffer, contentType: String},
|
17
|
+
isApproved: Boolean,
|
18
|
+
resetPasswordToken: String,
|
19
|
+
}, { autoIndex: true });
|
20
|
+
|
21
|
+
UserSchema.methods.getResetPasswordToken = function(){
|
22
|
+
// const resetToken = crypto.randomBytes(20).toString('hex');
|
23
|
+
const resetToken = Math.floor(Math.random() * 10000).toString();
|
24
|
+
console.log(resetToken);
|
25
|
+
// Hash token and set to resetPassordToken field
|
26
|
+
this.resetPasswordToken = crypto.createHash('sha512').update(resetToken).digest('hex');
|
27
|
+
return resetToken;
|
28
|
+
}
|
29
|
+
// Generates hash and salt for user's password
|
30
|
+
UserSchema.methods.setPassword = function(password) {
|
31
|
+
this.salt = crypto.randomBytes(16).toString('hex');
|
32
|
+
this.hash = crypto.pbkdf2Sync(password, this.salt, 10000, 512, 'sha512').toString('hex');
|
33
|
+
};
|
34
|
+
|
35
|
+
// Validate user's password
|
36
|
+
UserSchema.methods.validatePassword = function(password) {
|
37
|
+
console.log(password);
|
38
|
+
const hash = crypto.pbkdf2Sync(password, this.salt, 10000, 512, 'sha512').toString('hex');
|
39
|
+
return this.hash === hash;
|
40
|
+
};
|
41
|
+
|
42
|
+
// Generates token
|
43
|
+
UserSchema.methods.generateJWT = function() {
|
44
|
+
const today = new Date();
|
45
|
+
const expirationDate = new Date(today);
|
46
|
+
expirationDate.setDate(today.getDate() + 60);
|
47
|
+
|
48
|
+
return jwt.sign({
|
49
|
+
email: this.email,
|
50
|
+
id: this._id,
|
51
|
+
algorithms:['sha1', 'RS256', 'HS256'],
|
52
|
+
digest:'hex',
|
53
|
+
exp: parseInt(expirationDate.getTime() / 1000, 10),
|
54
|
+
}, 'secret');
|
55
|
+
}
|
56
|
+
// db.model('User', UserSchema, 'User'); // (model, UserSchema, collection)
|
57
|
+
mongo.model('Users', UserSchema,'Users'); // if model name as lowercase with suffix "s" === collection name: User => users
|
@@ -0,0 +1,9 @@
|
|
1
|
+
const mongo = require("mongoose");
|
2
|
+
const { Schema } = mongo;
|
3
|
+
|
4
|
+
const WishlistSchema = new Schema({
|
5
|
+
userId: String,
|
6
|
+
products: Array,
|
7
|
+
}, { autoIndex: false });
|
8
|
+
|
9
|
+
mongo.model('Wishlists', WishlistSchema, 'Wishlists'); // if model name as lowercase with suffix "s" === collection name: User => users
|
@@ -0,0 +1,21 @@
|
|
1
|
+
const jwt = require('express-jwt');
|
2
|
+
|
3
|
+
|
4
|
+
const checkAuthenticated = (req, res, next) => {
|
5
|
+
console.log("checkAuthenticated");
|
6
|
+
if (req.isAuthenticated()) { return next() }
|
7
|
+
res.redirect("/login")
|
8
|
+
}
|
9
|
+
|
10
|
+
const checkLoggedIn = (req, res, next) => {
|
11
|
+
console.log("checkLoggedIn");
|
12
|
+
if (req.isAuthenticated()) {
|
13
|
+
return res.redirect("/Dashboard")
|
14
|
+
}
|
15
|
+
next()
|
16
|
+
}
|
17
|
+
|
18
|
+
module.exports = {
|
19
|
+
checkAuthenticated: checkAuthenticated,
|
20
|
+
checkLoggedIn:checkLoggedIn
|
21
|
+
};
|
@@ -0,0 +1,40 @@
|
|
1
|
+
const express = require("express");
|
2
|
+
const router = express.Router();
|
3
|
+
const UserCtrl = require("../Controllers/user.controller");
|
4
|
+
const CatalogCtrl = require("../Controllers/catalog.controller");
|
5
|
+
const ShoppinglistCtrl = require("../Controllers/shoppinglist.controller");
|
6
|
+
const WishlistCtrl = require("../Controllers/wishlist.controller");
|
7
|
+
|
8
|
+
var bodyParser = require("body-parser");
|
9
|
+
var jsonParser = bodyParser.json();
|
10
|
+
const auth = require('./auth');
|
11
|
+
|
12
|
+
router.post("/auth", jsonParser, UserCtrl.auth);
|
13
|
+
router.get("/getCurrentUser", jsonParser, UserCtrl.getCurrentUser);
|
14
|
+
router.get("/logout", jsonParser, UserCtrl.logout);
|
15
|
+
router.post("/emailForResetPassword", jsonParser, UserCtrl.emailForResetPassword);
|
16
|
+
router.post("/checkToken", jsonParser, UserCtrl.checkToken);
|
17
|
+
router.post("/updatePassword", jsonParser, UserCtrl.updatePassword);
|
18
|
+
router.post("/signup", jsonParser, UserCtrl.signup);
|
19
|
+
router.get("/getProfileImage", jsonParser, UserCtrl.getProfileImage);
|
20
|
+
router.post("/addUserProfile", jsonParser, UserCtrl.addUserProfile);
|
21
|
+
router.post("/getCatalog", jsonParser, CatalogCtrl.getCatalog);
|
22
|
+
router.post("/addNewProduct", jsonParser, CatalogCtrl.addNewProduct);
|
23
|
+
router.post("/addProductPicture", jsonParser, CatalogCtrl.addProductPicture);
|
24
|
+
router.post("/updateProduct", jsonParser, CatalogCtrl.updateProduct);
|
25
|
+
router.post("/deleteProduct", jsonParser, CatalogCtrl.deleteProduct);
|
26
|
+
// router.post("addProductToCart", jsonParser, ShoppinglistCtrl.addProduct);
|
27
|
+
router.get("/getCurrentCart", jsonParser, ShoppinglistCtrl.getCurrentCart);
|
28
|
+
router.get("/getCurrentWishlist", jsonParser, WishlistCtrl.getCurrentWishlist);
|
29
|
+
router.get("/isLogged", jsonParser, UserCtrl.isLogged);
|
30
|
+
router.post("/addNewProductToCart", jsonParser, ShoppinglistCtrl.addNewProductToCart);
|
31
|
+
router.post("/updateProductInCart", jsonParser, ShoppinglistCtrl.updateProductInCart);
|
32
|
+
router.post("/deleteProductFromCart", jsonParser, ShoppinglistCtrl.deleteProductFromCart);
|
33
|
+
router.post("/addNewProductToWishlist", jsonParser, WishlistCtrl.addNewProductToWishlist);
|
34
|
+
router.post("/updateProductInWishlist", jsonParser, WishlistCtrl.updateProductInWishlist);
|
35
|
+
router.post("/deleteProductFromWishlist", jsonParser, WishlistCtrl.deleteProductFromWishlist);
|
36
|
+
router.get("/getSession", jsonParser, UserCtrl.getSession);
|
37
|
+
router.get("/payNow",jsonParser, ShoppinglistCtrl.payNow)
|
38
|
+
|
39
|
+
|
40
|
+
module.exports = router;
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require("../Models/products");
|
2
|
+
var mongoose = require("mongoose");
|
3
|
+
const Product = mongoose.model('Products');
|
4
|
+
|
5
|
+
module.exports = class ProductService {
|
6
|
+
|
7
|
+
static async GetALL() {
|
8
|
+
return Product.find({ isActivate: true }).exec();
|
9
|
+
}
|
10
|
+
static async GetCatalogByType(type) {
|
11
|
+
return Product.find({ isActivate: true, type:type }).exec();
|
12
|
+
}
|
13
|
+
|
14
|
+
static async CREATE(product) {
|
15
|
+
return Product.create({
|
16
|
+
name: product.name,
|
17
|
+
description: product.description,
|
18
|
+
price: product.price,
|
19
|
+
type: product.type,
|
20
|
+
isActivate: true,
|
21
|
+
color: product.color,
|
22
|
+
image: product.image,
|
23
|
+
maxAmount: product.maxAmount,
|
24
|
+
sellerId: product.sellerId
|
25
|
+
});
|
26
|
+
}
|
27
|
+
|
28
|
+
static async LastId() {
|
29
|
+
return Product.find().sort({ _id: -1 }).limit(1);
|
30
|
+
}
|
31
|
+
|
32
|
+
static async FIND(id) {
|
33
|
+
return Product.find({ _id: id });
|
34
|
+
}
|
35
|
+
|
36
|
+
static async UPDATE(id, product) {
|
37
|
+
return Product.updateOne(
|
38
|
+
{ _id: id },
|
39
|
+
{
|
40
|
+
$set: {
|
41
|
+
name: product.name,
|
42
|
+
description: product.description,
|
43
|
+
color: product.color,
|
44
|
+
price: product.price,
|
45
|
+
type: product.type,
|
46
|
+
maxAmount: product.maxAmount,
|
47
|
+
// sellerId: product.sellerId
|
48
|
+
// image: product.image,
|
49
|
+
// isActivate: product.isActivate
|
50
|
+
},
|
51
|
+
}
|
52
|
+
).exec();
|
53
|
+
}
|
54
|
+
|
55
|
+
static async UpdatePicture(id, product) {
|
56
|
+
return Product.updateOne(
|
57
|
+
{ _id: id },
|
58
|
+
{
|
59
|
+
$set: {
|
60
|
+
image: product.image,
|
61
|
+
},
|
62
|
+
}
|
63
|
+
).exec();
|
64
|
+
}
|
65
|
+
|
66
|
+
static async DELETE(id) {
|
67
|
+
return Product.updateOne(
|
68
|
+
{ _id: id },
|
69
|
+
{
|
70
|
+
$set: {
|
71
|
+
isActivate: false,
|
72
|
+
},
|
73
|
+
}
|
74
|
+
).exec();
|
75
|
+
}
|
76
|
+
};
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require("../Models/shoppinglists");
|
2
|
+
var mongoose = require("mongoose");
|
3
|
+
const Shoppinglist = mongoose.model('Shoppinglists');
|
4
|
+
const Products = mongoose.model('Products');
|
5
|
+
const OrderProducts = mongoose.model('OrderProducts');
|
6
|
+
module.exports = class ProductService {
|
7
|
+
|
8
|
+
static async GetCurrentCart(userId) {
|
9
|
+
var cart = await Shoppinglist.findOne({userId: userId, isPaid: false});
|
10
|
+
// console.log(cart);
|
11
|
+
if(!cart){
|
12
|
+
console.log("new cart")
|
13
|
+
cart = new Shoppinglist({userId:userId, isPaid:false, products:[]})
|
14
|
+
await cart.save();
|
15
|
+
}
|
16
|
+
return cart;
|
17
|
+
}
|
18
|
+
|
19
|
+
static async GetProductsDetails(products) {
|
20
|
+
var result = [];
|
21
|
+
console.log(products);
|
22
|
+
for (let i = 0; i < products.length; i++) {
|
23
|
+
console.log(products[i]);
|
24
|
+
result.push(await this.GetProductDetails(products[i]));
|
25
|
+
}
|
26
|
+
return result;
|
27
|
+
}
|
28
|
+
|
29
|
+
static async GetProductDetails(orderProductId) {
|
30
|
+
console.log("inside order product")
|
31
|
+
console.log(orderProductId);
|
32
|
+
var orderProduct = await OrderProducts.findById(orderProductId)
|
33
|
+
console.log("got order product")
|
34
|
+
var product = await Products.findById(orderProduct.productId)
|
35
|
+
console.log("got product")
|
36
|
+
var result = {id: product._id, name:product.name, price: product.price, quantity: orderProduct.quantity, image: product.image}
|
37
|
+
return result;
|
38
|
+
}
|
39
|
+
|
40
|
+
static async AddProduct(id, product) {
|
41
|
+
var cart = await this.GetCurrentCart(id)
|
42
|
+
var orderProducts = await OrderProducts.find({ _id: { "$in": cart.products }});
|
43
|
+
var orderProduct = orderProducts.find(p => p.productId == product._id);
|
44
|
+
console.log("exisits " + orderProduct);
|
45
|
+
if(orderProduct){
|
46
|
+
console.log("update quantity")
|
47
|
+
await OrderProducts.updateOne(
|
48
|
+
{ _id:orderProduct._id },
|
49
|
+
{ $set: { quantity: orderProduct.quantity + 1 } }
|
50
|
+
);
|
51
|
+
return;
|
52
|
+
}
|
53
|
+
console.log("create orderProduct")
|
54
|
+
// create orderProduct
|
55
|
+
product = {productId: product._id, quantity: 1, priceForEach: product.price};
|
56
|
+
var orderProduct = new OrderProducts(product);
|
57
|
+
await orderProduct.save();
|
58
|
+
console.log(orderProduct)
|
59
|
+
console.log("new order product " + orderProduct);
|
60
|
+
cart.products.push(orderProduct._id);
|
61
|
+
await Shoppinglist.updateOne(
|
62
|
+
{ _id: cart._id},
|
63
|
+
{ $set: { products: cart.products } }
|
64
|
+
);
|
65
|
+
}
|
66
|
+
static async AddProductsFromSession(userId, products){
|
67
|
+
for(let i = 0; i < products.length; i++){
|
68
|
+
await this.AddProductFromSession(userId, products[i])
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
static async AddProductFromSession(id, product) {
|
73
|
+
var cart = await this.GetCurrentCart(id)
|
74
|
+
var orderProducts = await OrderProducts.find({ _id: { "$in": cart.products }});
|
75
|
+
var orderProduct = orderProducts.find(p => p.productId == product.id);
|
76
|
+
console.log("exisits " + orderProduct);
|
77
|
+
if(orderProduct){
|
78
|
+
console.log("update quantity")
|
79
|
+
await OrderProducts.updateOne(
|
80
|
+
{ productId:product.id },
|
81
|
+
{ $set: { quantity: orderProduct.quantity + product.quantity } }
|
82
|
+
);
|
83
|
+
return;
|
84
|
+
}
|
85
|
+
console.log("create orderProduct")
|
86
|
+
// create orderProduct
|
87
|
+
product = {productId: product.id, quantity: product.quantity, priceForEach: product.price};
|
88
|
+
console.log(product);
|
89
|
+
var orderProduct = new OrderProducts(product);
|
90
|
+
await orderProduct.save();
|
91
|
+
console.log(orderProduct)
|
92
|
+
console.log("new order product " + orderProduct);
|
93
|
+
cart.products.push(orderProduct._id);
|
94
|
+
Shoppinglist.updateOne(
|
95
|
+
{ _id: cart._id},
|
96
|
+
{ $set: { products: cart.products } }
|
97
|
+
).exec();
|
98
|
+
}
|
99
|
+
|
100
|
+
static async UpdateProduct(id, product) {
|
101
|
+
product = {productId: product.productId, quantity: product.quantity, priceForEach: product.price};
|
102
|
+
console.log("updating order product")
|
103
|
+
var cart = await this.GetCurrentCart(id)
|
104
|
+
var orderProducts = await OrderProducts.find({ _id: { "$in": cart.products }});
|
105
|
+
var orderProduct = orderProducts.find(p => p.productId == product.productId);
|
106
|
+
// cart.products.map(p => {if(p.productId == product.productId) p = product })
|
107
|
+
await OrderProducts.updateOne(
|
108
|
+
{ _id: orderProduct._id},
|
109
|
+
{ $set: { quantity: product.quantity, price: product.price } }
|
110
|
+
);
|
111
|
+
}
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
static async DeleteProduct(id, productId) {
|
116
|
+
var cart = await this.GetCurrentCart(id);
|
117
|
+
var orderProduct = await OrderProducts.findOne({ productId: productId });
|
118
|
+
const index = cart.products.indexOf(orderProduct._id);
|
119
|
+
console.log(index);
|
120
|
+
cart.products.splice(index, 1);
|
121
|
+
console.log("after delete" + cart.products)
|
122
|
+
await Shoppinglist.updateOne(
|
123
|
+
{ _id: cart._id},
|
124
|
+
{ $set: { products: cart.products } }
|
125
|
+
);
|
126
|
+
await OrderProducts.deleteOne({productId: productId})
|
127
|
+
}
|
128
|
+
|
129
|
+
static async CartPaid(userId){
|
130
|
+
await Shoppinglist.updateOne(
|
131
|
+
{ userId: userId, isPaid: false},
|
132
|
+
{ $set: { isPaid: true, date: Date.now() } }
|
133
|
+
);
|
134
|
+
}
|
135
|
+
};
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require("../Models/users");
|
2
|
+
var mongoose = require("mongoose");
|
3
|
+
const User = mongoose.model('Users');
|
4
|
+
|
5
|
+
module.exports = class UserService {
|
6
|
+
static async CREATE(user) {
|
7
|
+
return User.create({
|
8
|
+
name: user.name,
|
9
|
+
phone: user.phone,
|
10
|
+
degree: user.degree,
|
11
|
+
address: user.address,
|
12
|
+
isActivate: true,
|
13
|
+
email: user.email,
|
14
|
+
password: user.password,
|
15
|
+
image: user.image,
|
16
|
+
isApproved: user.degree !="Customer" ? false: true
|
17
|
+
});
|
18
|
+
}
|
19
|
+
|
20
|
+
static async GetALL() {
|
21
|
+
return User.find({ isApproved:true, isActivate: true }).exec();
|
22
|
+
}
|
23
|
+
static async GetClients() {
|
24
|
+
return User.find({ isActivate: true, degree: "client" }).exec();
|
25
|
+
}
|
26
|
+
static async FindById(id) {
|
27
|
+
console.log("finding user:" + id);
|
28
|
+
return User.findOne({ _id: id });
|
29
|
+
}
|
30
|
+
static async FindByEmail(e) {
|
31
|
+
console.log("finding user by email:" + e);
|
32
|
+
return User.findOne({ email: e , isApproved: true, isActivate:true});
|
33
|
+
}
|
34
|
+
static async FIND(e, p) {
|
35
|
+
console.log("finding user:" + e + "" + p);
|
36
|
+
return await User.findOne({ email: e, password: p, isApproved: true, isActivate:true});
|
37
|
+
}
|
38
|
+
|
39
|
+
static async REMOVE(e, p) {
|
40
|
+
return User.updateOne(
|
41
|
+
{ email: e, password: p },
|
42
|
+
{ $set: { isActivate: false } }
|
43
|
+
).exec();
|
44
|
+
}
|
45
|
+
|
46
|
+
static async UPDATE(e, user) {
|
47
|
+
return User.updateOne(
|
48
|
+
{ email: e },
|
49
|
+
{ $set: { email: user.email, hash: user.hash, salt:user.salt, degree: user.degree, profileImage: user.profileImage } }
|
50
|
+
).exec();
|
51
|
+
}
|
52
|
+
|
53
|
+
static async UpdateById(id, user) {
|
54
|
+
return User.updateOne(
|
55
|
+
{ _id: id },
|
56
|
+
{ $set: { email: user.email, hash: user.hash, salt:user.salt, degree: user.degree, profileImage: user.profileImage } }
|
57
|
+
).exec();
|
58
|
+
}
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
};
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require("../Models/wishlists");
|
2
|
+
var ShoppinglistService = require("../Services/ShoppinglistService");
|
3
|
+
var mongoose = require("mongoose");
|
4
|
+
const Shoppinglist = mongoose.model('Shoppinglists');
|
5
|
+
const Wishlist = mongoose.model('Wishlists');
|
6
|
+
const Products = mongoose.model('Products');
|
7
|
+
const OrderProducts = mongoose.model('OrderProducts');
|
8
|
+
module.exports = class ProductService {
|
9
|
+
|
10
|
+
static async GetCurrentWishlist(userId) {
|
11
|
+
var wl = await Wishlist.findOne({userId: userId});
|
12
|
+
if(!wl){
|
13
|
+
console.log("new wl")
|
14
|
+
wl = new Wishlist({userId:userId, products:[]})
|
15
|
+
await wl.save();
|
16
|
+
}
|
17
|
+
return wl;
|
18
|
+
}
|
19
|
+
|
20
|
+
static async GetProductsDetails(products) {
|
21
|
+
var result = [];
|
22
|
+
console.log(products);
|
23
|
+
for (let i = 0; i < products.length; i++) {
|
24
|
+
console.log(products[i]);
|
25
|
+
result.push(await this.GetProductDetails(products[i]));
|
26
|
+
}
|
27
|
+
return result;
|
28
|
+
}
|
29
|
+
|
30
|
+
static async GetProductDetails(productId) {
|
31
|
+
var product = await Products.findById(productId)
|
32
|
+
console.log("got product")
|
33
|
+
var result = {id: product._id, name:product.name, price: product.price, image: product.image}
|
34
|
+
return result;
|
35
|
+
}
|
36
|
+
|
37
|
+
static async AddProduct(userId, productId) {
|
38
|
+
var wl = await this.GetCurrentWishlist(userId)
|
39
|
+
console.log("add product to wish list")
|
40
|
+
// create orderProduct
|
41
|
+
var products = new Set(wl.products)
|
42
|
+
products.add(productId);
|
43
|
+
wl.products = Array.from(products);
|
44
|
+
await Wishlist.updateOne(
|
45
|
+
{ _id: wl._id},
|
46
|
+
{ $set: { products: wl.products } }
|
47
|
+
);
|
48
|
+
}
|
49
|
+
|
50
|
+
// static async AddProductToCart(userId, productId) {
|
51
|
+
// var wl = await this.GetCurrentWishlist(userId)
|
52
|
+
// for (let i = 0; i < wl.products.length; i++) {
|
53
|
+
// var product = await Products.findById(wl.products[i])
|
54
|
+
// await ShoppinglistService.AddProduct(userId, product)
|
55
|
+
// }
|
56
|
+
// }
|
57
|
+
|
58
|
+
// static async UpdateProduct(product) {
|
59
|
+
// product = {productId: product.productId, quantity: product.quantity, priceForEach: product.price};
|
60
|
+
// console.log("updating order product")
|
61
|
+
// console.log(product.productId)
|
62
|
+
// // cart.products.map(p => {if(p.productId == product.productId) p = product })
|
63
|
+
// await OrderProducts.updateOne(
|
64
|
+
// { productId: product.productId},
|
65
|
+
// { $set: { quantity: product.quantity, price: product.price } }
|
66
|
+
// );
|
67
|
+
// }
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
static async DeleteProduct(userId, productId) {
|
72
|
+
var wl = await this.GetCurrentWishlist(userId);
|
73
|
+
console.log(wl);
|
74
|
+
const index = wl.products.indexOf(productId);
|
75
|
+
console.log(index);
|
76
|
+
wl.products.splice(index, 1);
|
77
|
+
console.log("after delete" + wl.products)
|
78
|
+
await Wishlist.updateOne(
|
79
|
+
{ _id: wl._id},
|
80
|
+
{ $set: { products: wl.products } }
|
81
|
+
);
|
82
|
+
}
|
83
|
+
|
84
|
+
static async AddProductsFromSession(userId, products){
|
85
|
+
for(let i = 0; i < products.length; i++){
|
86
|
+
await this.AddProductFromSession(userId, products[i].id)
|
87
|
+
}
|
88
|
+
}
|
89
|
+
static async AddProductFromSession(id, productId) {
|
90
|
+
var wishlist = await this.GetCurrentWishlist(id)
|
91
|
+
var exists = wishlist.products.indexOf(productId) == -1 ? false: true;
|
92
|
+
console.log("exisits " + exists);
|
93
|
+
if(exists){
|
94
|
+
console.log("update quantity")
|
95
|
+
return;
|
96
|
+
}
|
97
|
+
console.log("new wish product " + productId);
|
98
|
+
wishlist.products.push(productId);
|
99
|
+
await Wishlist.updateOne(
|
100
|
+
{ _id: wishlist._id},
|
101
|
+
{ $set: { products: wishlist.products } }
|
102
|
+
);
|
103
|
+
}
|
104
|
+
|
105
|
+
};
|
@@ -0,0 +1,45 @@
|
|
1
|
+
import React, { Component } from "react";
|
2
|
+
import '../css/about.css';
|
3
|
+
|
4
|
+
class About extends Component {
|
5
|
+
render() {
|
6
|
+
return (
|
7
|
+
<div>
|
8
|
+
<div className="about-section">
|
9
|
+
<h1 >Welcome to The Flower Shop!</h1>
|
10
|
+
<h2>About Us</h2>
|
11
|
+
<p>Our store was established in 1970.</p>
|
12
|
+
<p>Since then we specialize in creating the most beautiful bouquets for any occasion you need:</p>
|
13
|
+
<p>A wedding, engagement or if you want to show your love to someone</p>
|
14
|
+
<p>We have delivery services all over the country</p>
|
15
|
+
<p>All at the best prices on the market</p>
|
16
|
+
<p>So just go to our bouquet catalog and choose your favorite bouquet and we will continue from there ..</p>
|
17
|
+
<p>For any question, request or problem, contact us at the button above and we will get back to you as soon as possible.</p>
|
18
|
+
</div>
|
19
|
+
<div className="carousel slide center" id="carouselExampleInterval" data-bs-ride="carousel" style={{"width":"30%", "height": "30%"}}>
|
20
|
+
<div className="carousel-inner" >
|
21
|
+
<div className="carousel-item active" data-bs-interval="5000">
|
22
|
+
<img src="../images/1.JPG" className="d-block w-100"/>
|
23
|
+
</div>
|
24
|
+
<div className="carousel-item" data-bs-interval="5000">
|
25
|
+
<img src="../images/2.JPG" className="d-block w-100"/>
|
26
|
+
</div>
|
27
|
+
<div className="carousel-item" data-bs-interval="5000">
|
28
|
+
<img src="../images/3.JPG" className="d-block w-100"/>
|
29
|
+
</div>
|
30
|
+
</div>
|
31
|
+
<button className="carousel-control-prev" type="button" data-bs-target="#carouselExampleInterval" data-bs-slide="prev">
|
32
|
+
<span className="carousel-control-prev-icon" aria-hidden="true"></span>
|
33
|
+
<span className="visually-hidden">Previous</span>
|
34
|
+
</button>
|
35
|
+
<button className="carousel-control-next" type="button" data-bs-target="#carouselExampleInterval" data-bs-slide="next">
|
36
|
+
<span className="carousel-control-next-icon" aria-hidden="true"></span>
|
37
|
+
<span className="visually-hidden">Next</span>
|
38
|
+
</button>
|
39
|
+
</div>
|
40
|
+
</div>
|
41
|
+
);
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
export default About;
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import React, {Component} from 'react';
|
2
|
+
import { Navigate } from 'react-router-dom';
|
3
|
+
export default function withAuth(Component){
|
4
|
+
const AuthRoute = () => {
|
5
|
+
const isAuth = !!localStorage.getItem("token");
|
6
|
+
console.log(localStorage);
|
7
|
+
if (isAuth) {
|
8
|
+
return <Component />;
|
9
|
+
} else {
|
10
|
+
return <Navigate to="/NoPermission" />;
|
11
|
+
}
|
12
|
+
};
|
13
|
+
|
14
|
+
return AuthRoute;
|
15
|
+
};
|