Spaces:
Sleeping
Sleeping
Mohamed Abu Basith
commited on
Commit
·
97f53b4
1
Parent(s):
02a1b88
addded all files
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- Database/DbConnection.js +18 -0
- Database/models/BabyItems.js +23 -0
- Database/models/DriedNoodles.js +23 -0
- Database/models/address.js +42 -0
- Database/models/banner.js +37 -0
- Database/models/category.js +12 -0
- Database/models/comments.js +70 -0
- Database/models/dairy.js +23 -0
- Database/models/drinks.js +23 -0
- Database/models/fruits.js +23 -0
- Database/models/gocery.js +23 -0
- Database/models/healthCare.js +23 -0
- Database/models/home.js +14 -0
- Database/models/newPost.js +66 -0
- Database/models/order.js +33 -0
- Database/models/personalCare.js +23 -0
- Database/models/postNews.js +13 -0
- Database/models/product.js +23 -0
- Database/models/special_offers.js +9 -0
- Database/models/user.js +118 -0
- Database/models/vegitables.js +23 -0
- Database/mufiModels/featureProduct.js +61 -0
- Database/mufiModels/hijabs.js +62 -0
- Database/mufiModels/scarfs.js +62 -0
- Dockerfile +1 -1
- README.md +1 -12
- app.js +117 -0
- bootstrap.js +75 -0
- core/auth.js +27 -0
- package.json +40 -11
- push-notification-key.json +13 -0
- routes/address.js +99 -0
- routes/babyItems.js +142 -0
- routes/banner.js +148 -0
- routes/category.js +128 -0
- routes/changePassword.js +48 -0
- routes/cmd.js +173 -0
- routes/comment.js +57 -0
- routes/confirmOrder.js +0 -0
- routes/dairy.js +125 -0
- routes/driedNoodles.js +128 -0
- routes/drinks.js +125 -0
- routes/fcm.js +75 -0
- routes/forgotPassword.js +214 -0
- routes/fruits.js +123 -0
- routes/grocery.js +127 -0
- routes/healthCare.js +126 -0
- routes/home.js +80 -0
- routes/login.js +93 -0
- routes/logout.js +36 -0
Database/DbConnection.js
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const mongoose = require("mongoose")
|
2 |
+
require('dotenv').config();
|
3 |
+
|
4 |
+
const musfiCollection = 'mongodb+srv://abu:[email protected]/?retryWrites=true&w=majority&appName=musficollection'
|
5 |
+
|
6 |
+
const hayatCollections = 'mongodb+srv://basith:[email protected]/RegisterLogin?retryWrites=true&w=majority'
|
7 |
+
|
8 |
+
function dbConnection() {
|
9 |
+
mongoose.connect(musfiCollection, {
|
10 |
+
connectTimeoutMS: 30000, // Set a custom timeout (default is 30,000 ms)
|
11 |
+
})
|
12 |
+
.then(() => console.log('MongoDB connected successfully'))
|
13 |
+
.catch(error => console.error('MongoDB connection error:', error));
|
14 |
+
|
15 |
+
mongoose.Promise = global.Promise;
|
16 |
+
}
|
17 |
+
|
18 |
+
module.exports = {dbConnection}
|
Database/models/BabyItems.js
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
var mongoose = require('mongoose');
|
2 |
+
|
3 |
+
const babyItems = mongoose.Schema({
|
4 |
+
_id: mongoose.Schema.Types.ObjectId,
|
5 |
+
name: {
|
6 |
+
type: String,
|
7 |
+
},
|
8 |
+
price: {
|
9 |
+
type: Number,
|
10 |
+
},
|
11 |
+
description: {
|
12 |
+
type: String,
|
13 |
+
},
|
14 |
+
image: {
|
15 |
+
type: String,
|
16 |
+
},
|
17 |
+
isLiked: {
|
18 |
+
type: Boolean,
|
19 |
+
default: false,
|
20 |
+
}
|
21 |
+
});
|
22 |
+
|
23 |
+
module.exports = mongoose.model('BabyItems', babyItems);
|
Database/models/DriedNoodles.js
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
var mongoose = require('mongoose');
|
2 |
+
|
3 |
+
const driedNoodles = mongoose.Schema({
|
4 |
+
_id: mongoose.Schema.Types.ObjectId,
|
5 |
+
name: {
|
6 |
+
type: String,
|
7 |
+
},
|
8 |
+
price: {
|
9 |
+
type: Number,
|
10 |
+
},
|
11 |
+
description: {
|
12 |
+
type: String,
|
13 |
+
},
|
14 |
+
image: {
|
15 |
+
type: String,
|
16 |
+
},
|
17 |
+
isLiked: {
|
18 |
+
type: Boolean,
|
19 |
+
default: false,
|
20 |
+
}
|
21 |
+
});
|
22 |
+
|
23 |
+
module.exports = mongoose.model('DriedNoodles', driedNoodles);
|
Database/models/address.js
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
var mongoose = require('mongoose');
|
2 |
+
var Schema = mongoose.Schema;
|
3 |
+
|
4 |
+
addressSchema = new Schema({
|
5 |
+
_id: mongoose.Schema.Types.ObjectId,
|
6 |
+
user_id: {
|
7 |
+
type: String
|
8 |
+
},
|
9 |
+
address: [
|
10 |
+
{
|
11 |
+
name: {
|
12 |
+
type: String
|
13 |
+
},
|
14 |
+
userId: {
|
15 |
+
type: String
|
16 |
+
},
|
17 |
+
mobileNumber: {
|
18 |
+
type: String
|
19 |
+
},
|
20 |
+
pinCode: {
|
21 |
+
type: String
|
22 |
+
},
|
23 |
+
address: {
|
24 |
+
type: String
|
25 |
+
},
|
26 |
+
area: {
|
27 |
+
type: String
|
28 |
+
},
|
29 |
+
landMark: {
|
30 |
+
type: String
|
31 |
+
},
|
32 |
+
alterMobileNumber: {
|
33 |
+
type: String
|
34 |
+
}
|
35 |
+
|
36 |
+
}
|
37 |
+
]
|
38 |
+
},
|
39 |
+
{ timestamps: true }
|
40 |
+
);
|
41 |
+
|
42 |
+
module.exports = mongoose.model('Address', addressSchema);
|
Database/models/banner.js
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
var mongoose = require('mongoose');
|
2 |
+
|
3 |
+
const bannerScheme = mongoose.Schema({
|
4 |
+
_id: mongoose.Schema.Types.ObjectId,
|
5 |
+
name: {
|
6 |
+
type: String,
|
7 |
+
},
|
8 |
+
percentage: {
|
9 |
+
type: String,
|
10 |
+
},
|
11 |
+
image: {
|
12 |
+
type: String
|
13 |
+
},
|
14 |
+
products: [
|
15 |
+
{
|
16 |
+
_id: mongoose.Schema.Types.ObjectId,
|
17 |
+
name: {
|
18 |
+
type: String,
|
19 |
+
},
|
20 |
+
price: {
|
21 |
+
type: Number,
|
22 |
+
},
|
23 |
+
description: {
|
24 |
+
type: String,
|
25 |
+
},
|
26 |
+
image: {
|
27 |
+
type: String,
|
28 |
+
},
|
29 |
+
isLiked: {
|
30 |
+
type: Boolean,
|
31 |
+
default: false,
|
32 |
+
}
|
33 |
+
},
|
34 |
+
],
|
35 |
+
});
|
36 |
+
|
37 |
+
module.exports = mongoose.model('Banner', bannerScheme);
|
Database/models/category.js
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
const { Schema, model } = require("mongoose");
|
3 |
+
|
4 |
+
const categorySchema = Schema({
|
5 |
+
id: Schema.Types.ObjectId,
|
6 |
+
name: { type: String, required: true },
|
7 |
+
description: { type: String },
|
8 |
+
image: { type: String },
|
9 |
+
link: { type: String },
|
10 |
+
});
|
11 |
+
|
12 |
+
module.exports = model("Category", categorySchema);
|
Database/models/comments.js
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const mongoose = require('mongoose');
|
2 |
+
|
3 |
+
const commentSchema = new mongoose.Schema(
|
4 |
+
{
|
5 |
+
user: {
|
6 |
+
type: mongoose.Schema.Types.ObjectId,
|
7 |
+
ref: 'User',
|
8 |
+
},
|
9 |
+
createdAt: {
|
10 |
+
type: Date,
|
11 |
+
default: Date.now,
|
12 |
+
},
|
13 |
+
comment: {
|
14 |
+
type: String,
|
15 |
+
required: [true, 'Comment is required'],
|
16 |
+
},
|
17 |
+
likes: [
|
18 |
+
{
|
19 |
+
type: mongoose.Schema.Types.ObjectId,
|
20 |
+
ref: 'User',
|
21 |
+
},
|
22 |
+
],
|
23 |
+
post: {
|
24 |
+
type: mongoose.Schema.Types.ObjectId,
|
25 |
+
ref: 'Post',
|
26 |
+
},
|
27 |
+
// reply: [
|
28 |
+
// {
|
29 |
+
// user: {
|
30 |
+
// type: mongoose.Schema.Types.ObjectId,
|
31 |
+
// ref: 'User',
|
32 |
+
// },
|
33 |
+
// comment: {
|
34 |
+
// type: String,
|
35 |
+
// },
|
36 |
+
// like: [
|
37 |
+
// {
|
38 |
+
// type: mongoose.Schema.Types.ObjectId,
|
39 |
+
// ref: 'Profile',
|
40 |
+
// },
|
41 |
+
// ],
|
42 |
+
// },
|
43 |
+
// ],
|
44 |
+
},
|
45 |
+
{
|
46 |
+
toJSON: { virtuals: true },
|
47 |
+
toObject: { virtuals: true },
|
48 |
+
}
|
49 |
+
);
|
50 |
+
|
51 |
+
// commentSchema.virtual('replies', {
|
52 |
+
// ref: 'Reply',
|
53 |
+
// localField: '_id',
|
54 |
+
// foreignField: 'comment'
|
55 |
+
|
56 |
+
// })
|
57 |
+
|
58 |
+
commentSchema.pre(/^find/, function (next) {
|
59 |
+
this.find()
|
60 |
+
.populate('user')
|
61 |
+
.populate({
|
62 |
+
path: 'likes',
|
63 |
+
select: 'username user name photo _id',
|
64 |
+
});
|
65 |
+
|
66 |
+
next();
|
67 |
+
});
|
68 |
+
|
69 |
+
const Comment = mongoose.model('Comment', commentSchema);
|
70 |
+
module.exports = Comment;
|
Database/models/dairy.js
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
var mongoose = require('mongoose');
|
2 |
+
|
3 |
+
const diaryScheme = mongoose.Schema({
|
4 |
+
_id: mongoose.Schema.Types.ObjectId,
|
5 |
+
name: {
|
6 |
+
type: String,
|
7 |
+
},
|
8 |
+
price: {
|
9 |
+
type: Number,
|
10 |
+
},
|
11 |
+
description: {
|
12 |
+
type: String,
|
13 |
+
},
|
14 |
+
image: {
|
15 |
+
type: String,
|
16 |
+
},
|
17 |
+
isLiked: {
|
18 |
+
type: Boolean,
|
19 |
+
default: false,
|
20 |
+
}
|
21 |
+
});
|
22 |
+
|
23 |
+
module.exports = mongoose.model('Diary', diaryScheme);
|
Database/models/drinks.js
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
var mongoose = require('mongoose');
|
2 |
+
|
3 |
+
const drinksScheme = mongoose.Schema({
|
4 |
+
_id: mongoose.Schema.Types.ObjectId,
|
5 |
+
name: {
|
6 |
+
type: String,
|
7 |
+
},
|
8 |
+
price: {
|
9 |
+
type: Number,
|
10 |
+
},
|
11 |
+
description: {
|
12 |
+
type: String,
|
13 |
+
},
|
14 |
+
image: {
|
15 |
+
type: String,
|
16 |
+
},
|
17 |
+
isLiked: {
|
18 |
+
type: Boolean,
|
19 |
+
default: false,
|
20 |
+
}
|
21 |
+
});
|
22 |
+
|
23 |
+
module.exports = mongoose.model('Drinks', drinksScheme);
|
Database/models/fruits.js
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
var mongoose = require('mongoose');
|
2 |
+
|
3 |
+
const fruitsScheme = mongoose.Schema({
|
4 |
+
_id: mongoose.Schema.Types.ObjectId,
|
5 |
+
name: {
|
6 |
+
type: String,
|
7 |
+
},
|
8 |
+
price: {
|
9 |
+
type: Number,
|
10 |
+
},
|
11 |
+
description: {
|
12 |
+
type: String,
|
13 |
+
},
|
14 |
+
image: {
|
15 |
+
type: String,
|
16 |
+
},
|
17 |
+
isLiked: {
|
18 |
+
type: Boolean,
|
19 |
+
default: false,
|
20 |
+
}
|
21 |
+
});
|
22 |
+
|
23 |
+
module.exports = mongoose.model('Fruits', fruitsScheme);
|
Database/models/gocery.js
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
var mongoose = require('mongoose');
|
2 |
+
|
3 |
+
const groceryScheme = mongoose.Schema({
|
4 |
+
_id: mongoose.Schema.Types.ObjectId,
|
5 |
+
name: {
|
6 |
+
type: String,
|
7 |
+
},
|
8 |
+
price: {
|
9 |
+
type: Number,
|
10 |
+
},
|
11 |
+
description: {
|
12 |
+
type: String,
|
13 |
+
},
|
14 |
+
image: {
|
15 |
+
type: String,
|
16 |
+
},
|
17 |
+
isLiked: {
|
18 |
+
type: Boolean,
|
19 |
+
default: false,
|
20 |
+
}
|
21 |
+
});
|
22 |
+
|
23 |
+
module.exports = mongoose.model('Grocery', groceryScheme);
|
Database/models/healthCare.js
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
var mongoose = require('mongoose');
|
2 |
+
|
3 |
+
const healthCare = mongoose.Schema({
|
4 |
+
_id: mongoose.Schema.Types.ObjectId,
|
5 |
+
name: {
|
6 |
+
type: String,
|
7 |
+
},
|
8 |
+
price: {
|
9 |
+
type: Number,
|
10 |
+
},
|
11 |
+
description: {
|
12 |
+
type: String,
|
13 |
+
},
|
14 |
+
image: {
|
15 |
+
type: String,
|
16 |
+
},
|
17 |
+
isLiked: {
|
18 |
+
type: Boolean,
|
19 |
+
default: false,
|
20 |
+
}
|
21 |
+
});
|
22 |
+
|
23 |
+
module.exports = mongoose.model('HealthCare', healthCare);
|
Database/models/home.js
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
const { Schema, model } = require("mongoose");
|
3 |
+
import bannerSchema from '../models/banner'
|
4 |
+
import productSchema from '../models/product'
|
5 |
+
import categorySchema from '../models/category'
|
6 |
+
|
7 |
+
const homeSchema = new Schema({
|
8 |
+
banners: [bannerSchema],
|
9 |
+
categories: [categorySchema],
|
10 |
+
recentPurchase: [],
|
11 |
+
newProducts: [productSchema]
|
12 |
+
});
|
13 |
+
|
14 |
+
module.exports = model('Home', homeSchema);
|
Database/models/newPost.js
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const mongoose = require('mongoose');
|
2 |
+
const Profile = require('./user');
|
3 |
+
|
4 |
+
const postSchema = new mongoose.Schema(
|
5 |
+
{
|
6 |
+
user: {
|
7 |
+
type: mongoose.Schema.Types.ObjectId,
|
8 |
+
ref: 'User',
|
9 |
+
},
|
10 |
+
createdAt: {
|
11 |
+
type: Date,
|
12 |
+
default: Date.now,
|
13 |
+
},
|
14 |
+
profile: {
|
15 |
+
type: mongoose.Schema.Types.ObjectId,
|
16 |
+
ref: 'User',
|
17 |
+
},
|
18 |
+
caption: {
|
19 |
+
type: String,
|
20 |
+
trim: true,
|
21 |
+
},
|
22 |
+
location: {
|
23 |
+
type: String,
|
24 |
+
},
|
25 |
+
likes: [
|
26 |
+
{
|
27 |
+
type: mongoose.Schema.Types.ObjectId,
|
28 |
+
ref: 'User',
|
29 |
+
},
|
30 |
+
],
|
31 |
+
image: String,
|
32 |
+
// comment: {
|
33 |
+
// type: mongoose.Schema.Types.ObjectId,
|
34 |
+
// ref: 'Comment',
|
35 |
+
// },
|
36 |
+
},
|
37 |
+
{
|
38 |
+
toJSON: { virtuals: true },
|
39 |
+
toObject: { virtuals: true },
|
40 |
+
}
|
41 |
+
);
|
42 |
+
|
43 |
+
postSchema.set('toObject', { virtuals: true });
|
44 |
+
postSchema.set('toJSON', { virtuals: true });
|
45 |
+
|
46 |
+
postSchema.virtual('commentsPost', {
|
47 |
+
ref: 'Comment',
|
48 |
+
localField: '_id',
|
49 |
+
foreignField: 'post',
|
50 |
+
});
|
51 |
+
|
52 |
+
postSchema.methods.getProfileId = async function (id) {
|
53 |
+
const { _id } = await Profile.findOne({ unique_id: id });
|
54 |
+
return _id;
|
55 |
+
};
|
56 |
+
|
57 |
+
// //Todo
|
58 |
+
// postSchema.pre(/^find/, function (next) {
|
59 |
+
// this.find().populate('commentsPost');
|
60 |
+
|
61 |
+
// next();
|
62 |
+
// });
|
63 |
+
|
64 |
+
const Post = mongoose.model('PostTest', postSchema);
|
65 |
+
|
66 |
+
module.exports = Post;
|
Database/models/order.js
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const mongoose = require('mongoose');
|
2 |
+
|
3 |
+
const orderSchema = new mongoose.Schema(
|
4 |
+
{
|
5 |
+
unique_id: { type: Number, required: true },
|
6 |
+
numOfItems: { type: Number, required: true },
|
7 |
+
user_id: { type: Number, required: true },
|
8 |
+
user_name: { type: String, required: true },
|
9 |
+
products: [
|
10 |
+
{
|
11 |
+
productId: {
|
12 |
+
type: String,
|
13 |
+
},
|
14 |
+
productName: {
|
15 |
+
type: String,
|
16 |
+
},
|
17 |
+
productImage: {
|
18 |
+
type: String,
|
19 |
+
// required: true
|
20 |
+
},
|
21 |
+
quantity: {
|
22 |
+
type: String,
|
23 |
+
},
|
24 |
+
},
|
25 |
+
],
|
26 |
+
amount: { type: Number, required: true },
|
27 |
+
address: { type: Object, required: true },
|
28 |
+
status: { type: String, default: "Packing" },
|
29 |
+
},
|
30 |
+
{ timestamps: true }
|
31 |
+
);
|
32 |
+
|
33 |
+
module.exports = mongoose.model('Order', orderSchema);
|
Database/models/personalCare.js
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
var mongoose = require('mongoose');
|
2 |
+
|
3 |
+
const personalCareScheme = mongoose.Schema({
|
4 |
+
_id: mongoose.Schema.Types.ObjectId,
|
5 |
+
name: {
|
6 |
+
type: String,
|
7 |
+
},
|
8 |
+
price: {
|
9 |
+
type: Number,
|
10 |
+
},
|
11 |
+
description: {
|
12 |
+
type: String,
|
13 |
+
},
|
14 |
+
image: {
|
15 |
+
type: String,
|
16 |
+
},
|
17 |
+
isLiked: {
|
18 |
+
type: Boolean,
|
19 |
+
default: false,
|
20 |
+
}
|
21 |
+
});
|
22 |
+
|
23 |
+
module.exports = mongoose.model('PersonalCare', personalCareScheme);
|
Database/models/postNews.js
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const mongoose = require('mongoose');
|
2 |
+
|
3 |
+
const postSchema = new mongoose.Schema({
|
4 |
+
postId: {
|
5 |
+
type: mongoose.Schema.Types.ObjectId, ref: 'User'
|
6 |
+
},
|
7 |
+
postedBy: String,
|
8 |
+
caption: String,
|
9 |
+
imageUrl: String,
|
10 |
+
liked: String,
|
11 |
+
});
|
12 |
+
|
13 |
+
module.exports = mongoose.model('Post', postSchema);
|
Database/models/product.js
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
var mongoose = require('mongoose');
|
2 |
+
|
3 |
+
const productSchema = mongoose.Schema({
|
4 |
+
_id: mongoose.Schema.Types.ObjectId,
|
5 |
+
name: {
|
6 |
+
type: String,
|
7 |
+
},
|
8 |
+
price: {
|
9 |
+
type: Number,
|
10 |
+
},
|
11 |
+
description: {
|
12 |
+
type: String,
|
13 |
+
},
|
14 |
+
image: {
|
15 |
+
type: String,
|
16 |
+
},
|
17 |
+
isLiked: {
|
18 |
+
type: Boolean,
|
19 |
+
default: false,
|
20 |
+
}
|
21 |
+
});
|
22 |
+
|
23 |
+
module.exports = mongoose.model('Product', productSchema);
|
Database/models/special_offers.js
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
var mongoose = require('mongoose');
|
2 |
+
|
3 |
+
const specialOffer = mongoose.Schema({
|
4 |
+
_id: mongoose.Schema.Types.ObjectId,
|
5 |
+
offerName: { type: String, require: true },
|
6 |
+
offerBannerImage: { type: String, require: true }
|
7 |
+
})
|
8 |
+
|
9 |
+
module.exports = mongoose.model('Offers', specialOffer);
|
Database/models/user.js
ADDED
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const mongoose = require('mongoose');
|
2 |
+
const { Schema } = mongoose;
|
3 |
+
|
4 |
+
const userSchema = new Schema({
|
5 |
+
unique_id: {
|
6 |
+
type: Number,
|
7 |
+
required: true,
|
8 |
+
unique: true
|
9 |
+
},
|
10 |
+
email: {
|
11 |
+
type: String,
|
12 |
+
unique: true,
|
13 |
+
sparse: true, // Indexing only if present
|
14 |
+
validate: {
|
15 |
+
validator: function (value) {
|
16 |
+
// Validate only if the email field is updated
|
17 |
+
if (this.isModified('email') && value) {
|
18 |
+
return !this.mobileNumber;
|
19 |
+
}
|
20 |
+
return true;
|
21 |
+
},
|
22 |
+
message: 'Mobile number must be empty if email is provided.'
|
23 |
+
}
|
24 |
+
},
|
25 |
+
|
26 |
+
username: {
|
27 |
+
type: String,
|
28 |
+
required: true
|
29 |
+
},
|
30 |
+
dateOfBirth: {
|
31 |
+
type: String
|
32 |
+
},
|
33 |
+
mobileNumber: {
|
34 |
+
type: String,
|
35 |
+
unique: true,
|
36 |
+
sparse: true, // Indexing only if present
|
37 |
+
validate: {
|
38 |
+
validator: function (value) {
|
39 |
+
// Validate only if the mobileNumber field is updated
|
40 |
+
if (this.isModified('mobileNumber') && value) {
|
41 |
+
return !this.email;
|
42 |
+
}
|
43 |
+
return true;
|
44 |
+
},
|
45 |
+
message: 'Email must be empty if mobile number is provided.'
|
46 |
+
}
|
47 |
+
},
|
48 |
+
password: {
|
49 |
+
type: String,
|
50 |
+
required: true
|
51 |
+
},
|
52 |
+
pushToken: {
|
53 |
+
type: String
|
54 |
+
},
|
55 |
+
token: {
|
56 |
+
type: String
|
57 |
+
},
|
58 |
+
role: {
|
59 |
+
type: String,
|
60 |
+
enum: ['user', 'admin', 'customer'],
|
61 |
+
default: 'user'
|
62 |
+
},
|
63 |
+
googleId: {
|
64 |
+
type: String
|
65 |
+
},
|
66 |
+
profilePic: {
|
67 |
+
type: String
|
68 |
+
},
|
69 |
+
address: [
|
70 |
+
{
|
71 |
+
name: {
|
72 |
+
type: String
|
73 |
+
},
|
74 |
+
userId: {
|
75 |
+
type: String
|
76 |
+
},
|
77 |
+
mobileNumber: {
|
78 |
+
type: String
|
79 |
+
},
|
80 |
+
pinCode: {
|
81 |
+
type: String
|
82 |
+
},
|
83 |
+
address: {
|
84 |
+
type: String
|
85 |
+
},
|
86 |
+
area: {
|
87 |
+
type: String
|
88 |
+
},
|
89 |
+
landMark: {
|
90 |
+
type: String
|
91 |
+
},
|
92 |
+
alterMobileNumber: {
|
93 |
+
type: String
|
94 |
+
}
|
95 |
+
}
|
96 |
+
]
|
97 |
+
}, {
|
98 |
+
timestamps: true // This adds `createdAt` and `updatedAt` fields
|
99 |
+
});
|
100 |
+
|
101 |
+
// Pre-update hook to ensure validation happens only when email or mobileNumber are updated
|
102 |
+
// userSchema.pre('findOneAndUpdate', function (next) {
|
103 |
+
// const update = this.getUpdate();
|
104 |
+
// const user = this._conditions;
|
105 |
+
|
106 |
+
// // Check if email and mobileNumber are both in the update query
|
107 |
+
// if (update.email && update.mobileNumber) {
|
108 |
+
// const error = new Error('Email and mobile number cannot both be provided.');
|
109 |
+
// return next(error); // Return error if both fields are set
|
110 |
+
// }
|
111 |
+
|
112 |
+
// // Proceed with the update
|
113 |
+
// next();
|
114 |
+
// });
|
115 |
+
|
116 |
+
const User = mongoose.model('User', userSchema);
|
117 |
+
|
118 |
+
module.exports = User;
|
Database/models/vegitables.js
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
var mongoose = require('mongoose');
|
2 |
+
|
3 |
+
const vegetablesSchema = mongoose.Schema({
|
4 |
+
_id: mongoose.Schema.Types.ObjectId,
|
5 |
+
name: {
|
6 |
+
type: String,
|
7 |
+
},
|
8 |
+
price: {
|
9 |
+
type: Number,
|
10 |
+
},
|
11 |
+
description: {
|
12 |
+
type: String,
|
13 |
+
},
|
14 |
+
image: {
|
15 |
+
type: String,
|
16 |
+
},
|
17 |
+
isLiked: {
|
18 |
+
type: Boolean,
|
19 |
+
default: false,
|
20 |
+
}
|
21 |
+
});
|
22 |
+
|
23 |
+
module.exports = mongoose.model('Vegetables', vegetablesSchema);
|
Database/mufiModels/featureProduct.js
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const { Schema, model } = require("mongoose");
|
2 |
+
const mongoose = require("mongoose");
|
3 |
+
|
4 |
+
const featureProductsScema = new Schema(
|
5 |
+
{
|
6 |
+
name: {
|
7 |
+
type: String,
|
8 |
+
required: true,
|
9 |
+
unique: true,
|
10 |
+
trim: true,
|
11 |
+
minLength: [3, "Too Short product Name"],
|
12 |
+
},
|
13 |
+
images: {
|
14 |
+
type: [String],
|
15 |
+
},
|
16 |
+
description: {
|
17 |
+
type: String,
|
18 |
+
maxlength: [100, "Description should be less than or equal to 100"],
|
19 |
+
minlength: [10, "Description should be more than or equal to 10"],
|
20 |
+
required: true,
|
21 |
+
trim: true,
|
22 |
+
},
|
23 |
+
price: {
|
24 |
+
type: Number,
|
25 |
+
default: 0,
|
26 |
+
min: 0,
|
27 |
+
required: true,
|
28 |
+
},
|
29 |
+
priceAfterDiscount: {
|
30 |
+
type: Number,
|
31 |
+
default: 0,
|
32 |
+
min: 0,
|
33 |
+
},
|
34 |
+
quantity: {
|
35 |
+
type: Number,
|
36 |
+
default: 0,
|
37 |
+
min: 0,
|
38 |
+
},
|
39 |
+
sold: {
|
40 |
+
type: Number,
|
41 |
+
default: 0,
|
42 |
+
min: 0,
|
43 |
+
},
|
44 |
+
category: {
|
45 |
+
type: Schema.ObjectId,
|
46 |
+
ref: "Category",
|
47 |
+
},
|
48 |
+
ratingAvg: {
|
49 |
+
type: Number,
|
50 |
+
min: 1,
|
51 |
+
max: 5,
|
52 |
+
},
|
53 |
+
ratingCount: {
|
54 |
+
type: Number,
|
55 |
+
min: 0,
|
56 |
+
},
|
57 |
+
},
|
58 |
+
{ timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
|
59 |
+
)
|
60 |
+
|
61 |
+
module.exports = mongoose.model('featureProducts', featureProductsScema);
|
Database/mufiModels/hijabs.js
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const { Schema, model } = require("mongoose");
|
2 |
+
const mongoose = require("mongoose");
|
3 |
+
|
4 |
+
const hijabsScema = new Schema(
|
5 |
+
{
|
6 |
+
name: {
|
7 |
+
type: String,
|
8 |
+
required: true,
|
9 |
+
unique: true,
|
10 |
+
trim: true,
|
11 |
+
minLength: [3, "Too Short product Name"],
|
12 |
+
},
|
13 |
+
images: {
|
14 |
+
type: [String],
|
15 |
+
},
|
16 |
+
description: {
|
17 |
+
type: String,
|
18 |
+
maxlength: [100, "Description should be less than or equal to 100"],
|
19 |
+
minlength: [10, "Description should be more than or equal to 10"],
|
20 |
+
required: true,
|
21 |
+
trim: true,
|
22 |
+
},
|
23 |
+
price: {
|
24 |
+
type: Number,
|
25 |
+
default: 0,
|
26 |
+
min: 0,
|
27 |
+
required: true,
|
28 |
+
},
|
29 |
+
priceAfterDiscount: {
|
30 |
+
type: Number,
|
31 |
+
default: 0,
|
32 |
+
min: 0,
|
33 |
+
},
|
34 |
+
quantity: {
|
35 |
+
type: Number,
|
36 |
+
default: 0,
|
37 |
+
min: 0,
|
38 |
+
},
|
39 |
+
sold: {
|
40 |
+
type: Number,
|
41 |
+
default: 0,
|
42 |
+
min: 0,
|
43 |
+
},
|
44 |
+
category: {
|
45 |
+
type: Schema.ObjectId,
|
46 |
+
ref: "Category",
|
47 |
+
required: true,
|
48 |
+
},
|
49 |
+
ratingAvg: {
|
50 |
+
type: Number,
|
51 |
+
min: 1,
|
52 |
+
max: 5,
|
53 |
+
},
|
54 |
+
ratingCount: {
|
55 |
+
type: Number,
|
56 |
+
min: 0,
|
57 |
+
},
|
58 |
+
},
|
59 |
+
{ timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
|
60 |
+
)
|
61 |
+
|
62 |
+
module.exports = mongoose.model('hijabs', hijabsScema);
|
Database/mufiModels/scarfs.js
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const { Schema, model } = require("mongoose");
|
2 |
+
const mongoose = require("mongoose");
|
3 |
+
|
4 |
+
const scarfsScema = new Schema(
|
5 |
+
{
|
6 |
+
name: {
|
7 |
+
type: String,
|
8 |
+
required: true,
|
9 |
+
unique: true,
|
10 |
+
trim: true,
|
11 |
+
minLength: [3, "Too Short product Name"],
|
12 |
+
},
|
13 |
+
images: {
|
14 |
+
type: [String],
|
15 |
+
},
|
16 |
+
description: {
|
17 |
+
type: String,
|
18 |
+
maxlength: [100, "Description should be less than or equal to 100"],
|
19 |
+
minlength: [10, "Description should be more than or equal to 10"],
|
20 |
+
required: true,
|
21 |
+
trim: true,
|
22 |
+
},
|
23 |
+
price: {
|
24 |
+
type: Number,
|
25 |
+
default: 0,
|
26 |
+
min: 0,
|
27 |
+
required: true,
|
28 |
+
},
|
29 |
+
priceAfterDiscount: {
|
30 |
+
type: Number,
|
31 |
+
default: 0,
|
32 |
+
min: 0,
|
33 |
+
},
|
34 |
+
quantity: {
|
35 |
+
type: Number,
|
36 |
+
default: 0,
|
37 |
+
min: 0,
|
38 |
+
},
|
39 |
+
sold: {
|
40 |
+
type: Number,
|
41 |
+
default: 0,
|
42 |
+
min: 0,
|
43 |
+
},
|
44 |
+
category: {
|
45 |
+
type: Schema.ObjectId,
|
46 |
+
ref: "Category",
|
47 |
+
required: true,
|
48 |
+
},
|
49 |
+
ratingAvg: {
|
50 |
+
type: Number,
|
51 |
+
min: 1,
|
52 |
+
max: 5,
|
53 |
+
},
|
54 |
+
ratingCount: {
|
55 |
+
type: Number,
|
56 |
+
min: 0,
|
57 |
+
},
|
58 |
+
},
|
59 |
+
{ timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
|
60 |
+
)
|
61 |
+
|
62 |
+
module.exports = mongoose.model('scarfs', scarfsScema);
|
Dockerfile
CHANGED
@@ -18,5 +18,5 @@ RUN npm ci --only=production
|
|
18 |
# Copy the rest of your application code
|
19 |
COPY . .
|
20 |
|
21 |
-
EXPOSE
|
22 |
CMD ["node", "server.js"]
|
|
|
18 |
# Copy the rest of your application code
|
19 |
COPY . .
|
20 |
|
21 |
+
EXPOSE 4000
|
22 |
CMD ["node", "server.js"]
|
README.md
CHANGED
@@ -1,12 +1 @@
|
|
1 |
-
|
2 |
-
title: Hayat
|
3 |
-
emoji: 🏃
|
4 |
-
colorFrom: pink
|
5 |
-
colorTo: green
|
6 |
-
sdk: docker
|
7 |
-
pinned: false
|
8 |
-
license: apache-2.0
|
9 |
-
short_description: Node JS backend project
|
10 |
-
---
|
11 |
-
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
+
# MyApi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.js
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
var express = require('express');
|
2 |
+
var router = express.Router();
|
3 |
+
var app = express();
|
4 |
+
const http = require('http');
|
5 |
+
var bodyParser = require('body-parser');
|
6 |
+
const morgan = require('morgan');
|
7 |
+
|
8 |
+
|
9 |
+
//Routes
|
10 |
+
const login = require("./routes/login");
|
11 |
+
const register = require("./routes/register");
|
12 |
+
const profile = require("./routes/profile");
|
13 |
+
const profileUpdate = require("./routes/profileUpdate");
|
14 |
+
const changePassword = require("./routes/changePassword");
|
15 |
+
const productRoutes = require("./routes/products");
|
16 |
+
const orderRoutes = require("./routes/orders");
|
17 |
+
const category = require("./routes/category");
|
18 |
+
const vegetables = require("./routes/vegetables");
|
19 |
+
const grocery = require("./routes/grocery");
|
20 |
+
const drinks = require("./routes/drinks");
|
21 |
+
const fruites = require("./routes/fruits");
|
22 |
+
const dairy = require("./routes/dairy");
|
23 |
+
const forgotPassword = require("./routes/forgotPassword")
|
24 |
+
const fcm = require("./routes/fcm");
|
25 |
+
const banner = require("./routes/banner");
|
26 |
+
const address = require("./routes/address")
|
27 |
+
const firebase = require("./utils/firebase")
|
28 |
+
const post = require("./routes/post")
|
29 |
+
const newPost = require("./routes/newPost");
|
30 |
+
const comment = require("./routes/cmd");
|
31 |
+
const personalCare = require("./routes/personalCare");
|
32 |
+
const healthCare = require("./routes/healthCare");
|
33 |
+
const driedNoodles = require("./routes/driedNoodles");
|
34 |
+
const home = require("./routes/home")
|
35 |
+
const babyItems = require("./routes/babyItems")
|
36 |
+
|
37 |
+
// //Mongoes Db
|
38 |
+
// mongoose.connect('mongodb+srv://basith:[email protected]/RegisterLogin?retryWrites=true&w=majority', {
|
39 |
+
// useNewUrlParser: true,
|
40 |
+
// useUnifiedTopology: true
|
41 |
+
// }, (err) => {
|
42 |
+
// if (!err) {
|
43 |
+
// console.log('MongoDB Connection Succeeded.');
|
44 |
+
// } else {
|
45 |
+
// console.log('Error in DB connection : ' + err);
|
46 |
+
// }
|
47 |
+
// });
|
48 |
+
|
49 |
+
// mongoose.Promise = global.Promise;
|
50 |
+
|
51 |
+
|
52 |
+
//Setting the requestParse
|
53 |
+
app.use(morgan("dev"));
|
54 |
+
app.use('/uploads', express.static('uploads'));
|
55 |
+
app.use(bodyParser.urlencoded({ extended: false }));
|
56 |
+
app.use(bodyParser.json());
|
57 |
+
|
58 |
+
|
59 |
+
//IDK why we use this and i think this is Header what required....
|
60 |
+
app.use((req, res, next) => {
|
61 |
+
res.header("Access-Control-Allow-Origin", "*");
|
62 |
+
res.header(
|
63 |
+
"Access-Control-Allow-Headers",
|
64 |
+
"Origin, X-Requested-With, Content-Type, Accept, Authorization"
|
65 |
+
);
|
66 |
+
if (req.method === "OPTIONS") {
|
67 |
+
res.header("Access-Control-Allow-Methods", "PUT, POST, PATCH, DELETE, GET");
|
68 |
+
return res.status(200).json({});
|
69 |
+
}
|
70 |
+
next();
|
71 |
+
});
|
72 |
+
|
73 |
+
// Routes which should handle requests
|
74 |
+
app.use("/login", login);
|
75 |
+
app.use("/register", register);
|
76 |
+
app.use("/profile", profile);
|
77 |
+
app.use("/profileUpdate", profileUpdate);
|
78 |
+
app.use("/products", productRoutes);
|
79 |
+
app.use("/category", category);
|
80 |
+
app.use("/orders", orderRoutes);
|
81 |
+
app.use("/vegetables", vegetables);
|
82 |
+
app.use("/grocery", grocery);
|
83 |
+
app.use("/fruits", fruites);
|
84 |
+
app.use("/drinks", drinks);
|
85 |
+
app.use("/dairy", dairy);
|
86 |
+
app.use("/forgotPassword", forgotPassword);
|
87 |
+
app.use("/changePassword", changePassword);
|
88 |
+
app.use("/fcm", fcm);
|
89 |
+
app.use("/banner", banner);
|
90 |
+
app.use("/address", address);
|
91 |
+
app.use("/newPost", newPost);
|
92 |
+
app.use("/cmd", comment);
|
93 |
+
app.use("/personalCare", personalCare);
|
94 |
+
app.use("/healthCare", healthCare);
|
95 |
+
app.use("/driedNoodles", driedNoodles);
|
96 |
+
app.use("/home", home)
|
97 |
+
app.use("/babyItems", babyItems)
|
98 |
+
|
99 |
+
|
100 |
+
//Error catch
|
101 |
+
app.use((req, res, next) => {
|
102 |
+
const error = new Error("Not found");
|
103 |
+
error.status = 404;
|
104 |
+
next(error);
|
105 |
+
});
|
106 |
+
|
107 |
+
//Some other error show
|
108 |
+
app.use((error, req, res, next) => {
|
109 |
+
res.status(error.status || 500);
|
110 |
+
res.json({
|
111 |
+
error: {
|
112 |
+
message: error.message
|
113 |
+
}
|
114 |
+
});
|
115 |
+
});
|
116 |
+
|
117 |
+
module.exports = app;
|
bootstrap.js
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const { AppError } = require("./utils/AppError.js");
|
2 |
+
const globalErrorHandling = require("./utils/GlobalErrorHandling.js");
|
3 |
+
|
4 |
+
// Routes
|
5 |
+
const login = require("./routes/login");
|
6 |
+
const register = require("./routes/register");
|
7 |
+
const profile = require("./routes/profile");
|
8 |
+
const profileUpdate = require("./routes/profileUpdate");
|
9 |
+
const changePassword = require("./routes/changePassword");
|
10 |
+
const productRoutes = require("./routes/products");
|
11 |
+
const orderRoutes = require("./routes/orders");
|
12 |
+
const category = require("./routes/category");
|
13 |
+
const vegetables = require("./routes/vegetables");
|
14 |
+
const grocery = require("./routes/grocery");
|
15 |
+
const drinks = require("./routes/drinks");
|
16 |
+
const fruites = require("./routes/fruits");
|
17 |
+
const dairy = require("./routes/dairy");
|
18 |
+
const forgotPassword = require("./routes/forgotPassword");
|
19 |
+
const fcm = require("./routes/fcm");
|
20 |
+
const banner = require("./routes/banner");
|
21 |
+
const address = require("./routes/address");
|
22 |
+
const post = require("./routes/post");
|
23 |
+
const newPost = require("./routes/newPost");
|
24 |
+
const comment = require("./routes/cmd");
|
25 |
+
const personalCare = require("./routes/personalCare");
|
26 |
+
const healthCare = require("./routes/healthCare");
|
27 |
+
const driedNoodles = require("./routes/driedNoodles");
|
28 |
+
const home = require("./routes/home");
|
29 |
+
const babyItems = require("./routes/babyItems");
|
30 |
+
|
31 |
+
const hijabRouter = require("./routes/musfiRouters/hijabs/hijabsRouter.js");
|
32 |
+
const featureRoute = require("./routes/musfiRouters/featureProducts/featureProductsRouter.js");
|
33 |
+
const scarfsRouter = require("./routes/musfiRouters/scarfs/scarfsRouter.js");
|
34 |
+
|
35 |
+
function bootstrap(app) {
|
36 |
+
app.use("/api/v1/login", login);
|
37 |
+
app.use("/api/v1/register", register);
|
38 |
+
app.use("/api/v1/profile", profile);
|
39 |
+
app.use("/api/v1/profileUpdate", profileUpdate);
|
40 |
+
app.use("/api/v1/changePassword", changePassword);
|
41 |
+
app.use("/api/v1/productRoutes", productRoutes);
|
42 |
+
app.use("/api/v1/orderRoutes", orderRoutes);
|
43 |
+
app.use("/api/v1/category", category);
|
44 |
+
app.use("/api/v1/vegetables", vegetables);
|
45 |
+
app.use("/api/v1/grocery", grocery);
|
46 |
+
app.use("/api/v1/drinks", drinks);
|
47 |
+
app.use("/api/v1/fruites", fruites);
|
48 |
+
app.use("/api/v1/dairy", dairy);
|
49 |
+
app.use("/api/v1/forgotPassword", forgotPassword);
|
50 |
+
app.use("/api/v1/address", address);
|
51 |
+
app.use("/api/v1/fcm", fcm);
|
52 |
+
app.use("/api/v1/banner", banner);
|
53 |
+
app.use("/api/v1/home", home);
|
54 |
+
app.use("/api/v1/babyItems", babyItems);
|
55 |
+
app.use("/api/v1/personalCare", personalCare);
|
56 |
+
app.use("/api/v1/healthCare", healthCare);
|
57 |
+
app.use("/api/v1/driedNoodles", driedNoodles);
|
58 |
+
app.use("/api/v1/post", post);
|
59 |
+
app.use("/api/v1/newPost", newPost);
|
60 |
+
app.use("/api/v1/comment", comment);
|
61 |
+
|
62 |
+
app.use("/api/v1/hijabs", hijabRouter);
|
63 |
+
app.use("/api/v1/featureProducts", featureRoute)
|
64 |
+
app.use("/api/v1/scarfs", scarfsRouter)
|
65 |
+
|
66 |
+
// Catch-all for undefined routes
|
67 |
+
app.all("*", (req, res, next) => {
|
68 |
+
next(new AppError("Endpoint was not found", 404));
|
69 |
+
});
|
70 |
+
|
71 |
+
// // Global error handling middleware
|
72 |
+
// app.use(globalErrorHandling);
|
73 |
+
}
|
74 |
+
|
75 |
+
module.exports = { bootstrap };
|
core/auth.js
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const { OAuth2Client } = require('google-auth-library');
|
2 |
+
require('dotenv').config();
|
3 |
+
const googleClientId = process.env.GOOGLE_ID;
|
4 |
+
|
5 |
+
// Initialize the OAuth2 client with your Google Client ID
|
6 |
+
const client = new OAuth2Client('YOUR_GOOGLE_CLIENT_ID');
|
7 |
+
|
8 |
+
async function verifyGoogleToken(token) {
|
9 |
+
try {
|
10 |
+
// Verify the token
|
11 |
+
const ticket = await client.verifyIdToken({
|
12 |
+
idToken: token,
|
13 |
+
audience: googleClientId, // Specify the CLIENT_ID of the app that accesses the backend
|
14 |
+
});
|
15 |
+
|
16 |
+
// Get the user payload from the ticket
|
17 |
+
const payload = ticket.getPayload();
|
18 |
+
|
19 |
+
// Return the payload with user information
|
20 |
+
return ticket;
|
21 |
+
} catch (error) {
|
22 |
+
console.error('Google token verification failed:', error);
|
23 |
+
throw new Error('Invalid Google token');
|
24 |
+
}
|
25 |
+
}
|
26 |
+
|
27 |
+
module.exports = verifyGoogleToken;
|
package.json
CHANGED
@@ -1,13 +1,42 @@
|
|
1 |
{
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
"
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
"
|
11 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
}
|
13 |
-
|
|
|
1 |
{
|
2 |
+
"name": "creating-registration-and-login-form-in-nodejs-and-mongodb",
|
3 |
+
"version": "1.0.0",
|
4 |
+
"engines": {
|
5 |
+
"node": "21.x"
|
6 |
+
},
|
7 |
+
"description": "This is a user login and registration app using Node.js, Express, Mongoose and express-sessions. ",
|
8 |
+
"main": "server.js",
|
9 |
+
"dependencies": {
|
10 |
+
"@pusher/push-notifications-server": "^1.0.1",
|
11 |
+
"axios": "^1.2.5",
|
12 |
+
"bcrypt": "^5.0.1",
|
13 |
+
"connect-mongo": "^3.0.0",
|
14 |
+
"crypto": "^1.0.1",
|
15 |
+
"dotenv": "^8.6.0",
|
16 |
+
"cors": "^2.8.5",
|
17 |
+
"ejs": "^3.0.1",
|
18 |
+
"express": "^4.21.2",
|
19 |
+
"express-handlebars": "^6.0.6",
|
20 |
+
"express-session": "^1.16.2",
|
21 |
+
"fcm-node": "^1.3.0",
|
22 |
+
"fcm-push": "^1.1.3",
|
23 |
+
"firebase": "^9.23.0",
|
24 |
+
"firebase-admin": "^11.5.0",
|
25 |
+
"form-data": "^4.0.0",
|
26 |
+
"google-auth-library": "^9.14.0",
|
27 |
+
"jsonwebtoken": "^9.0.0",
|
28 |
+
"mailgun.js": "^7.0.0",
|
29 |
+
"mongodb": "^6.8.0",
|
30 |
+
"mongoose": "^8.9.1",
|
31 |
+
"morgan": "^1.10.0",
|
32 |
+
"multer": "^1.4.5-lts.1",
|
33 |
+
"nodemailer": "^6.7.7",
|
34 |
+
"nodemon": "^2.0.16",
|
35 |
+
"salted-md5": "^4.0.5"
|
36 |
+
},
|
37 |
+
"scripts": {
|
38 |
+
"test": "echo \"Error: no test specified\" && exit 1",
|
39 |
+
"start": "nodemon server.js",
|
40 |
+
"build": "nodemon server.js"
|
41 |
}
|
42 |
+
}
|
push-notification-key.json
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"type": "service_account",
|
3 |
+
"project_id": "flutter-hayat",
|
4 |
+
"private_key_id": "f558d83ec7eb29dd6b0ea474f6d4001cdcc6f6df",
|
5 |
+
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCxivFISQeNWg5t\ndiNYzA2cuNvhbLL3kMmxMk7EIVdxVXrnM9YIzh2PPa82dyKyhJaCr/9DPPrhxRtW\nnHyTwqXxh6ycjxTHazM2Nj8aScUvK382Tl7QIynzcwirQ48iJSQtXeo7sy3fJLTd\nC8lYfGQV2is4l+bOYIDmcMdLzQ43RAiIjj+Xy8QLAW7GBOsJtuMsask7MVAhOph7\nfn/aQK9rWXKRutyKrstBpwkI4aGKfd3y89gxPuk8Fj4H3PyB3FZUF5eb5E11VD0R\n7mU7s7VWWtMja0pDUO8sFq+AmB6hFi3Ua7wS1M1uBl7eEMNDlVlUyBpsa15JODHD\nosq+guahAgMBAAECggEABPvlR5XzPhLV3llHZz39MNXYqFSclooMO2rx3pwgAAi6\nBUUFgGRG3KdK5KDGCtRhhEQsCodq9I0Ltiv47E31yhi4rgFvQCTggGhX76U8AZW7\nQbtD+pxOGG01hFdGbJs1z4c4JNpkEoRNhnoG+jKtvZZNCc7r1gXMAIwQcC6OtFrq\nwyZAFTiUdDartKAe5eevNf8HCb/vchl34rzxEb669Mujju8LRm/3LF393Kxr9Wum\nV+oEVyp6ofieSr8Do5vvg94TD2/2pEvtPuainfnbe99b3UPw1CgF7+16jKumV3RE\nMxSAX2UXgKPre6Gs5JvKE4d1ubGnBIDk0VhZmrWqVQKBgQDwVu6Bo0HDSM3wy8w2\nJXeW/aSCV03TpPZn5nmpapikZHuCx0U6OnMmoUbAYKMTdKzNeBy6xgYFED5P7jEn\nlDD4hY0+jIySyie6gcnYPy4mAqxQeltPvo538dAxPaxFKR43sFmDYFdo6Zifitut\n2DPFcY5XZsD/+zS3cK7ChuNHZQKBgQC9HIGeX1BENIeef0W/oyYPhfQEejVZNMpU\n8OGo36FELcfd+DmzgD2lNNNUFEoENc5QceJ0d1GMerTLBMp+0AUriB5O+E9na9EM\nWEp3Zx0ZXacaPw7IYGSG44cG4qMSnBj88h+WHZrfLhADXKXBpZb8PXV9tFCfVdpi\nUoMwY2sEjQKBgQCkWN3JumjK8GsbQVFIqYBIuPOYybiHhKOW0wzY4/KzX57yA+/7\n7GI3xUsLXEnHkR5ldsA2nBkbt0rU/62PQg/msfSvFA9AhYp7SCtNe47EIUnR0onE\nUys7LBlQwrqdpItsS2Q6qVO8gxiB6MNl8pUcbBWJANPzd8VJt31ZukGK3QKBgQC5\nBoAHbOgCo4ahW5Lpif2+KGh0TQGPUyg3bSrMaGjHZSdtFOWXq3wk/IdbdzJn5iEC\n8joHi4p9ML1c+UYKRwsX6WkGCMrfvExfkK7jHj8JR2ksM9AJ2s3gcBL3eJzmo1WL\nfnXLERIrFE1UjLwcuB/+kT84C0jqbDxsAKEcodjeLQKBgHTBa43VlAH3X9cbyikW\nm+ZEN7o7AGoyQySVMJ1jTIDn1cq/AqnpH4Bl3Lu8U4PYYaBP2aPdFUpEGX9nXUzK\nwLPTIifwd0UHjkQGKpH68lbc4pW1iNcRpJTp5IG5W0XVOWl6MnPD8BSRdA1zfJi7\nxBlMV2UDVJCZIT2ySY03C89l\n-----END PRIVATE KEY-----\n",
|
6 |
+
"client_email": "[email protected]",
|
7 |
+
"client_id": "102750862365764776921",
|
8 |
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
9 |
+
"token_uri": "https://oauth2.googleapis.com/token",
|
10 |
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
11 |
+
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-fr502%40flutter-hayat.iam.gserviceaccount.com"
|
12 |
+
}
|
13 |
+
|
routes/address.js
ADDED
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const express = require("express");
|
2 |
+
const router = express.Router();
|
3 |
+
const mongoose = require("mongoose");
|
4 |
+
const Address = require("../Database/models/address");
|
5 |
+
|
6 |
+
function successResponse(message) {
|
7 |
+
return {
|
8 |
+
"status": 200,
|
9 |
+
"connection": "Connected",
|
10 |
+
"message": message
|
11 |
+
}
|
12 |
+
}
|
13 |
+
|
14 |
+
function failedResponse(message) {
|
15 |
+
return {
|
16 |
+
"status": 400,
|
17 |
+
"connection": "Dissconnected",
|
18 |
+
"message": message
|
19 |
+
}
|
20 |
+
}
|
21 |
+
|
22 |
+
//Post order
|
23 |
+
router.post("/", async (req, res, next) => {
|
24 |
+
|
25 |
+
console.log(req.body);
|
26 |
+
|
27 |
+
const address = new Address(req.body);
|
28 |
+
|
29 |
+
try {
|
30 |
+
const address = await address.save();
|
31 |
+
|
32 |
+
res.status(500).send(successResponse(address));
|
33 |
+
} catch (err) {
|
34 |
+
console.log(err);
|
35 |
+
res.status(500).send(failedResponse(err));
|
36 |
+
}
|
37 |
+
|
38 |
+
});
|
39 |
+
|
40 |
+
router.get("/:user_id", async (req, res, next) => {
|
41 |
+
|
42 |
+
console.log(req.params.user_id);
|
43 |
+
|
44 |
+
try {
|
45 |
+
const orders = await Address.find({ user_id: req.params.user_id });
|
46 |
+
res.status(200).send(successResponse(orders));
|
47 |
+
} catch (err) {
|
48 |
+
res.status(500).send(failedResponse(err));
|
49 |
+
}
|
50 |
+
});
|
51 |
+
|
52 |
+
//UPDATE
|
53 |
+
router.put("/:id", async (req, res) => {
|
54 |
+
console.log(req.params.id);
|
55 |
+
console.log(req.body);
|
56 |
+
|
57 |
+
try {
|
58 |
+
|
59 |
+
Address.updateOne({ _id: req.params.id },
|
60 |
+
{ $set: { status: req.body.status } }, function (err, data) {
|
61 |
+
|
62 |
+
if (err) {
|
63 |
+
return res.status(500).send(failedResponse(err))
|
64 |
+
} else {
|
65 |
+
return res.status(200).send(successResponse(data))
|
66 |
+
}
|
67 |
+
})
|
68 |
+
|
69 |
+
} catch (err) {
|
70 |
+
console.log(err);
|
71 |
+
res.status(500).send(failedResponse(err));
|
72 |
+
}
|
73 |
+
|
74 |
+
|
75 |
+
});
|
76 |
+
|
77 |
+
// //GET ALL
|
78 |
+
router.get("/", async (req, res) => {
|
79 |
+
try {
|
80 |
+
const address = await Address.find();
|
81 |
+
res.status(200).json(successResponse(address));
|
82 |
+
} catch (err) {
|
83 |
+
res.status(500).json(failedResponse(err));
|
84 |
+
}
|
85 |
+
});
|
86 |
+
|
87 |
+
//DELETE
|
88 |
+
router.delete("/:id", (req, res, next) => {
|
89 |
+
Order.remove({ _id: req.params.id })
|
90 |
+
.exec()
|
91 |
+
.then(result => {
|
92 |
+
res.status(200).send(successResponse(result));
|
93 |
+
})
|
94 |
+
.catch(err => {
|
95 |
+
res.status(500).send(failedResponse(err));
|
96 |
+
});
|
97 |
+
});
|
98 |
+
|
99 |
+
module.exports = router;
|
routes/babyItems.js
ADDED
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const express = require("express");
|
2 |
+
const router = express.Router();
|
3 |
+
const mongoose = require("mongoose");
|
4 |
+
const multer = require('multer');
|
5 |
+
const { responseAddProduct, responseFetchProduct } = require("../utils/responseModel");
|
6 |
+
const firebase = require("../utils/firebase");
|
7 |
+
const BabyItems = require("../Database/models/BabyItems");
|
8 |
+
var imageUrl = ""
|
9 |
+
|
10 |
+
//Disk storage where image store
|
11 |
+
const storage = multer.diskStorage({
|
12 |
+
destination: function (req, file, cb) {
|
13 |
+
cb(null, './uploads');
|
14 |
+
},
|
15 |
+
filename: function (req, file, cb) {
|
16 |
+
cb(null, file.originalname);
|
17 |
+
}
|
18 |
+
});
|
19 |
+
|
20 |
+
//Check the image formate
|
21 |
+
const fileFilter = (req, file, cb) => {
|
22 |
+
// reject a file
|
23 |
+
if (file.mimetype === 'image/jpeg' || file.mimetype === 'image/png' || file.mimetype === 'image/jpg' || file.mimetype === 'image/webp') {
|
24 |
+
cb(null, true);
|
25 |
+
} else {
|
26 |
+
cb(null, false);
|
27 |
+
}
|
28 |
+
};
|
29 |
+
|
30 |
+
const upload = multer({
|
31 |
+
storage: storage,
|
32 |
+
limits: {
|
33 |
+
fileSize: 1024 * 1024 * 5
|
34 |
+
},
|
35 |
+
fileFilter: fileFilter
|
36 |
+
});
|
37 |
+
|
38 |
+
//Add products
|
39 |
+
router.post("/", upload.single('file'), async (req, res, next) => {
|
40 |
+
|
41 |
+
await firebase.uploadFile(req.file.path, "BabyItems/" + req.file.filename)
|
42 |
+
await firebase.generateSignedUrl("BabyItems/" + req.file.filename).then(res => {
|
43 |
+
imageUrl = res
|
44 |
+
})
|
45 |
+
|
46 |
+
if (imageUrl == "") {
|
47 |
+
imageUrl = req.file.path
|
48 |
+
}
|
49 |
+
|
50 |
+
console.log(req.body)
|
51 |
+
const babyItems = BabyItems({
|
52 |
+
_id: mongoose.Types.ObjectId(),
|
53 |
+
name: req.body.name,
|
54 |
+
price: req.body.price,
|
55 |
+
description: req.body.description,
|
56 |
+
image: imageUrl,
|
57 |
+
isLiked: req.body.isLiked,
|
58 |
+
|
59 |
+
});
|
60 |
+
babyItems
|
61 |
+
.save()
|
62 |
+
.then(result => {
|
63 |
+
console.log(result);
|
64 |
+
res.status(200).send(
|
65 |
+
responseAddProduct(true, result));
|
66 |
+
})
|
67 |
+
.catch(err => {
|
68 |
+
console.log(err.message);
|
69 |
+
res.status(500).send(responseAddProduct(false, err));
|
70 |
+
});
|
71 |
+
});
|
72 |
+
|
73 |
+
|
74 |
+
//Get products
|
75 |
+
router.get("/", (req, res, next) => {
|
76 |
+
BabyItems.find()
|
77 |
+
.exec()
|
78 |
+
.then(result => {
|
79 |
+
res.status(200).send(responseFetchProduct(true, result));
|
80 |
+
})
|
81 |
+
.catch(err => {
|
82 |
+
console.log(err);
|
83 |
+
res.status(500).send(responseFetchProduct(false, err));
|
84 |
+
});
|
85 |
+
});
|
86 |
+
|
87 |
+
//Update products
|
88 |
+
router.put('/:id', upload.single('fruitImage'), async (req, res) => {
|
89 |
+
const id = req.params.id;
|
90 |
+
console.log(req.body);
|
91 |
+
const updateOps = {};
|
92 |
+
for (const ops of Object.keys(req.body)) {
|
93 |
+
updateOps[ops] = req.body[ops];
|
94 |
+
}
|
95 |
+
|
96 |
+
console.log(updateOps);
|
97 |
+
BabyItems.updateOne({ _id: id }, { $set: updateOps })
|
98 |
+
.exec()
|
99 |
+
.then(result => {
|
100 |
+
res.status(200).json({
|
101 |
+
message: 'Product updated',
|
102 |
+
request: {
|
103 |
+
type: 'GET',
|
104 |
+
url: 'http://localhost:4000/products/' + id
|
105 |
+
}
|
106 |
+
});
|
107 |
+
})
|
108 |
+
.catch(err => {
|
109 |
+
console.log(err);
|
110 |
+
res.status(500).json({
|
111 |
+
error: err
|
112 |
+
});
|
113 |
+
});
|
114 |
+
});
|
115 |
+
|
116 |
+
//Delete products
|
117 |
+
router.delete("/:id", (req, res) => {
|
118 |
+
const id = req.params.id;
|
119 |
+
BabyItems.deleteOne({ _id: id })
|
120 |
+
.exec()
|
121 |
+
.then(result => {
|
122 |
+
res.status(200).json({
|
123 |
+
message: 'Fruit item deleted',
|
124 |
+
request: {
|
125 |
+
type: 'POST',
|
126 |
+
url: 'http://localhost:3000/products',
|
127 |
+
body: { name: 'String', price: 'Number' }
|
128 |
+
}
|
129 |
+
});
|
130 |
+
})
|
131 |
+
.catch(err => {
|
132 |
+
console.log(err);
|
133 |
+
res.status(500).json({
|
134 |
+
error: err
|
135 |
+
});
|
136 |
+
});
|
137 |
+
});
|
138 |
+
|
139 |
+
|
140 |
+
|
141 |
+
|
142 |
+
module.exports = router;
|
routes/banner.js
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const express = require("express");
|
2 |
+
const router = express.Router();
|
3 |
+
var Banner = require('../Database/models/banner');
|
4 |
+
const mongoose = require("mongoose");
|
5 |
+
const multer = require('multer');
|
6 |
+
const firebase = require("../utils/firebase")
|
7 |
+
var imageUrl = ""
|
8 |
+
|
9 |
+
//Disk storage where image store
|
10 |
+
const storage = multer.diskStorage({
|
11 |
+
destination: function (req, file, cb) {
|
12 |
+
cb(null, './uploads');
|
13 |
+
},
|
14 |
+
filename: function (req, file, cb) {
|
15 |
+
cb(null, file.originalname);
|
16 |
+
}
|
17 |
+
});
|
18 |
+
|
19 |
+
//Check the image formate
|
20 |
+
const fileFilter = (req, file, cb) => {
|
21 |
+
// reject a file
|
22 |
+
if (file.mimetype === 'image/jpeg' || file.mimetype === 'image/png' || file.mimetype === 'image/jpg') {
|
23 |
+
cb(null, true);
|
24 |
+
} else {
|
25 |
+
cb(null, false);
|
26 |
+
}
|
27 |
+
};
|
28 |
+
|
29 |
+
const upload = multer({
|
30 |
+
storage: storage,
|
31 |
+
limits: {
|
32 |
+
fileSize: 1024 * 1024 * 5
|
33 |
+
},
|
34 |
+
fileFilter: fileFilter
|
35 |
+
});
|
36 |
+
|
37 |
+
router.post("/", upload.any(), async (req, res) => {
|
38 |
+
console.log(req.body); // Log non-file data
|
39 |
+
const uploadedFiles = req.files; // Uploaded files
|
40 |
+
let bannerImage = ""
|
41 |
+
|
42 |
+
let bannerImageName = uploadedFiles.find(
|
43 |
+
(f) => f.fieldname.includes('banner')
|
44 |
+
);
|
45 |
+
|
46 |
+
if (bannerImageName != "" && bannerImageName != undefined) {
|
47 |
+
|
48 |
+
let bannerImagePath = uploadedFiles.find(
|
49 |
+
(f) => f.path.includes('banner')
|
50 |
+
);
|
51 |
+
await firebase.uploadFile(bannerImagePath, "bannerImage/" + bannerImageName);
|
52 |
+
|
53 |
+
// Generating signed URL for the uploaded image
|
54 |
+
await firebase.generateSignedUrl("bannerImage/" + bannerImageName)
|
55 |
+
.then((url) => {
|
56 |
+
imageUrl = url;
|
57 |
+
})
|
58 |
+
.catch((err) => {
|
59 |
+
console.error(`Error generating signed URL for ${fileName.filename}:`, err);
|
60 |
+
return res.status(500).json({ error: 'Error generating image URL.' });
|
61 |
+
});
|
62 |
+
}
|
63 |
+
|
64 |
+
try {
|
65 |
+
const { name, percentage, products } = req.body; // Non-file data
|
66 |
+
|
67 |
+
const bannerProducts = [];
|
68 |
+
let imageUrl = ''; // Declare imageUrl variable
|
69 |
+
|
70 |
+
for (let i = 0; i < products.length; i++) {
|
71 |
+
const product = products[i]; // Directly use product if it's already an object
|
72 |
+
const fileName = uploadedFiles.find(
|
73 |
+
(f) => f.fieldname === `products[${i}][image]`
|
74 |
+
);
|
75 |
+
|
76 |
+
// If no file is found for the product, skip
|
77 |
+
if (!fileName) {
|
78 |
+
console.log(`No image found for product ${i}`);
|
79 |
+
continue;
|
80 |
+
}
|
81 |
+
|
82 |
+
const filePath = fileName.path;
|
83 |
+
|
84 |
+
// Upload file and generate the signed URL
|
85 |
+
await firebase.uploadFile(filePath, "bannerProducts/" + fileName.filename);
|
86 |
+
|
87 |
+
// Generating signed URL for the uploaded image
|
88 |
+
await firebase.generateSignedUrl("bannerProducts/" + fileName.filename)
|
89 |
+
.then((url) => {
|
90 |
+
imageUrl = url;
|
91 |
+
})
|
92 |
+
.catch((err) => {
|
93 |
+
console.error(`Error generating signed URL for ${fileName.filename}:`, err);
|
94 |
+
return res.status(500).json({ error: 'Error generating image URL.' });
|
95 |
+
});
|
96 |
+
|
97 |
+
bannerProducts.push({
|
98 |
+
_id: new mongoose.Types.ObjectId(),
|
99 |
+
name: product.name,
|
100 |
+
image: imageUrl,
|
101 |
+
price: product.price,
|
102 |
+
});
|
103 |
+
}
|
104 |
+
|
105 |
+
const banner = new Banner({
|
106 |
+
_id: new mongoose.Types.ObjectId(),
|
107 |
+
name,
|
108 |
+
percentage,
|
109 |
+
bannerImage,
|
110 |
+
products: bannerProducts,
|
111 |
+
});
|
112 |
+
|
113 |
+
const savedBanner = await banner.save();
|
114 |
+
res.status(201).json({ message: 'Banner created successfully', savedBanner });
|
115 |
+
} catch (error) {
|
116 |
+
console.error('Error in creating banner:', error);
|
117 |
+
res.status(500).json({ error: error.message });
|
118 |
+
}
|
119 |
+
});
|
120 |
+
|
121 |
+
router.get("/", function (req, res) {
|
122 |
+
Banner.find()
|
123 |
+
.exec()
|
124 |
+
.then((data) => {
|
125 |
+
console.log(data)
|
126 |
+
try {
|
127 |
+
const response = {
|
128 |
+
count: data.length,
|
129 |
+
products: data
|
130 |
+
};
|
131 |
+
res.status(200).json(response);
|
132 |
+
} catch (e) {
|
133 |
+
res.status(400).json({
|
134 |
+
error: e
|
135 |
+
});
|
136 |
+
}
|
137 |
+
|
138 |
+
})
|
139 |
+
.catch((error) => {
|
140 |
+
res.status(400).json({
|
141 |
+
error: error
|
142 |
+
});
|
143 |
+
})
|
144 |
+
});
|
145 |
+
|
146 |
+
module.exports = router;
|
147 |
+
|
148 |
+
|
routes/category.js
ADDED
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const Category = require("../Database/models/category");
|
2 |
+
const express = require("express");
|
3 |
+
const { responseAddProduct, responseFetchProduct } = require("../utils/responseModel");
|
4 |
+
const router = express.Router();
|
5 |
+
const firebase = require("../utils/firebase");
|
6 |
+
const { filePath } = require("../utils/upladImageUtils");
|
7 |
+
const multer = require('multer');
|
8 |
+
var imageUrl = ""
|
9 |
+
|
10 |
+
|
11 |
+
//Disk storage where image store
|
12 |
+
const storage = multer.diskStorage({
|
13 |
+
destination: function (req, file, cb) {
|
14 |
+
cb(null, './uploads');
|
15 |
+
},
|
16 |
+
filename: function (req, file, cb) {
|
17 |
+
cb(null, file.originalname);
|
18 |
+
}
|
19 |
+
});
|
20 |
+
|
21 |
+
//Check the image formate
|
22 |
+
const fileFilter = (req, file, cb) => {
|
23 |
+
// reject a file
|
24 |
+
if (file.mimetype === 'image/jpeg' || file.mimetype === 'image/png' || file.mimetype === 'image/jpg') {
|
25 |
+
cb(null, true);
|
26 |
+
} else {
|
27 |
+
cb(null, false);
|
28 |
+
}
|
29 |
+
};
|
30 |
+
|
31 |
+
const upload = multer({
|
32 |
+
storage: storage,
|
33 |
+
limits: {
|
34 |
+
fileSize: 1024 * 1024 * 5
|
35 |
+
},
|
36 |
+
fileFilter: fileFilter
|
37 |
+
});
|
38 |
+
|
39 |
+
router.get("/", async (req, res) => {
|
40 |
+
const categoryList = await Category.find();
|
41 |
+
|
42 |
+
if (!categoryList) {
|
43 |
+
res.status(500).json({ success: false });
|
44 |
+
}
|
45 |
+
res.status(200).send(
|
46 |
+
categoryList);
|
47 |
+
});
|
48 |
+
|
49 |
+
|
50 |
+
//GetCategory
|
51 |
+
router.get("/:id", async (req, res) => {
|
52 |
+
const category = await Category.findById(req.params.id);
|
53 |
+
|
54 |
+
if (!category) {
|
55 |
+
res
|
56 |
+
.status(500)
|
57 |
+
.json({ message: "the category with the given ID not found" });
|
58 |
+
}
|
59 |
+
res.status(200).send(category);
|
60 |
+
});
|
61 |
+
|
62 |
+
|
63 |
+
//Add
|
64 |
+
router.post("/", upload.single('file'), async (req, res) => {
|
65 |
+
|
66 |
+
await firebase.uploadFile(req.file.path, "hijab/" + req.file.filename)
|
67 |
+
await firebase.generateSignedUrl("hijab/" + req.file.filename).then(res => {
|
68 |
+
imageUrl = res
|
69 |
+
})
|
70 |
+
|
71 |
+
if (imageUrl == "") {
|
72 |
+
imageUrl = req.file.path
|
73 |
+
}
|
74 |
+
|
75 |
+
console.log(req.body);
|
76 |
+
let category = new Category({
|
77 |
+
name: req.body.name,
|
78 |
+
description: req.body.description,
|
79 |
+
image: imageUrl,
|
80 |
+
link: req.body.link,
|
81 |
+
});
|
82 |
+
category.save()
|
83 |
+
.then(result => {
|
84 |
+
res.status(200).send(responseFetchProduct(true, result))
|
85 |
+
}).catch(error => {
|
86 |
+
res.status(400).send(responseAddProduct(false,));
|
87 |
+
})
|
88 |
+
});
|
89 |
+
|
90 |
+
|
91 |
+
//Upadte
|
92 |
+
router.put("/:id", async (req, res) => {
|
93 |
+
const category = await Category.findByIdAndUpdate(
|
94 |
+
req.params.id,
|
95 |
+
{
|
96 |
+
name: req.body.name,
|
97 |
+
icon: req.body.icon,
|
98 |
+
color: req.body.color,
|
99 |
+
},
|
100 |
+
{ new: true }
|
101 |
+
);
|
102 |
+
|
103 |
+
if (!category) return res.status(400).send("the category cannot be created");
|
104 |
+
|
105 |
+
res.send(category);
|
106 |
+
});
|
107 |
+
|
108 |
+
|
109 |
+
//delete
|
110 |
+
router.delete("/:id", (req, res) => {
|
111 |
+
Category.findByIdAndRemove(req.params.id)
|
112 |
+
.then((category) => {
|
113 |
+
if (category) {
|
114 |
+
return res
|
115 |
+
.status(200)
|
116 |
+
.json({ success: true, message: "the category deleted" });
|
117 |
+
} else {
|
118 |
+
return res
|
119 |
+
.status(404)
|
120 |
+
.json({ success: false, message: "categry not found" });
|
121 |
+
}
|
122 |
+
})
|
123 |
+
.catch((err) => {
|
124 |
+
return res.status(400).json({ success: false, error: err });
|
125 |
+
});
|
126 |
+
});
|
127 |
+
|
128 |
+
module.exports = router;
|
routes/changePassword.js
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
var express = require('express');
|
2 |
+
var router = express.Router();
|
3 |
+
var app = express();
|
4 |
+
var User = require('../Database/models/user');
|
5 |
+
const bcrypt = require("bcrypt");
|
6 |
+
const { successResponse, failedResponse } = require('../utils/responseModel');
|
7 |
+
|
8 |
+
router.post('/', async function (req, res, next) {
|
9 |
+
|
10 |
+
var newPassword = req.body.newPassword;
|
11 |
+
var cnfrmNewPassword = req.body.cnfrmNewPassword;
|
12 |
+
|
13 |
+
// generate salt to hash password
|
14 |
+
const salt = await bcrypt.genSalt(10);
|
15 |
+
// now we set user password to hashed password
|
16 |
+
const password = await bcrypt.hash(newPassword, salt);
|
17 |
+
|
18 |
+
const updateOps = {
|
19 |
+
password: password,
|
20 |
+
passwordConf: cnfrmNewPassword
|
21 |
+
};
|
22 |
+
console.log(updateOps);
|
23 |
+
try {
|
24 |
+
const { email } = req.body;
|
25 |
+
// Find the user by email
|
26 |
+
const user = await User.findOne({ email: email }).exec();
|
27 |
+
|
28 |
+
if (user) {
|
29 |
+
// Update the user's password
|
30 |
+
await User.updateOne({ email: user.email }, { $set: updateOps }).exec();
|
31 |
+
res.status(200).send(successResponse("Password changed successfully!"));
|
32 |
+
} else {
|
33 |
+
res.status(201).send(failedResponse("Email not registered!", 400));
|
34 |
+
}
|
35 |
+
} catch (err) {
|
36 |
+
console.error(err);
|
37 |
+
res.status(500).send(failedResponse(err.message, 500));
|
38 |
+
}
|
39 |
+
|
40 |
+
// }
|
41 |
+
// else {
|
42 |
+
// res.send(failedResponse("Password not matched"));
|
43 |
+
// }
|
44 |
+
|
45 |
+
});
|
46 |
+
|
47 |
+
|
48 |
+
module.exports = router;
|
routes/cmd.js
ADDED
@@ -0,0 +1,173 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const express = require("express");
|
2 |
+
const router = express.Router();
|
3 |
+
const mongoose = require("mongoose");
|
4 |
+
const multer = require('multer');
|
5 |
+
const User = require('../Database/models/user');
|
6 |
+
const Post = require('../Database/models/newPost');
|
7 |
+
const Comment = require('../Database/models/comments');
|
8 |
+
const response = require('../utils/responseModel');
|
9 |
+
|
10 |
+
|
11 |
+
|
12 |
+
//Disk storage where image store
|
13 |
+
const storage = multer.diskStorage({
|
14 |
+
destination: function (req, file, cb) {
|
15 |
+
cb(null, './uploads/fruits');
|
16 |
+
},
|
17 |
+
filename: function (req, file, cb) {
|
18 |
+
cb(null, file.originalname);
|
19 |
+
}
|
20 |
+
});
|
21 |
+
|
22 |
+
//Check the image formate
|
23 |
+
const fileFilter = (req, file, cb) => {
|
24 |
+
// reject a file
|
25 |
+
if (file.mimetype === 'image/jpeg' || file.mimetype === 'image/png' || file.mimetype === 'image/jpg') {
|
26 |
+
cb(null, true);
|
27 |
+
} else {
|
28 |
+
cb(null, false);
|
29 |
+
}
|
30 |
+
};
|
31 |
+
|
32 |
+
const upload = multer({
|
33 |
+
storage: storage,
|
34 |
+
limits: {
|
35 |
+
fileSize: 1024 * 1024 * 10
|
36 |
+
},
|
37 |
+
fileFilter: fileFilter
|
38 |
+
});
|
39 |
+
|
40 |
+
router.post('/create', upload.single('file'), async (req, res, next) => {
|
41 |
+
console.log(req.body);
|
42 |
+
const userData = await User.findOne({ unique_id: req.body.userId }).exec();
|
43 |
+
if (!userData) {
|
44 |
+
res.send(response.failedResponse('Data not found!'))
|
45 |
+
} else {
|
46 |
+
console.log(" Data => " + userData)
|
47 |
+
|
48 |
+
Post.findOne({ _id: req.body.postId }, function (err, postData) {
|
49 |
+
if (!postData) {
|
50 |
+
res.status(500).json({ error: 'Post not found!' });
|
51 |
+
} else {
|
52 |
+
var comment = Comment({
|
53 |
+
user: userData,
|
54 |
+
post: postData,
|
55 |
+
userId: req.body.userId,
|
56 |
+
comment: req.body.comment,
|
57 |
+
likes: userData
|
58 |
+
})
|
59 |
+
|
60 |
+
comment.save()
|
61 |
+
.then((post) => {
|
62 |
+
res.status(200).json(post);
|
63 |
+
})
|
64 |
+
.catch((error) => {
|
65 |
+
res.status(500).json({ error: 'An error occurred while creating the post.' });
|
66 |
+
});
|
67 |
+
|
68 |
+
}
|
69 |
+
|
70 |
+
});
|
71 |
+
}
|
72 |
+
});
|
73 |
+
|
74 |
+
router.get('/:id', async (req, res, next) => {
|
75 |
+
const postData = await Post.findOne({ _id: req.params.id }).exec();
|
76 |
+
if (!postData) {
|
77 |
+
res.status(500).json({ error: 'Post not found!' });
|
78 |
+
} else {
|
79 |
+
const comments = await Comment.find({ post: postData })
|
80 |
+
.sort({ createdAt: 'descending' });
|
81 |
+
if (!comments) {
|
82 |
+
res.status(500).json({ error: 'Comments not found!' });
|
83 |
+
} else {
|
84 |
+
res.status(200).json({
|
85 |
+
status: 'success',
|
86 |
+
count: comments.length,
|
87 |
+
comments,
|
88 |
+
});
|
89 |
+
}
|
90 |
+
}
|
91 |
+
});
|
92 |
+
|
93 |
+
router.get('/byId', async (req, res, next) => {
|
94 |
+
const post = await Post.findById(req.params.id).populate({
|
95 |
+
path: 'profile',
|
96 |
+
select: '-bio -website -user -_v',
|
97 |
+
});
|
98 |
+
|
99 |
+
if (!post) {
|
100 |
+
return next(new AppError('Post not found', 400));
|
101 |
+
}
|
102 |
+
|
103 |
+
res.status(200).json({
|
104 |
+
status: 'success',
|
105 |
+
post,
|
106 |
+
});
|
107 |
+
});
|
108 |
+
|
109 |
+
router.delete('/', async (req, res, next) => {
|
110 |
+
//const post = await Post.deleteOne({ _id: req.params.id });
|
111 |
+
const post = await Post.findById(req.params.id);
|
112 |
+
if (!post) {
|
113 |
+
return next(new AppError('Post not found', 400));
|
114 |
+
}
|
115 |
+
// console.log(post, post.user.toString() === req.user.id)
|
116 |
+
if (post.user.toString() !== req.user.id) {
|
117 |
+
return next(
|
118 |
+
new AppError('You are not authorized to delete this post', 401)
|
119 |
+
);
|
120 |
+
}
|
121 |
+
|
122 |
+
post.commentsPost.length &&
|
123 |
+
(await Comment.findByIdAndDelete(post.commentsPost[0]._id));
|
124 |
+
|
125 |
+
await post.remove();
|
126 |
+
|
127 |
+
res.status(200).json({
|
128 |
+
message: 'deleted',
|
129 |
+
});
|
130 |
+
});
|
131 |
+
|
132 |
+
router.post('/like', async (req, res, next) => {
|
133 |
+
const post = await Post.findById(req.params.id).populate('profile');
|
134 |
+
|
135 |
+
if (!post) {
|
136 |
+
return next(new AppError('Post not found', 400));
|
137 |
+
}
|
138 |
+
const id = await post.getProfileId(req.user.id);
|
139 |
+
|
140 |
+
if (post.likes.includes(id)) {
|
141 |
+
const index = post.likes.indexOf(id);
|
142 |
+
post.likes.splice(index, 1);
|
143 |
+
await post.save((err) => {
|
144 |
+
console.log(err);
|
145 |
+
});
|
146 |
+
await Notification.deleteMany({
|
147 |
+
to: post.profile._id,
|
148 |
+
user: id,
|
149 |
+
type: 'Like',
|
150 |
+
});
|
151 |
+
} else {
|
152 |
+
post.likes.push(id);
|
153 |
+
await post.save();
|
154 |
+
}
|
155 |
+
|
156 |
+
res.status(200).json({
|
157 |
+
status: 'success',
|
158 |
+
post,
|
159 |
+
});
|
160 |
+
});
|
161 |
+
|
162 |
+
router.delete('/:id', async (req, res) => {
|
163 |
+
Comment.remove({ _id: req.params.id })
|
164 |
+
.exec()
|
165 |
+
.then(result => {
|
166 |
+
res.status(200).send(response.successResponse(result));
|
167 |
+
})
|
168 |
+
.catch(error => {
|
169 |
+
res.send(500).send(response.failedResponse(error))
|
170 |
+
});
|
171 |
+
});
|
172 |
+
|
173 |
+
module.exports = router;
|
routes/comment.js
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const express = require("express");
|
2 |
+
const router = express.Router();
|
3 |
+
const User = require('../models/user');
|
4 |
+
const Post = require('../models/postNews');
|
5 |
+
const Comment = require('../models/comments');
|
6 |
+
const response = require('../utils/responseModel');
|
7 |
+
|
8 |
+
|
9 |
+
router.post('/', async (req, res) => {
|
10 |
+
console.log(req.body)
|
11 |
+
User.findOne({ unique_id: req.body.userId }, function (err, data) {
|
12 |
+
if (!data) {
|
13 |
+
res.send(failedResponse('Data not found!'))
|
14 |
+
} else {
|
15 |
+
console.log(" Data => " + data)
|
16 |
+
Post.findOne({ postId: req.body.postId }, function (err, postData) {
|
17 |
+
if (!postData) {
|
18 |
+
res.send(failedResponse('Data not found!: ' + err))
|
19 |
+
} else {
|
20 |
+
var comment = Comment({
|
21 |
+
user: data,
|
22 |
+
post: postData,
|
23 |
+
userId: req.body.userId,
|
24 |
+
text: req.body.comment
|
25 |
+
})
|
26 |
+
|
27 |
+
comment.save()
|
28 |
+
.then((post) => {
|
29 |
+
res.status(200).json(post);
|
30 |
+
})
|
31 |
+
.catch((error) => {
|
32 |
+
res.status(500).json({ error: 'An error occurred while creating the post.' });
|
33 |
+
});
|
34 |
+
|
35 |
+
}
|
36 |
+
|
37 |
+
})
|
38 |
+
}
|
39 |
+
});
|
40 |
+
|
41 |
+
});
|
42 |
+
|
43 |
+
|
44 |
+
router.delete('/:id', async (req, res) => {
|
45 |
+
|
46 |
+
Comment.remove({ _id: req.params.id })
|
47 |
+
.exec()
|
48 |
+
.then(result => {
|
49 |
+
res.status(200).send(response.successResponse(result));
|
50 |
+
})
|
51 |
+
.catch(error => {
|
52 |
+
res.send(500).send(response.failedResponse(error))
|
53 |
+
});
|
54 |
+
|
55 |
+
});
|
56 |
+
|
57 |
+
module.exports = router;
|
routes/confirmOrder.js
ADDED
File without changes
|
routes/dairy.js
ADDED
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const express = require("express");
|
2 |
+
const router = express.Router();
|
3 |
+
const mongoose = require("mongoose");
|
4 |
+
const multer = require('multer');
|
5 |
+
const Dairy = require("../Database/models/dairy");
|
6 |
+
const { responseAddProduct, responseFetchProduct } = require("../utils/responseModel");
|
7 |
+
const firebase = require("../utils/firebase")
|
8 |
+
var imageUrl = ""
|
9 |
+
|
10 |
+
//Disk storage where image store
|
11 |
+
const storage = multer.diskStorage({
|
12 |
+
destination: function (req, file, cb) {
|
13 |
+
cb(null, './uploads/dairy');
|
14 |
+
},
|
15 |
+
filename: function (req, file, cb) {
|
16 |
+
cb(null, file.originalname);
|
17 |
+
}
|
18 |
+
});
|
19 |
+
|
20 |
+
//Check the image formate
|
21 |
+
const fileFilter = (req, file, cb) => {
|
22 |
+
// reject a file
|
23 |
+
if (file.mimetype === 'image/jpeg' || file.mimetype === 'image/png' || file.mimetype === 'image/jpg') {
|
24 |
+
cb(null, true);
|
25 |
+
} else {
|
26 |
+
cb(null, false);
|
27 |
+
}
|
28 |
+
};
|
29 |
+
|
30 |
+
const upload = multer({
|
31 |
+
storage: storage,
|
32 |
+
limits: {
|
33 |
+
fileSize: 1024 * 1024 * 5
|
34 |
+
},
|
35 |
+
fileFilter: fileFilter
|
36 |
+
});
|
37 |
+
|
38 |
+
//Add products
|
39 |
+
router.post("/", upload.single('file'), async (req, res, next) => {
|
40 |
+
|
41 |
+
await firebase.uploadFile(req.file.path, "Dairy/" + req.file.filename)
|
42 |
+
await firebase.generateSignedUrl("Dairy/" + req.file.filename).then(res => {
|
43 |
+
imageUrl = res
|
44 |
+
})
|
45 |
+
|
46 |
+
if (imageUrl == "") {
|
47 |
+
imageUrl = req.file.path
|
48 |
+
}
|
49 |
+
|
50 |
+
const dairy = Dairy({
|
51 |
+
_id: mongoose.Types.ObjectId(),
|
52 |
+
name: req.body.name,
|
53 |
+
price: req.body.price,
|
54 |
+
description: req.body.description,
|
55 |
+
image: imageUrl,
|
56 |
+
isLiked: req.body.isLiked,
|
57 |
+
|
58 |
+
});
|
59 |
+
dairy
|
60 |
+
.save()
|
61 |
+
.then(result => {
|
62 |
+
console.log(result);
|
63 |
+
res.status(200).send(
|
64 |
+
responseAddProduct(true, result));
|
65 |
+
})
|
66 |
+
.catch(err => {
|
67 |
+
console.log(err.message);
|
68 |
+
res.status(500).send(responseAddProduct(false, err));
|
69 |
+
});
|
70 |
+
});
|
71 |
+
|
72 |
+
|
73 |
+
//Get products
|
74 |
+
router.get("/", (req, res, next) => {
|
75 |
+
Dairy.find()
|
76 |
+
.exec()
|
77 |
+
.then(result => {
|
78 |
+
res.status(200).send(responseFetchProduct(true, result));
|
79 |
+
})
|
80 |
+
.catch(err => {
|
81 |
+
console.log(err);
|
82 |
+
res.status(500).send(responseFetchProduct(false, err));
|
83 |
+
});
|
84 |
+
});
|
85 |
+
|
86 |
+
//Update products
|
87 |
+
router.put('/:id', upload.single('dairyImage'), async (req, res) => {
|
88 |
+
const id = req.params.id;
|
89 |
+
console.log(req.body);
|
90 |
+
const updateOps = {};
|
91 |
+
for (const ops of Object.keys(req.body)) {
|
92 |
+
updateOps[ops] = req.body[ops];
|
93 |
+
}
|
94 |
+
console.log(updateOps);
|
95 |
+
Dairy.updateOne({ _id: id }, { $set: updateOps })
|
96 |
+
.exec()
|
97 |
+
.then(result => {
|
98 |
+
res.status(200).send(
|
99 |
+
responseAddProduct(true, result));
|
100 |
+
})
|
101 |
+
.catch(err => {
|
102 |
+
console.log(err);
|
103 |
+
res.status(500).send(responseFetchProduct(false, err));
|
104 |
+
});
|
105 |
+
});
|
106 |
+
|
107 |
+
//Delete products
|
108 |
+
router.delete("/:id", (req, res) => {
|
109 |
+
const id = req.params.id;
|
110 |
+
Dairy.deleteOne({ _id: id })
|
111 |
+
.exec()
|
112 |
+
.then(result => {
|
113 |
+
res.status(200).send(
|
114 |
+
responseAddProduct(true, result));
|
115 |
+
})
|
116 |
+
.catch(err => {
|
117 |
+
res.status(500).send(responseFetchProduct(false, err));
|
118 |
+
console.log(err);
|
119 |
+
});
|
120 |
+
});
|
121 |
+
|
122 |
+
|
123 |
+
|
124 |
+
|
125 |
+
module.exports = router;
|
routes/driedNoodles.js
ADDED
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const express = require("express");
|
2 |
+
const router = express.Router();
|
3 |
+
const mongoose = require("mongoose");
|
4 |
+
const multer = require('multer');
|
5 |
+
const DriedNoodles = require("../Database/models/DriedNoodles")
|
6 |
+
const { responseAddProduct, responseFetchProduct } = require("../utils/responseModel");
|
7 |
+
|
8 |
+
const firebase = require("../utils/firebase")
|
9 |
+
var imageUrl = ""
|
10 |
+
|
11 |
+
//Disk storage where image store
|
12 |
+
const storage = multer.diskStorage({
|
13 |
+
destination: function (req, file, cb) {
|
14 |
+
cb(null, './uploads');
|
15 |
+
},
|
16 |
+
filename: function (req, file, cb) {
|
17 |
+
cb(null, file.originalname);
|
18 |
+
}
|
19 |
+
});
|
20 |
+
|
21 |
+
//Check the image formate
|
22 |
+
const fileFilter = (req, file, cb) => {
|
23 |
+
// reject a file
|
24 |
+
if (file.mimetype === 'image/jpeg' || file.mimetype === 'image/png' || file.mimetype === 'image/jpg' || file.mimetype === 'image/webp') {
|
25 |
+
cb(null, true);
|
26 |
+
} else {
|
27 |
+
cb(null, false);
|
28 |
+
}
|
29 |
+
};
|
30 |
+
|
31 |
+
const upload = multer({
|
32 |
+
storage: storage,
|
33 |
+
limits: {
|
34 |
+
fileSize: 1024 * 1024 * 5
|
35 |
+
},
|
36 |
+
fileFilter: fileFilter
|
37 |
+
});
|
38 |
+
|
39 |
+
//Add products
|
40 |
+
router.post("/", upload.single('file'), async (req, res, next) => {
|
41 |
+
|
42 |
+
await firebase.uploadFile(req.file.path, "DriedNoodles/" + req.file.filename)
|
43 |
+
await firebase.generateSignedUrl("DriedNoodles/" + req.file.filename).then(res => {
|
44 |
+
imageUrl = res
|
45 |
+
})
|
46 |
+
|
47 |
+
if (imageUrl == "") {
|
48 |
+
imageUrl = req.file.path
|
49 |
+
}
|
50 |
+
|
51 |
+
console.log(req.body)
|
52 |
+
const fruites = DriedNoodles({
|
53 |
+
_id: mongoose.Types.ObjectId(),
|
54 |
+
name: req.body.name,
|
55 |
+
price: req.body.price,
|
56 |
+
description: req.body.description,
|
57 |
+
image: imageUrl,
|
58 |
+
isLiked: req.body.isLiked,
|
59 |
+
|
60 |
+
});
|
61 |
+
fruites
|
62 |
+
.save()
|
63 |
+
.then(result => {
|
64 |
+
console.log(result);
|
65 |
+
res.status(200).send(
|
66 |
+
responseAddProduct(true, result));
|
67 |
+
})
|
68 |
+
.catch(err => {
|
69 |
+
console.log(err.message);
|
70 |
+
res.status(500).send(responseAddProduct(false, err));
|
71 |
+
});
|
72 |
+
});
|
73 |
+
|
74 |
+
|
75 |
+
//Get products
|
76 |
+
router.get("/", (req, res, next) => {
|
77 |
+
DriedNoodles.find()
|
78 |
+
.exec()
|
79 |
+
.then(result => {
|
80 |
+
res.status(200).send(responseFetchProduct(true, result));
|
81 |
+
})
|
82 |
+
.catch(err => {
|
83 |
+
console.log(err);
|
84 |
+
res.status(500).send(responseFetchProduct(false, err));
|
85 |
+
});
|
86 |
+
});
|
87 |
+
|
88 |
+
//Update products
|
89 |
+
router.put('/:id', upload.single('fruitImage'), async (req, res) => {
|
90 |
+
const id = req.params.id;
|
91 |
+
console.log(req.body);
|
92 |
+
const updateOps = {};
|
93 |
+
for (const ops of Object.keys(req.body)) {
|
94 |
+
updateOps[ops] = req.body[ops];
|
95 |
+
}
|
96 |
+
|
97 |
+
console.log(updateOps);
|
98 |
+
DriedNoodles.updateOne({ _id: id }, { $set: updateOps })
|
99 |
+
.exec()
|
100 |
+
.then(result => {
|
101 |
+
res.status(200).send(
|
102 |
+
responseFetchProduct(true, result));
|
103 |
+
})
|
104 |
+
.catch(err => {
|
105 |
+
console.log(err);
|
106 |
+
res.status(500).send(responseFetchProduct(false, err));
|
107 |
+
});
|
108 |
+
});
|
109 |
+
|
110 |
+
//Delete products
|
111 |
+
router.delete("/:id", (req, res) => {
|
112 |
+
const id = req.params.id;
|
113 |
+
DriedNoodles.deleteOne({ _id: id })
|
114 |
+
.exec()
|
115 |
+
.then(result => {
|
116 |
+
res.status(200).send(
|
117 |
+
responseFetchProduct(true, result));
|
118 |
+
})
|
119 |
+
.catch(err => {
|
120 |
+
console.log(err);
|
121 |
+
res.status(500).send(responseFetchProduct(false, err));
|
122 |
+
});
|
123 |
+
});
|
124 |
+
|
125 |
+
|
126 |
+
|
127 |
+
|
128 |
+
module.exports = router;
|
routes/drinks.js
ADDED
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const express = require("express");
|
2 |
+
const router = express.Router();
|
3 |
+
const mongoose = require("mongoose");
|
4 |
+
const multer = require('multer');
|
5 |
+
const Drinks = require("../Database/models/drinks");
|
6 |
+
const { responseAddProduct, responseFetchProduct } = require("../utils/responseModel");
|
7 |
+
const firebase = require("../utils/firebase")
|
8 |
+
var imageUrl = ""
|
9 |
+
|
10 |
+
//Disk storage where image store
|
11 |
+
const storage = multer.diskStorage({
|
12 |
+
destination: function (req, file, cb) {
|
13 |
+
cb(null, './uploads/drinks');
|
14 |
+
},
|
15 |
+
filename: function (req, file, cb) {
|
16 |
+
cb(null, file.originalname);
|
17 |
+
}
|
18 |
+
});
|
19 |
+
|
20 |
+
//Check the image formate
|
21 |
+
const fileFilter = (req, file, cb) => {
|
22 |
+
// reject a file
|
23 |
+
if (file.mimetype === 'image/jpeg' || file.mimetype === 'image/png' || file.mimetype === 'image/jpg') {
|
24 |
+
cb(null, true);
|
25 |
+
} else {
|
26 |
+
cb(null, false);
|
27 |
+
}
|
28 |
+
};
|
29 |
+
|
30 |
+
const upload = multer({
|
31 |
+
storage: storage,
|
32 |
+
limits: {
|
33 |
+
fileSize: 1024 * 1024 * 5
|
34 |
+
},
|
35 |
+
fileFilter: fileFilter
|
36 |
+
});
|
37 |
+
|
38 |
+
//Add products
|
39 |
+
router.post("/", upload.single('file'), async (req, res) => {
|
40 |
+
|
41 |
+
await firebase.uploadFile(req.file.path, "Drinks/" + req.file.filename)
|
42 |
+
await firebase.generateSignedUrl("Drinks/" + req.file.filename).then(res => {
|
43 |
+
imageUrl = res
|
44 |
+
})
|
45 |
+
|
46 |
+
if (imageUrl == "") {
|
47 |
+
imageUrl = req.file.path
|
48 |
+
}
|
49 |
+
|
50 |
+
console.log(req.body)
|
51 |
+
const drinks = Drinks({
|
52 |
+
_id: mongoose.Types.ObjectId(),
|
53 |
+
name: req.body.name,
|
54 |
+
price: req.body.price,
|
55 |
+
description: req.body.description,
|
56 |
+
image: imageUrl,
|
57 |
+
isLiked: req.body.isLiked,
|
58 |
+
|
59 |
+
});
|
60 |
+
drinks
|
61 |
+
.save()
|
62 |
+
.then(result => {
|
63 |
+
console.log(result);
|
64 |
+
res.status(200).send(
|
65 |
+
responseAddProduct(true, result));
|
66 |
+
})
|
67 |
+
.catch(err => {
|
68 |
+
console.log(err.message);
|
69 |
+
res.status(500).send(responseAddProduct(false, err));
|
70 |
+
});
|
71 |
+
});
|
72 |
+
|
73 |
+
//Get products
|
74 |
+
router.get("/", (req, res, next) => {
|
75 |
+
Drinks.find()
|
76 |
+
.exec()
|
77 |
+
.then(result => {
|
78 |
+
res.status(200).send(
|
79 |
+
responseFetchProduct(true, result));
|
80 |
+
})
|
81 |
+
.catch(err => {
|
82 |
+
console.log(err);
|
83 |
+
res.status(500).send(responseFetchProduct(false, err));
|
84 |
+
});
|
85 |
+
});
|
86 |
+
|
87 |
+
//Update products
|
88 |
+
router.put('/:id', upload.single('drinksImage'), async (req, res) => {
|
89 |
+
const id = req.params.id;
|
90 |
+
console.log(req.body);
|
91 |
+
const updateOps = {};
|
92 |
+
for (const ops of Object.keys(req.body)) {
|
93 |
+
updateOps[ops] = req.body[ops];
|
94 |
+
}
|
95 |
+
|
96 |
+
console.log(updateOps);
|
97 |
+
Drinks.updateOne({ _id: id }, { $set: updateOps })
|
98 |
+
.exec()
|
99 |
+
.then(result => {
|
100 |
+
res.status(200).send(
|
101 |
+
responseFetchProduct(true, result));
|
102 |
+
})
|
103 |
+
.catch(err => {
|
104 |
+
console.log(err);
|
105 |
+
res.status(500).send(responseFetchProduct(false, err));
|
106 |
+
});
|
107 |
+
});
|
108 |
+
|
109 |
+
//Delete products
|
110 |
+
router.delete("/:id", (req, res) => {
|
111 |
+
const id = req.params.id;
|
112 |
+
Vegetables.deleteOne({ _id: id })
|
113 |
+
.exec()
|
114 |
+
.then(result => {
|
115 |
+
res.status(200).send(
|
116 |
+
responseFetchProduct(true, result));
|
117 |
+
})
|
118 |
+
.catch(err => {
|
119 |
+
console.log(err);
|
120 |
+
res.status(500).send(responseFetchProduct(false, err));
|
121 |
+
});
|
122 |
+
});
|
123 |
+
|
124 |
+
|
125 |
+
module.exports = router;
|
routes/fcm.js
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
var express = require('express');
|
2 |
+
var router = express.Router();
|
3 |
+
var FCM = require('fcm-node');
|
4 |
+
var serverKey = 'AAAAKXRRooI:APA91bH9pMJziYPRNRI2XyMaSIG_e5a-eJzxMSkaozaCrmCencitDrTul4XyrVAV87K6d-56zGJC49y7Cz6mTRpcxca16QzmF1TF8EW7OmxHPvcQdseHWoD3TIAe62u2gfY0pVXlhJ8Y'
|
5 |
+
var fcm = new FCM(serverKey);
|
6 |
+
var User = require('../Database/models/user');
|
7 |
+
const { successResponse, failedResponse } = require('../utils/responseModel');
|
8 |
+
// const admin = require('firebase-admin');
|
9 |
+
const admin = require("../utils/firebase")
|
10 |
+
|
11 |
+
// Initialize the Firebase Admin SDK (replace with your credentials)
|
12 |
+
// admin.initializeApp({
|
13 |
+
// credential: admin.credential.cert(require('../push-notification-key.json'))
|
14 |
+
// });
|
15 |
+
|
16 |
+
router.post('/pushToken', async function (req, res) {
|
17 |
+
var unique_idValue = req.body.unique_id;
|
18 |
+
var pushTokenValue = req.body.pushToken;
|
19 |
+
try {
|
20 |
+
const data = await User.findOne({ unique_id: unique_idValue });
|
21 |
+
if (data) {
|
22 |
+
User.updateOne({
|
23 |
+
unique_id
|
24 |
+
: data.unique_id
|
25 |
+
}, {
|
26 |
+
$set: {
|
27 |
+
pushToken: pushTokenValue
|
28 |
+
}
|
29 |
+
}).exec()
|
30 |
+
.then(result => {
|
31 |
+
res.status(200).send(successResponse("Push token updated."));
|
32 |
+
})
|
33 |
+
.catch(err => {
|
34 |
+
console.log(err);
|
35 |
+
res.status(500).json({
|
36 |
+
error: err
|
37 |
+
});
|
38 |
+
});
|
39 |
+
} else {
|
40 |
+
res.status(201).send(failedResponse("User not found!"));
|
41 |
+
}
|
42 |
+
} catch (e) {
|
43 |
+
res.status(500).send(failedResponse(e));
|
44 |
+
}
|
45 |
+
});
|
46 |
+
|
47 |
+
|
48 |
+
|
49 |
+
router.post('/push', async (req, res) => {
|
50 |
+
try {
|
51 |
+
const deviceToken = req.body.deviceToken;
|
52 |
+
const title = req.body.title;
|
53 |
+
const bodyText = req.body.bodyText;
|
54 |
+
|
55 |
+
const message = {
|
56 |
+
token: deviceToken,
|
57 |
+
notification: {
|
58 |
+
title: title,
|
59 |
+
body: bodyText,
|
60 |
+
},
|
61 |
+
android: {
|
62 |
+
priority: "high",
|
63 |
+
},
|
64 |
+
};
|
65 |
+
|
66 |
+
// Send message via Firebase Admin SDK
|
67 |
+
const response = await admin.messaging().send(message);
|
68 |
+
res.status(200).send(response);
|
69 |
+
} catch (err) {
|
70 |
+
res.status(400).send("Something has gone wrong! => " + err.message);
|
71 |
+
console.error("Error sending message:", err);
|
72 |
+
}
|
73 |
+
});
|
74 |
+
|
75 |
+
module.exports = router;
|
routes/forgotPassword.js
ADDED
@@ -0,0 +1,214 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const express = require("express");
|
2 |
+
const router = express.Router();
|
3 |
+
const mongoose = require("mongoose");
|
4 |
+
const exphbs = require('express-handlebars');
|
5 |
+
var nodemailer = require('nodemailer');
|
6 |
+
var User = require('../Database/models/user');
|
7 |
+
const { successResponse, failedResponse } = require("../utils/responseModel");
|
8 |
+
|
9 |
+
var otp = Math.random();
|
10 |
+
otp = otp * 10000;
|
11 |
+
otp = parseInt(otp);
|
12 |
+
|
13 |
+
|
14 |
+
var transporter = nodemailer.createTransport({
|
15 |
+
|
16 |
+
service: 'gmail',
|
17 |
+
|
18 |
+
auth: {
|
19 |
+
user: '[email protected]', // here use your real email
|
20 |
+
pass: 'vmllbwfiehtqaeep' // put your password correctly (not in this question please)
|
21 |
+
}
|
22 |
+
});
|
23 |
+
|
24 |
+
router.post('/', async (req, res, next) => {
|
25 |
+
try {
|
26 |
+
var email = req.body.email;
|
27 |
+
console.log(email);
|
28 |
+
|
29 |
+
var newOtpValue = Math.floor(1000 + Math.random() * 9000);
|
30 |
+
|
31 |
+
const data = await User.findOne({ email: email });
|
32 |
+
|
33 |
+
if (data) {
|
34 |
+
console.log(data);
|
35 |
+
//find the user using unique id for update token.
|
36 |
+
User.updateOne({
|
37 |
+
unique_id
|
38 |
+
: data.unique_id
|
39 |
+
}, {
|
40 |
+
$set: {
|
41 |
+
token: newOtpValue
|
42 |
+
}
|
43 |
+
}).exec()
|
44 |
+
.then(result => {
|
45 |
+
//Generate Main formate how you send.
|
46 |
+
var mailOptions = {
|
47 |
+
priority: "high",
|
48 |
+
from: '[email protected]',
|
49 |
+
to: email,
|
50 |
+
subject: `OTP for frogot password`,
|
51 |
+
html: `<div style="font-family: Helvetica,Arial,sans-serif;min-width:1000px;overflow:auto;line-height:2">
|
52 |
+
<div style="margin:50px auto;width:70%;padding:20px 0">
|
53 |
+
<div style="border-bottom:1px solid #eee">
|
54 |
+
<a href="" style="font-size:1.4em;color: #00466a;text-decoration:none;font-weight:600">Hayat Store</a>
|
55 |
+
</div>
|
56 |
+
<p style="font-size:1.1em">Hi ${data.username},</p>
|
57 |
+
<p>Thank you for choosing the Hayat. Use the following OTP to complete your forgot password procedures. OTP is valid for 2 minutes</p>
|
58 |
+
<h2 style="background: #00466a;margin: 0 auto;width: max-content;padding: 0 10px;color: #fff;border-radius: 4px;">${newOtpValue}</h2>
|
59 |
+
<p style="font-size:0.9em;">Regards,<br />Hayat Store</p>
|
60 |
+
<hr style="border:none;border-top:1px solid #eee" />
|
61 |
+
<div style="float:right;padding:8px 0;color:#aaa;font-size:0.8em;line-height:1;font-weight:300">
|
62 |
+
<p>Hayat Store Inc</p>
|
63 |
+
<p>Tamil Nadu,</p>
|
64 |
+
<p>Nagapattinum dt,</p>
|
65 |
+
<p>Enangudi.</p>
|
66 |
+
</div>
|
67 |
+
</div>
|
68 |
+
</div>` // html body
|
69 |
+
};
|
70 |
+
console.log(mailOptions);
|
71 |
+
transporter.sendMail(mailOptions, (error, info) => {
|
72 |
+
if (error) {
|
73 |
+
res.status(201).send(failedResponse(error));
|
74 |
+
console.log('Error found' + error);
|
75 |
+
} else {
|
76 |
+
//Success message
|
77 |
+
res.status(200).send(successResponse("OTP sent to your email!"));
|
78 |
+
console.log('');
|
79 |
+
}
|
80 |
+
});
|
81 |
+
})
|
82 |
+
.catch(err => {
|
83 |
+
console.log(err);
|
84 |
+
res.status(500).json({
|
85 |
+
error: err
|
86 |
+
});
|
87 |
+
});
|
88 |
+
|
89 |
+
|
90 |
+
|
91 |
+
} else {
|
92 |
+
res.send(failedResponse("Invalid user!"))
|
93 |
+
}
|
94 |
+
|
95 |
+
} catch (error) {
|
96 |
+
res.status(500).send(failedResponse(error));
|
97 |
+
}
|
98 |
+
|
99 |
+
});
|
100 |
+
|
101 |
+
|
102 |
+
//Verify the otp
|
103 |
+
router.post('/verify', async (req, res, next) => {
|
104 |
+
try {
|
105 |
+
var email = req.body.email;
|
106 |
+
console.log(req.body.otp)
|
107 |
+
|
108 |
+
const data = await User.findOne({ email: email });
|
109 |
+
if (data) {
|
110 |
+
if (data.token == req.body.otp) {
|
111 |
+
|
112 |
+
User.updateOne({
|
113 |
+
unique_id
|
114 |
+
: data.unique_id
|
115 |
+
}, {
|
116 |
+
$set: {
|
117 |
+
token: ""
|
118 |
+
}
|
119 |
+
}).exec()
|
120 |
+
.then(result => {
|
121 |
+
res.send(successResponse("Verified successfully!"))
|
122 |
+
});
|
123 |
+
otp = 0;
|
124 |
+
|
125 |
+
}
|
126 |
+
else {
|
127 |
+
res.send(failedResponse("Invalid OTP!"));
|
128 |
+
}
|
129 |
+
} else {
|
130 |
+
res.send(failedResponse("Data not found!"));
|
131 |
+
}
|
132 |
+
|
133 |
+
} catch (err) {
|
134 |
+
res.send(failedResponse(err));
|
135 |
+
}
|
136 |
+
});
|
137 |
+
|
138 |
+
|
139 |
+
//Resend the otp
|
140 |
+
router.post('/resend', async function (req, res) {
|
141 |
+
try {
|
142 |
+
var email = req.body.email;
|
143 |
+
console.log(email);
|
144 |
+
var newOtpValue = Math.floor(1000 + Math.random() * 9000);
|
145 |
+
|
146 |
+
const data = await User.findOne({ email: email });
|
147 |
+
|
148 |
+
if (data) {
|
149 |
+
console.log(data);
|
150 |
+
//find the user using unique id for update token.
|
151 |
+
User.updateOne({
|
152 |
+
unique_id
|
153 |
+
: data.unique_id
|
154 |
+
}, {
|
155 |
+
$set: {
|
156 |
+
token: newOtpValue
|
157 |
+
}
|
158 |
+
}).exec()
|
159 |
+
.then(result => {
|
160 |
+
//Generate Main formate how you send.
|
161 |
+
var mailOptions = {
|
162 |
+
priority: "high",
|
163 |
+
from: '[email protected]',
|
164 |
+
to: '[email protected] ',
|
165 |
+
subject: `OTP for frogot password`,
|
166 |
+
html: `<div style="font-family: Helvetica,Arial,sans-serif;min-width:1000px;overflow:auto;line-height:2">
|
167 |
+
<div style="margin:50px auto;width:70%;padding:20px 0">
|
168 |
+
<div style="border-bottom:1px solid #eee">
|
169 |
+
<a href="" style="font-size:1.4em;color: #00466a;text-decoration:none;font-weight:600">Hayat Store</a>
|
170 |
+
</div>
|
171 |
+
<p style="font-size:1.1em">Hi ${data.username},</p>
|
172 |
+
<p>Thank you for choosing the Hayat. Use the following OTP to complete your forgot password procedures. OTP is valid for 1 minutes</p>
|
173 |
+
<h2 style="background: #00466a;margin: 0 auto;width: max-content;padding: 0 10px;color: #fff;border-radius: 4px;">${newOtpValue}</h2>
|
174 |
+
<p style="font-size:0.9em;">Regards,<br />Hayat Store</p>
|
175 |
+
<hr style="border:none;border-top:1px solid #eee" />
|
176 |
+
<div style="float:right;padding:8px 0;color:#aaa;font-size:0.8em;line-height:1;font-weight:300">
|
177 |
+
<p>Hayat Store Inc</p>
|
178 |
+
<p>Tamil Nadu,</p>
|
179 |
+
<p>Nagapattinum dt,</p>
|
180 |
+
<p>Enangudi.</p>
|
181 |
+
</div>
|
182 |
+
</div>
|
183 |
+
</div>` // html body
|
184 |
+
};
|
185 |
+
console.log(mailOptions);
|
186 |
+
transporter.sendMail(mailOptions, (error, info) => {
|
187 |
+
if (error) {
|
188 |
+
res.status(400).send(failedResponse(error));
|
189 |
+
console.log('Error found' + error);
|
190 |
+
} else {
|
191 |
+
//Success message
|
192 |
+
res.send(successResponse("OTP sent to your email!"));
|
193 |
+
console.log('OTP sent to your email!');
|
194 |
+
}
|
195 |
+
});
|
196 |
+
})
|
197 |
+
.catch(err => {
|
198 |
+
console.log(err);
|
199 |
+
res.status(500).json({
|
200 |
+
error: err
|
201 |
+
});
|
202 |
+
});
|
203 |
+
} else {
|
204 |
+
res.status(400).send(failedResponse("Invalid user!"))
|
205 |
+
}
|
206 |
+
|
207 |
+
} catch (error) {
|
208 |
+
res.status(400).send(failedResponse(err));
|
209 |
+
}
|
210 |
+
|
211 |
+
});
|
212 |
+
|
213 |
+
|
214 |
+
module.exports = router;
|
routes/fruits.js
ADDED
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const express = require("express");
|
2 |
+
const router = express.Router();
|
3 |
+
const mongoose = require("mongoose");
|
4 |
+
const multer = require('multer');
|
5 |
+
const Fruites = require("../Database/models/fruits");
|
6 |
+
const { responseAddProduct, responseFetchProduct } = require("../utils/responseModel");
|
7 |
+
const firebase = require("../utils/firebase")
|
8 |
+
var imageUrl = ""
|
9 |
+
|
10 |
+
//Disk storage where image store
|
11 |
+
const storage = multer.diskStorage({
|
12 |
+
destination: function (req, file, cb) {
|
13 |
+
cb(null, './uploads/fruits');
|
14 |
+
},
|
15 |
+
filename: function (req, file, cb) {
|
16 |
+
cb(null, file.originalname);
|
17 |
+
}
|
18 |
+
});
|
19 |
+
|
20 |
+
//Check the image formate
|
21 |
+
const fileFilter = (req, file, cb) => {
|
22 |
+
// reject a file
|
23 |
+
if (file.mimetype === 'image/jpeg' || file.mimetype === 'image/png' || file.mimetype === 'image/jpg') {
|
24 |
+
cb(null, true);
|
25 |
+
} else {
|
26 |
+
cb(null, false);
|
27 |
+
}
|
28 |
+
};
|
29 |
+
|
30 |
+
const upload = multer({
|
31 |
+
storage: storage,
|
32 |
+
limits: {
|
33 |
+
fileSize: 1024 * 1024 * 5
|
34 |
+
},
|
35 |
+
fileFilter: fileFilter
|
36 |
+
});
|
37 |
+
|
38 |
+
//Add products
|
39 |
+
router.post("/", upload.single('file'), async (req, res, next) => {
|
40 |
+
|
41 |
+
await firebase.uploadFile(req.file.path, "Fruites/" + req.file.filename)
|
42 |
+
await firebase.generateSignedUrl("Fruites/" + req.file.filename).then(res => {
|
43 |
+
imageUrl = res
|
44 |
+
})
|
45 |
+
|
46 |
+
if (imageUrl == "") {
|
47 |
+
imageUrl = req.file.path
|
48 |
+
}
|
49 |
+
|
50 |
+
console.log(req.body)
|
51 |
+
const fruites = Fruites({
|
52 |
+
_id: mongoose.Types.ObjectId(),
|
53 |
+
name: req.body.name,
|
54 |
+
price: req.body.price,
|
55 |
+
description: req.body.description,
|
56 |
+
image: imageUrl,
|
57 |
+
isLiked: req.body.isLiked,
|
58 |
+
|
59 |
+
});
|
60 |
+
fruites
|
61 |
+
.save()
|
62 |
+
.then(result => {
|
63 |
+
console.log(result);
|
64 |
+
res.status(200).send(responseAddProduct(true, result));
|
65 |
+
})
|
66 |
+
.catch(err => {
|
67 |
+
console.log(err.message);
|
68 |
+
res.status(500).send(responseAddProduct(false, err));
|
69 |
+
});
|
70 |
+
});
|
71 |
+
|
72 |
+
|
73 |
+
//Get products
|
74 |
+
router.get("/", (req, res, next) => {
|
75 |
+
Fruites.find()
|
76 |
+
.exec()
|
77 |
+
.then(result => {
|
78 |
+
res.status(200).send(responseFetchProduct(true, result));
|
79 |
+
})
|
80 |
+
.catch(err => {
|
81 |
+
console.log(err);
|
82 |
+
res.status(500).send(responseFetchProduct(false, err));
|
83 |
+
});
|
84 |
+
});
|
85 |
+
|
86 |
+
//Update products
|
87 |
+
router.put('/:id', upload.single('file'), async (req, res) => {
|
88 |
+
const id = req.params.id;
|
89 |
+
console.log(req.body);
|
90 |
+
const updateOps = {};
|
91 |
+
for (const ops of Object.keys(req.body)) {
|
92 |
+
updateOps[ops] = req.body[ops];
|
93 |
+
}
|
94 |
+
console.log(updateOps);
|
95 |
+
Fruites.updateOne({ _id: id }, { $set: updateOps })
|
96 |
+
.exec()
|
97 |
+
.then(result => {
|
98 |
+
res.status(200).send(responseFetchProduct(true, result));
|
99 |
+
})
|
100 |
+
.catch(err => {
|
101 |
+
console.log(err);
|
102 |
+
res.status(500).send(responseFetchProduct(false, err));
|
103 |
+
});
|
104 |
+
});
|
105 |
+
|
106 |
+
//Delete products
|
107 |
+
router.delete("/:id", (req, res) => {
|
108 |
+
const id = req.params.id;
|
109 |
+
Fruites.deleteOne({ _id: id })
|
110 |
+
.exec()
|
111 |
+
.then(result => {
|
112 |
+
res.status(200).send(responseFetchProduct(true, result));
|
113 |
+
})
|
114 |
+
.catch(err => {
|
115 |
+
console.log(err);
|
116 |
+
res.status(500).send(responseFetchProduct(false, err));
|
117 |
+
});
|
118 |
+
});
|
119 |
+
|
120 |
+
|
121 |
+
|
122 |
+
|
123 |
+
module.exports = router;
|
routes/grocery.js
ADDED
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const express = require("express");
|
2 |
+
const router = express.Router();
|
3 |
+
const mongoose = require("mongoose");
|
4 |
+
const multer = require('multer');
|
5 |
+
const Grocery = require("../Database/models/gocery");
|
6 |
+
const { responseAddProduct, responseFetchProduct } = require("../utils/responseModel");
|
7 |
+
const firebase = require("../utils/firebase")
|
8 |
+
var imageUrl = ""
|
9 |
+
|
10 |
+
//Disk storage where image store
|
11 |
+
const storage = multer.diskStorage({
|
12 |
+
destination: function (req, file, cb) {
|
13 |
+
cb(null, './uploads/grocery');
|
14 |
+
},
|
15 |
+
filename: function (req, file, cb) {
|
16 |
+
cb(null, file.originalname);
|
17 |
+
}
|
18 |
+
});
|
19 |
+
|
20 |
+
//Check the image formate
|
21 |
+
const fileFilter = (req, file, cb) => {
|
22 |
+
// reject a file
|
23 |
+
if (file.mimetype === 'image/jpeg' || file.mimetype === 'image/png' || file.mimetype === 'image/jpg') {
|
24 |
+
cb(null, true);
|
25 |
+
} else {
|
26 |
+
cb(null, false);
|
27 |
+
}
|
28 |
+
};
|
29 |
+
|
30 |
+
const upload = multer({
|
31 |
+
storage: storage,
|
32 |
+
limits: {
|
33 |
+
fileSize: 1024 * 1024 * 10
|
34 |
+
},
|
35 |
+
fileFilter: fileFilter
|
36 |
+
});
|
37 |
+
|
38 |
+
//Add products
|
39 |
+
router.post("/", upload.single('file'), async (req, res, next) => {
|
40 |
+
|
41 |
+
|
42 |
+
await firebase.uploadFile(req.file.path, "Grocery/" + req.file.filename)
|
43 |
+
await firebase.generateSignedUrl("Grocery/" + req.file.filename).then(res => {
|
44 |
+
imageUrl = res
|
45 |
+
})
|
46 |
+
|
47 |
+
if (imageUrl == "") {
|
48 |
+
imageUrl = req.file.path
|
49 |
+
}
|
50 |
+
|
51 |
+
console.log(req.body)
|
52 |
+
const grocery = Grocery({
|
53 |
+
_id: mongoose.Types.ObjectId(),
|
54 |
+
name: req.body.name,
|
55 |
+
price: req.body.price,
|
56 |
+
description: req.body.description,
|
57 |
+
image: imageUrl,
|
58 |
+
isLiked: req.body.isLiked,
|
59 |
+
|
60 |
+
});
|
61 |
+
grocery
|
62 |
+
.save()
|
63 |
+
.then(result => {
|
64 |
+
console.log(result);
|
65 |
+
res.status(200).send(responseAddProduct(true, result));
|
66 |
+
})
|
67 |
+
.catch(err => {
|
68 |
+
console.log(err.message);
|
69 |
+
res.status(500).send(responseAddProduct(false, err));
|
70 |
+
});
|
71 |
+
});
|
72 |
+
|
73 |
+
|
74 |
+
//Get products
|
75 |
+
router.get("/", (req, res, next) => {
|
76 |
+
Grocery.find()
|
77 |
+
.exec()
|
78 |
+
.then(result => {
|
79 |
+
res.status(200).send(responseFetchProduct(true, result));
|
80 |
+
})
|
81 |
+
.catch(err => {
|
82 |
+
console.log(err);
|
83 |
+
res.status(500).send(responseFetchProduct(false, err));
|
84 |
+
});
|
85 |
+
});
|
86 |
+
|
87 |
+
//Update products
|
88 |
+
router.put('/:id', upload.single('file'), async (req, res) => {
|
89 |
+
const id = req.params.id;
|
90 |
+
console.log(req.body);
|
91 |
+
|
92 |
+
|
93 |
+
const updateOps = {};
|
94 |
+
|
95 |
+
for (const ops of Object.keys(req.body)) {
|
96 |
+
updateOps[ops] = req.body[ops];
|
97 |
+
}
|
98 |
+
|
99 |
+
Grocery.updateOne({ _id: id }, { $set: updateOps })
|
100 |
+
.exec()
|
101 |
+
.then(result => {
|
102 |
+
res.status(200).send(responseFetchProduct(true, result));
|
103 |
+
})
|
104 |
+
.catch(err => {
|
105 |
+
console.log(err);
|
106 |
+
res.status(500).send(responseFetchProduct(false, err));
|
107 |
+
});
|
108 |
+
});
|
109 |
+
|
110 |
+
//Delete products
|
111 |
+
router.delete("/:id", (req, res) => {
|
112 |
+
const id = req.params.id;
|
113 |
+
Grocery.deleteOne({ _id: id })
|
114 |
+
.exec()
|
115 |
+
.then(result => {
|
116 |
+
res.status(200).send(responseFetchProduct(true, result));
|
117 |
+
})
|
118 |
+
.catch(err => {
|
119 |
+
console.log(err);
|
120 |
+
res.status(500).send(responseFetchProduct(false, err));
|
121 |
+
});
|
122 |
+
});
|
123 |
+
|
124 |
+
|
125 |
+
|
126 |
+
|
127 |
+
module.exports = router;
|
routes/healthCare.js
ADDED
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const express = require("express");
|
2 |
+
const router = express.Router();
|
3 |
+
const mongoose = require("mongoose");
|
4 |
+
const multer = require('multer');
|
5 |
+
const HealthCare = require("../Database/models/healthCare");
|
6 |
+
const { responseAddProduct, responseFetchProduct } = require("../utils/responseModel");
|
7 |
+
|
8 |
+
const firebase = require("../utils/firebase")
|
9 |
+
var imageUrl = ""
|
10 |
+
|
11 |
+
//Disk storage where image store
|
12 |
+
const storage = multer.diskStorage({
|
13 |
+
destination: function (req, file, cb) {
|
14 |
+
cb(null, './uploads/healthCare');
|
15 |
+
},
|
16 |
+
filename: function (req, file, cb) {
|
17 |
+
cb(null, file.originalname);
|
18 |
+
}
|
19 |
+
});
|
20 |
+
|
21 |
+
//Check the image formate
|
22 |
+
const fileFilter = (req, file, cb) => {
|
23 |
+
// reject a file
|
24 |
+
if (file.mimetype === 'image/jpeg' || file.mimetype === 'image/png' || file.mimetype === 'image/jpg') {
|
25 |
+
cb(null, true);
|
26 |
+
} else {
|
27 |
+
cb(null, false);
|
28 |
+
}
|
29 |
+
};
|
30 |
+
|
31 |
+
const upload = multer({
|
32 |
+
storage: storage,
|
33 |
+
limits: {
|
34 |
+
fileSize: 1024 * 1024 * 5
|
35 |
+
},
|
36 |
+
fileFilter: fileFilter
|
37 |
+
});
|
38 |
+
|
39 |
+
//Add products
|
40 |
+
router.post("/", upload.single('file'), async (req, res, next) => {
|
41 |
+
|
42 |
+
await firebase.uploadFile(req.file.path, "HealthCare/" + req.file.filename)
|
43 |
+
await firebase.generateSignedUrl("HealthCare/" + req.file.filename).then(res => {
|
44 |
+
imageUrl = res
|
45 |
+
})
|
46 |
+
|
47 |
+
if (imageUrl == "") {
|
48 |
+
imageUrl = req.file.path
|
49 |
+
}
|
50 |
+
|
51 |
+
console.log(req.body)
|
52 |
+
const fruites = HealthCare({
|
53 |
+
_id: mongoose.Types.ObjectId(),
|
54 |
+
name: req.body.name,
|
55 |
+
price: req.body.price,
|
56 |
+
description: req.body.description,
|
57 |
+
image: imageUrl,
|
58 |
+
isLiked: req.body.isLiked,
|
59 |
+
|
60 |
+
});
|
61 |
+
fruites
|
62 |
+
.save()
|
63 |
+
.then(result => {
|
64 |
+
console.log(result);
|
65 |
+
res.status(200).send(
|
66 |
+
responseAddProduct(true, result));
|
67 |
+
})
|
68 |
+
.catch(err => {
|
69 |
+
console.log(err.message);
|
70 |
+
res.status(500).send(responseAddProduct(false, err));
|
71 |
+
});
|
72 |
+
});
|
73 |
+
|
74 |
+
|
75 |
+
//Get products
|
76 |
+
router.get("/", (req, res, next) => {
|
77 |
+
HealthCare.find()
|
78 |
+
.exec()
|
79 |
+
.then(result => {
|
80 |
+
res.status(200).send(responseFetchProduct(true, result));
|
81 |
+
})
|
82 |
+
.catch(err => {
|
83 |
+
console.log(err);
|
84 |
+
res.status(500).send(responseFetchProduct(false, err));
|
85 |
+
});
|
86 |
+
});
|
87 |
+
|
88 |
+
//Update products
|
89 |
+
router.put('/:id', upload.single('file'), async (req, res) => {
|
90 |
+
const id = req.params.id;
|
91 |
+
console.log(req.body);
|
92 |
+
const updateOps = {};
|
93 |
+
for (const ops of Object.keys(req.body)) {
|
94 |
+
updateOps[ops] = req.body[ops];
|
95 |
+
}
|
96 |
+
|
97 |
+
console.log(updateOps);
|
98 |
+
HealthCare.updateOne({ _id: id }, { $set: updateOps })
|
99 |
+
.exec()
|
100 |
+
.then(result => {
|
101 |
+
res.status(200).send(responseFetchProduct(true, result));
|
102 |
+
})
|
103 |
+
.catch(err => {
|
104 |
+
console.log(err);
|
105 |
+
res.status(500).send(responseFetchProduct(false, err));
|
106 |
+
});
|
107 |
+
});
|
108 |
+
|
109 |
+
//Delete products
|
110 |
+
router.delete("/:id", (req, res) => {
|
111 |
+
const id = req.params.id;
|
112 |
+
HealthCare.deleteOne({ _id: id })
|
113 |
+
.exec()
|
114 |
+
.then(result => {
|
115 |
+
res.status(200).send(responseFetchProduct(true, result));
|
116 |
+
})
|
117 |
+
.catch(err => {
|
118 |
+
console.log(err);
|
119 |
+
res.status(500).send(responseFetchProduct(false, err));
|
120 |
+
});
|
121 |
+
});
|
122 |
+
|
123 |
+
|
124 |
+
|
125 |
+
|
126 |
+
module.exports = router;
|
routes/home.js
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const express = require("express");
|
2 |
+
const router = express.Router();
|
3 |
+
const mongoose = require("mongoose");
|
4 |
+
const multer = require('multer');
|
5 |
+
const DriedNoodles = require("../Database/models/DriedNoodles")
|
6 |
+
const { responseAddProduct, responseFetchProduct } = require("../utils/responseModel");
|
7 |
+
const Banner = require("../Database/models/banner")
|
8 |
+
const Category = require("../Database/models/category")
|
9 |
+
const Order = require("../Database/models/order");
|
10 |
+
const Products = require("../Database/models/product");
|
11 |
+
const User = require("../Database/models/user");
|
12 |
+
const featureProduct = require("../Database/mufiModels/featureProduct");
|
13 |
+
|
14 |
+
router.get("/", async (req, res, next) => {
|
15 |
+
try {
|
16 |
+
const userId = req.query.id;
|
17 |
+
console.log("UserId -> ", userId);
|
18 |
+
const bannersList = await Banner.find();
|
19 |
+
const categoryList = await Category.find();
|
20 |
+
let userData = {}
|
21 |
+
let ordersList = {}
|
22 |
+
try {
|
23 |
+
ordersList = await Order.find({ unique_id: userId });
|
24 |
+
const tempData = await User.findOne({ unique_id: userId });
|
25 |
+
userData = tempData.toObject();
|
26 |
+
delete userData.passwordConf;
|
27 |
+
delete userData.password;
|
28 |
+
delete userData.pushToken;
|
29 |
+
console.log(userData);
|
30 |
+
} catch (err) {
|
31 |
+
console.log(err)
|
32 |
+
}
|
33 |
+
|
34 |
+
const featureProductList = await featureProduct.find()
|
35 |
+
const productsList = await Products.find();
|
36 |
+
|
37 |
+
const response = {
|
38 |
+
user: userData,
|
39 |
+
banner: bannersList,
|
40 |
+
categories: categoryList,
|
41 |
+
// recentPurchase: ordersList,
|
42 |
+
products: featureProductList ?? productsList
|
43 |
+
}
|
44 |
+
|
45 |
+
res.status(200).send(responseFetchProduct(true, response))
|
46 |
+
|
47 |
+
} catch (e) {
|
48 |
+
res.status(500).send(responseFetchProduct(false, e))
|
49 |
+
}
|
50 |
+
});
|
51 |
+
|
52 |
+
|
53 |
+
// router.get("/:id", async (req, res) => {
|
54 |
+
// try {
|
55 |
+
// const bannersList = await Banner.find();
|
56 |
+
// const categoryList = await Category.find();
|
57 |
+
// const ordersList = {}
|
58 |
+
// try {
|
59 |
+
// ordersList = await Order.find({ unique_id: req.params.id });
|
60 |
+
// } catch (err) {
|
61 |
+
// console.log(err)
|
62 |
+
// }
|
63 |
+
// const productsList = await Products.find();
|
64 |
+
|
65 |
+
// const response = {
|
66 |
+
// banner: bannersList,
|
67 |
+
// categories: categoryList,
|
68 |
+
// recentPurchase: ordersList,
|
69 |
+
// products: productsList
|
70 |
+
// }
|
71 |
+
|
72 |
+
// res.status(200).send(responseFetchProduct(true, response))
|
73 |
+
|
74 |
+
// } catch (e) {
|
75 |
+
// res.status(500).send(responseFetchProduct(false, e))
|
76 |
+
// }
|
77 |
+
|
78 |
+
// });
|
79 |
+
|
80 |
+
module.exports = router;
|
routes/login.js
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
var express = require('express');
|
2 |
+
var router = express.Router();
|
3 |
+
var User = require('../Database/models/user');
|
4 |
+
const bcrypt = require("bcrypt");
|
5 |
+
const { profileResponse, failedResponse, successResponse } = require('../utils/responseModel');
|
6 |
+
const verifyGoogleToken = require('../core/auth');
|
7 |
+
|
8 |
+
// Middleware to parse JSON bodies
|
9 |
+
router.use(express.json());
|
10 |
+
|
11 |
+
// Utility function to generate unique_id
|
12 |
+
async function generateUniqueId() {
|
13 |
+
const lastUser = await User.findOne({}).sort({ _id: -1 }).limit(1);
|
14 |
+
return lastUser ? lastUser.unique_id + 1 : 1;
|
15 |
+
}
|
16 |
+
|
17 |
+
// Login user
|
18 |
+
router.post('/', async function (req, res, next) {
|
19 |
+
const { email, mobileNumber, password, googleToken } = req.body;
|
20 |
+
|
21 |
+
// Validate input
|
22 |
+
if (!email && !mobileNumber && !googleToken) {
|
23 |
+
return res.status(400).send(failedResponse('Please provide email, mobile number, or Google token.'));
|
24 |
+
}
|
25 |
+
|
26 |
+
try {
|
27 |
+
let user;
|
28 |
+
// If Google token is provided, handle Google login
|
29 |
+
if (googleToken) {
|
30 |
+
// Verify Google token and get user information
|
31 |
+
const googleUserDetails = await verifyGoogleToken(googleToken);
|
32 |
+
const googleUser = googleUserDetails.getPayload();
|
33 |
+
console.log("Google user = ", googleUser.name);
|
34 |
+
console.log("Google user = ", googleUser.email);
|
35 |
+
// Find user by Google ID
|
36 |
+
await User.findOne({ email: googleUser.email }).exec().then(async (existUser) => {
|
37 |
+
if (existUser) {
|
38 |
+
user = existUser;
|
39 |
+
} else {
|
40 |
+
console.log(" User not found!");
|
41 |
+
// If user is not found, create a new user
|
42 |
+
const generatedUniqueId = await generateUniqueId();
|
43 |
+
const googleUserId = googleUserDetails.getUserId();
|
44 |
+
const password = googleUser.email + "/" + googleUserId;
|
45 |
+
const hashedPassword = await bcrypt.hash(password, 10);
|
46 |
+
|
47 |
+
const newUser = new User({
|
48 |
+
unique_id: generatedUniqueId, // Implement this function to generate a unique ID
|
49 |
+
email: googleUser.email,
|
50 |
+
username: googleUser.name,
|
51 |
+
profilePic: googleUser.picture,
|
52 |
+
googleId: googleUserId,
|
53 |
+
password: hashedPassword
|
54 |
+
// Add other fields if needed
|
55 |
+
});
|
56 |
+
console.log(newUser);
|
57 |
+
await newUser.save(); // Save the new user to the database
|
58 |
+
user = newUser;
|
59 |
+
}
|
60 |
+
}); // Use .exec() to ensure a promise is returned
|
61 |
+
} else {
|
62 |
+
// Handle email or mobile number login
|
63 |
+
if (email) {
|
64 |
+
user = await User.findOne({ email });
|
65 |
+
} else if (mobileNumber) {
|
66 |
+
user = await User.findOne({ mobileNumber });
|
67 |
+
}
|
68 |
+
|
69 |
+
if (!user) {
|
70 |
+
return res.status(201).send(failedResponse('User not found.'));
|
71 |
+
}
|
72 |
+
|
73 |
+
// Validate password if email or mobile number is used
|
74 |
+
if (password) {
|
75 |
+
const validPassword = await bcrypt.compare(password, user.password);
|
76 |
+
if (!validPassword) {
|
77 |
+
return res.status(400).send(failedResponse('Wrong password.'));
|
78 |
+
}
|
79 |
+
}
|
80 |
+
}
|
81 |
+
|
82 |
+
// // Success
|
83 |
+
// req.userId = user.unique_id; // Set user ID in session or handle as needed
|
84 |
+
// console.log(user);
|
85 |
+
res.status(200).send(profileResponse("Login successful", 200, user));
|
86 |
+
} catch (err) {
|
87 |
+
// Handle errors
|
88 |
+
console.error(err);
|
89 |
+
res.status(500).send(failedResponse('Internal server error.'));
|
90 |
+
}
|
91 |
+
});
|
92 |
+
|
93 |
+
module.exports = router;
|
routes/logout.js
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
var express = require('express');
|
2 |
+
var router = express.Router();
|
3 |
+
var app = express();
|
4 |
+
var User = require('../models/user');
|
5 |
+
const bcrypt = require("bcrypt");
|
6 |
+
const jwt = require("jsonwebtoken");
|
7 |
+
|
8 |
+
|
9 |
+
router.post('/logout', function (req, res, next) {
|
10 |
+
|
11 |
+
var session = {
|
12 |
+
"cookie": {
|
13 |
+
path: '/', _expires: null,
|
14 |
+
originalMaxAge: null,
|
15 |
+
httpOnly: true
|
16 |
+
},
|
17 |
+
userId: req.body.user_id
|
18 |
+
}
|
19 |
+
console.log(session)
|
20 |
+
|
21 |
+
if (session) {
|
22 |
+
// delete session object
|
23 |
+
req.session.destroy(function (err) {
|
24 |
+
if (err) {
|
25 |
+
return res.send(failedResponse("Logout failed!"))
|
26 |
+
|
27 |
+
} else {
|
28 |
+
return res.send(successResponse('Logout success'));
|
29 |
+
|
30 |
+
}
|
31 |
+
});
|
32 |
+
req.session.destroy;
|
33 |
+
}
|
34 |
+
});
|
35 |
+
|
36 |
+
module.exports = router;
|