database-connector 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,260 @@
1
+ const mongoose = require('mongoose');
2
+ const User = require('./User');
3
+ const Product = require('./Product');
4
+ const { policySchema } = require('./Policy');
5
+ var ObjectId = require('mongodb').ObjectID;
6
+
7
+ const storeSchema = new mongoose.Schema(
8
+ {
9
+ name: {
10
+ type: String,
11
+ required: true,
12
+ },
13
+ sellerId: {
14
+ type: mongoose.Schema.Types.ObjectId,
15
+ required: true,
16
+ ref: 'User',
17
+ },
18
+ address: {
19
+ city: {
20
+ type: String,
21
+ required: true,
22
+ },
23
+ streetName: {
24
+ type: String,
25
+ //required: true,
26
+ },
27
+ postalCode: {
28
+ type: String,
29
+ //required: true,
30
+ },
31
+ country: {
32
+ type: String,
33
+ //required: true,
34
+ },
35
+ fullAdress: {
36
+ type: String,
37
+ //required: true,
38
+ },
39
+ region: {
40
+ type: String,
41
+ //required: true,
42
+ },
43
+ countryCode: {
44
+ type: String,
45
+ //required: true,
46
+ },
47
+ phone: {
48
+ type: String,
49
+ //required: true,
50
+ },
51
+ },
52
+ location: {
53
+ type: {
54
+ type: String,
55
+ enum: ['Point'],
56
+ default: 'Point',
57
+ },
58
+ coordinates: [
59
+ {
60
+ type: Number,
61
+ required: true,
62
+ },
63
+ {
64
+ type: Number,
65
+ required: true,
66
+ },
67
+ ],
68
+ },
69
+
70
+ image: {
71
+ type: String,
72
+ required: true,
73
+ },
74
+ customCategorie: [
75
+ {
76
+ name: {
77
+ type: String,
78
+ required: true,
79
+ },
80
+ productIds: [
81
+ {
82
+ type: mongoose.Schema.Types.ObjectId,
83
+ ref: 'Product',
84
+ },
85
+ ],
86
+ },
87
+ ],
88
+ categories: [
89
+ {
90
+ name: {
91
+ type: String,
92
+ required: true,
93
+ },
94
+ productIds: [
95
+ {
96
+ type: mongoose.Schema.Types.ObjectId,
97
+ ref: 'Product',
98
+ },
99
+ ],
100
+ },
101
+ ],
102
+ isActive: {
103
+ type: Boolean,
104
+ default: true,
105
+ },
106
+ policy: policySchema,
107
+ offers: [
108
+ {
109
+ name: {
110
+ type: String,
111
+ required: true,
112
+ },
113
+ description: {
114
+ type: String,
115
+ required: true,
116
+ },
117
+ image: {
118
+ type: String,
119
+ },
120
+ timestamps: {
121
+ type: Date,
122
+ required: true,
123
+ default: Date.now(),
124
+ },
125
+ discount: {
126
+ type: Number,
127
+ required: true,
128
+ default: 0,
129
+ },
130
+ productId: {
131
+ type: mongoose.Schema.Types.ObjectId,
132
+ ref: 'Product',
133
+ },
134
+ },
135
+ ],
136
+ followers: [
137
+ {
138
+ userId: {
139
+ type: mongoose.Schema.Types.ObjectId,
140
+ ref: 'User',
141
+ },
142
+ date: {
143
+ type: Date,
144
+ required: true,
145
+ default: Date.now(),
146
+ },
147
+ },
148
+ ],
149
+ description: {
150
+ type: String,
151
+ required: true,
152
+ },
153
+ ratingCount: {
154
+ type: Number,
155
+ default: 0,
156
+ },
157
+ ratingSum: {
158
+ type: Number,
159
+ default: 0,
160
+ },
161
+ revenue: { type: Number, default: 0 },
162
+ workingTime: {
163
+ type: {
164
+ option: {
165
+ type: String,
166
+ default: '',
167
+ },
168
+ fixedHours: [
169
+ {
170
+ openTime: {
171
+ type: String,
172
+ required: true,
173
+ },
174
+ closeTime: {
175
+ type: String,
176
+ required: true,
177
+ },
178
+ },
179
+ ],
180
+ customizedHours: {
181
+ type: Map,
182
+ of: [
183
+ {
184
+ openTime: {
185
+ type: String,
186
+ required: true,
187
+ },
188
+ closeTime: {
189
+ type: String,
190
+ required: true,
191
+ },
192
+ },
193
+ ],
194
+ },
195
+ },
196
+ required: false,
197
+ },
198
+ storeCategorieIds: [
199
+ {
200
+ type: mongoose.Schema.Types.ObjectId,
201
+ ref: 'StoreCategory',
202
+ },
203
+ ],
204
+ productCategorieIds: [
205
+ {
206
+ categoryId: {
207
+ type: mongoose.Schema.Types.ObjectId,
208
+ ref: 'Category',
209
+ },
210
+ subCategories: [
211
+ {
212
+ type: mongoose.Schema.Types.ObjectId,
213
+ ref: 'Category.subCategories',
214
+ },
215
+ ],
216
+ },
217
+ ],
218
+ storeRayons: [
219
+ {
220
+ name: {
221
+ type: String,
222
+ required: true,
223
+ },
224
+ },
225
+ ],
226
+ templateId: {
227
+ type: Number,
228
+ default: 1,
229
+ },
230
+
231
+ activated: {
232
+ type: Boolean,
233
+ default: false,
234
+ },
235
+ subscriptionId: {
236
+ type: mongoose.Schema.Types.ObjectId,
237
+ ref: 'Subscription',
238
+ },
239
+ },
240
+ { timestamps: true }
241
+ //{ timestamps: true, toJSON: { virtuals: true } }
242
+ );
243
+ //virtual image url
244
+ storeSchema.virtual('imageUrl').get(function () {
245
+ if (this.image != null) {
246
+ return `${process.env.APP_URL}/${this.image}`;
247
+ }
248
+ return `${process.env.APP_URL}/images/stores/default.jpg`;
249
+ });
250
+ //virtual rating
251
+ storeSchema.virtual('rating').get(function () {
252
+ if (this.ratingSum != 0 && this.ratingCount != 0) {
253
+ return this.ratingSum / this.ratingCount;
254
+ }
255
+ return 0;
256
+ });
257
+ //creat index for location
258
+ storeSchema.index({ location: '2dsphere' });
259
+
260
+ module.exports = mongoose.model('Store', storeSchema);
@@ -0,0 +1,15 @@
1
+ const mongoose = require('mongoose');
2
+
3
+ const storeCategorySchema = new mongoose.Schema(
4
+ {
5
+ name: {
6
+ type: String,
7
+ required: true,
8
+ } ,
9
+
10
+ confirmed : { type : Boolean , default : false } ,
11
+ },
12
+ { timestamps: true, toJSON: { virtuals: true } }
13
+ );
14
+
15
+ module.exports = mongoose.model('StoreCategory', storeCategorySchema);
@@ -0,0 +1,23 @@
1
+ const mongoose = require('mongoose');
2
+
3
+ const storeRateSchema = new mongoose.Schema(
4
+ {
5
+ userId: {
6
+ type: mongoose.Schema.Types.ObjectId,
7
+ required: true,
8
+ ref: 'User',
9
+ },
10
+ storeId: {
11
+ type: mongoose.Schema.Types.ObjectId,
12
+ required: true,
13
+ ref: 'User',
14
+ },
15
+ rate: {
16
+ type: Number,
17
+ default: 0,
18
+ },
19
+ },
20
+ { toJSON: { virtuals: true } }
21
+ );
22
+
23
+ module.exports = mongoose.model('StoreRate', storeRateSchema);
@@ -0,0 +1,129 @@
1
+ const mongoose = require('mongoose');
2
+
3
+ const subscriptionSchema = new mongoose.Schema(
4
+ {
5
+ paymentManagerId: {
6
+ type: mongoose.Schema.Types.ObjectId,
7
+ required: false,
8
+ ref: 'User',
9
+ },
10
+ storeId: {
11
+ type: mongoose.Schema.Types.ObjectId,
12
+ required: true,
13
+ ref: 'Store',
14
+ },
15
+ planId: {
16
+ type: mongoose.Schema.Types.ObjectId,
17
+ required: false,
18
+ ref: 'Plan',
19
+ },
20
+ subscriptionOfferId: {
21
+ type: mongoose.Schema.Types.ObjectId,
22
+ required: false,
23
+ ref: 'SubscriptionOffer',
24
+ },
25
+ paymentAmount: {
26
+ type: Number,
27
+ required: true,
28
+ },
29
+ paymentTypeId: {
30
+ type: mongoose.Schema.Types.ObjectId,
31
+ required: false,
32
+ ref: 'PaymentType',
33
+ },
34
+ reductionOfferId: {
35
+ type: mongoose.Schema.Types.ObjectId,
36
+ required: false,
37
+ ref: 'ReductionOffer',
38
+ },
39
+ status: {
40
+ type: String,
41
+ enum: ['inactive', 'active', 'delayed', 'suspended', 'upcoming', 'deleted'],
42
+ default: 'inactive',
43
+ },
44
+ startDate: {
45
+ type: Date,
46
+ required: true,
47
+ },
48
+ endDate: {
49
+ type: Date,
50
+ required: true,
51
+ },
52
+ notes: [{ type: String }],
53
+ subscriptionsHistory: [
54
+ {
55
+ paymentManagerId: {
56
+ type: mongoose.Schema.Types.ObjectId,
57
+ required: true,
58
+ ref: 'User',
59
+ },
60
+ planId: {
61
+ type: mongoose.Schema.Types.ObjectId,
62
+ required: true,
63
+ ref: 'Plan',
64
+ },
65
+ subscriptionOfferId: {
66
+ type: mongoose.Schema.Types.ObjectId,
67
+ required: false,
68
+ ref: 'SubscriptionOffer',
69
+ },
70
+ paymentAmount: {
71
+ type: Number,
72
+ required: true,
73
+ },
74
+ status: {
75
+ type: String,
76
+ default: 'suspended',
77
+ },
78
+ startDate: {
79
+ type: Date,
80
+ required: true,
81
+ },
82
+ endDate: {
83
+ type: Date,
84
+ required: true,
85
+ },
86
+ notes: [{ type: String }],
87
+ },
88
+ ],
89
+ upcomingSubscriptions: [
90
+ {
91
+ paymentManagerId: {
92
+ type: mongoose.Schema.Types.ObjectId,
93
+ required: true,
94
+ ref: 'User',
95
+ },
96
+ planId: {
97
+ type: mongoose.Schema.Types.ObjectId,
98
+ required: true,
99
+ ref: 'Plan',
100
+ },
101
+ subscriptionOfferId: {
102
+ type: mongoose.Schema.Types.ObjectId,
103
+ required: false,
104
+ ref: 'SubscriptionOffer',
105
+ },
106
+ paymentAmount: {
107
+ type: Number,
108
+ required: true,
109
+ },
110
+ status: {
111
+ type: String,
112
+ default: 'upcoming',
113
+ },
114
+ startDate: {
115
+ type: Date,
116
+ required: true,
117
+ },
118
+ endDate: {
119
+ type: Date,
120
+ required: true,
121
+ },
122
+ notes: [{ type: String }],
123
+ },
124
+ ],
125
+ },
126
+ { toJSON: { virtuals: true } }
127
+ );
128
+
129
+ module.exports = mongoose.model('Subscription', subscriptionSchema);
@@ -0,0 +1,18 @@
1
+ const mongoose = require('mongoose');
2
+
3
+ const subscriptionOfferSchema = new mongoose.Schema(
4
+ {
5
+ discount: {
6
+ type: Number,
7
+ required: true,
8
+ },
9
+ isActive: {
10
+ type: Boolean,
11
+ required: true,
12
+ default: false,
13
+ },
14
+ },
15
+ { timestamps: true }
16
+ );
17
+
18
+ module.exports = mongoose.model('SubscriptionOffer', subscriptionOfferSchema);
package/models/User.js ADDED
@@ -0,0 +1,211 @@
1
+ const mongoose = require('mongoose');
2
+ const { policySchema } = require('./Policy');
3
+ var ObjectId = require('mongodb').ObjectID;
4
+
5
+ const userSchema = new mongoose.Schema(
6
+ {
7
+ password: {
8
+ type: String,
9
+ required: [true, 'Please provide a password'],
10
+ minlength: 8,
11
+ validate(value) {
12
+ if (!value.match(/\d/) || !value.match(/[a-zA-Z]/)) {
13
+ throw new Error('Password must contain at least one letter and one number');
14
+ }
15
+ },
16
+ },
17
+ username: {
18
+ type: String,
19
+ unique: true,
20
+ },
21
+ role: {
22
+ type: String,
23
+ enum: ['user', 'admin', 'seller', 'paymentManager','manager','SuperManager'],
24
+ default: 'user',
25
+ },
26
+ isAdmin: { type: Boolean, default: false },
27
+ companyName: {
28
+ type: String,
29
+ },
30
+ phone: {
31
+ type: String,
32
+ default: null,
33
+ },
34
+
35
+ verificationCode: {
36
+ type: String,
37
+ },
38
+ isVerified: {
39
+ type: Boolean,
40
+ default: false,
41
+ },
42
+ welcome: {
43
+ type: Boolean,
44
+ default: false,
45
+ },
46
+ profileImage: {
47
+ type: String,
48
+ },
49
+ discountCode: {
50
+ type: String,
51
+ },
52
+ email: {
53
+ type: String,
54
+ default: null,
55
+ },
56
+ favouritsProductst: [
57
+ {
58
+ productId: { type: String },
59
+ },
60
+ ],
61
+ adresse: {
62
+ latitude: { type: Number },
63
+ longitude: { type: Number },
64
+ countryCode: { type: String },
65
+ country: { type: String },
66
+ city: { type: String },
67
+ postalCode: { type: String },
68
+ locality: { type: String },
69
+ apartmentNumber: { type: String },
70
+ streetName: { type: String },
71
+ region: { type: String },
72
+ fullAddress: { type: String },
73
+ },
74
+ policy: policySchema,
75
+ shippingAdress: {
76
+ countryCode: { type: String },
77
+ country: { type: String },
78
+ city: { type: String },
79
+ postalCode: { type: String },
80
+ locality: { type: String },
81
+ apartmentNumber: { type: String },
82
+ streetName: { type: String },
83
+ region: { type: String },
84
+ fullAddress: { type: String },
85
+ },
86
+ proximityRange: {
87
+ type: Number,
88
+ default: 20,
89
+ },
90
+ storeCategorieIds: [
91
+ {
92
+ type: mongoose.Schema.Types.ObjectId,
93
+ ref: 'StoreCategory',
94
+ },
95
+ ],
96
+ productCategorieIds: [
97
+ {
98
+ categoryId: {
99
+ type: mongoose.Schema.Types.ObjectId,
100
+ ref: 'Category',
101
+ },
102
+ subCategories: [
103
+ {
104
+ type: mongoose.Schema.Types.ObjectId,
105
+ ref: 'Category.subCategories',
106
+ },
107
+ ],
108
+ },
109
+ ],
110
+ tags: [
111
+ {
112
+ name: {
113
+ type: String,
114
+ required: true,
115
+ },
116
+ },
117
+ ],
118
+ notification: {
119
+ orderNotifications: { type: Boolean, default: null },
120
+ offerNotification: { type: Boolean, default: null },
121
+ mail: { type: Boolean, default: null },
122
+ sms: { type: Boolean, default: null },
123
+ platforme: { type: Boolean, default: null },
124
+ popup: { type: Boolean, default: null },
125
+ vibration: { type: Boolean, default: null },
126
+ ringing: { type: Boolean, default: null },
127
+ },
128
+
129
+ pickupPersons: [
130
+ {
131
+ type: {
132
+ name: { type: String, required: true },
133
+ },
134
+ },
135
+ ],
136
+ addresses: [
137
+ {
138
+ type: {
139
+ deliveryLocation: {
140
+ type: {
141
+ type: String,
142
+ enum: ['Point'],
143
+ },
144
+ coordinates: [
145
+ {
146
+ type: Number,
147
+ },
148
+ {
149
+ type: Number,
150
+ },
151
+ ],
152
+ },
153
+ deliveryAddresse: {
154
+ city: {
155
+ type: String,
156
+ // required: true,
157
+ },
158
+ streetName: {
159
+ type: String,
160
+ //required: true,
161
+ },
162
+ postalCode: {
163
+ type: String,
164
+ //required: true,
165
+ },
166
+ country: {
167
+ type: String,
168
+ //required: true,
169
+ },
170
+ fullAdress: {
171
+ type: String,
172
+ //required: true,
173
+ },
174
+ region: {
175
+ type: String,
176
+ //required: true,
177
+ },
178
+ countryCode: {
179
+ type: String,
180
+ //required: true,
181
+ },
182
+ phone: {
183
+ type: String,
184
+ //required: true,
185
+ },
186
+ },
187
+ },
188
+ },
189
+ ],
190
+ cards: [
191
+ {
192
+ type: {
193
+ cardNumber: { type: String, default: null },
194
+ ccv: { type: String, default: null },
195
+ expdate: { type: String, default: null },
196
+ name: { type: String, required: true },
197
+ phone: { type: String, required: true },
198
+ postalCode: { type: String, required: true },
199
+ address_city: { type: String, required: true },
200
+ address_line1: { type: String, required: true },
201
+ address_line2: { type: String, default: '' },
202
+ },
203
+ },
204
+ ],
205
+ },
206
+
207
+ { timestamps: true }
208
+ );
209
+
210
+ userSchema.index({ username: 1 }, { unique: true });
211
+ module.exports = mongoose.model('User', userSchema);
package/models/View.js ADDED
@@ -0,0 +1,13 @@
1
+ const mongoose = require('mongoose');
2
+
3
+ const viewsSchema = new mongoose.Schema({
4
+ sellerId: { type: mongoose.Schema.Types.ObjectId, ref: 'Seller' },
5
+ storeId: { type: mongoose.Schema.Types.ObjectId, ref: 'Store' },
6
+ productId: { type: mongoose.Schema.Types.ObjectId, ref: 'Product' },
7
+ date: { type: Date, required: true },
8
+ region: { type: String }, // If you want to track region for each view
9
+ });
10
+
11
+ module.exports = mongoose.model('View', viewsSchema);
12
+
13
+
@@ -0,0 +1,35 @@
1
+ const mongoose = require('mongoose');
2
+
3
+ const connectToDatabase = async (databaseUrl) => {
4
+ try {
5
+ await mongoose.connect(databaseUrl, {
6
+ useNewUrlParser: true,
7
+ useUnifiedTopology: true,
8
+ });
9
+ console.log('Connected to the database successfully.');
10
+ } catch (error) {
11
+ console.error('Failed to connect to the database:', error.message);
12
+ throw error;
13
+ }
14
+ };
15
+
16
+
17
+
18
+
19
+ module.exports = require('./Cart');
20
+ module.exports = require('./Product');
21
+ module.exports = require('./View');
22
+ module.exports = require('./User');
23
+ module.exports = require('./Order');
24
+ module.exports = require('./Bill');
25
+ module.exports = require('./Payment');
26
+ module.exports = require('./Store');
27
+ module.exports = require('./Offer');
28
+ module.exports = require('./Category');
29
+ module.exports = require('./ResetPassword');
30
+ module.exports = require('./StoreRate');
31
+ module.exports = require('./Subscription');
32
+ module.exports = require('./Plan');
33
+ module.exports = require('./SubscriptionOffer');
34
+ module.exports.connectToDatabase = connectToDatabase;
35
+
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "database-connector",
3
+ "version": "1.0.0",
4
+ "main": "models/index.js",
5
+ "scripts": {
6
+ "test": "echo \"Error: no test specified\" && exit 1"
7
+ },
8
+ "keywords": [],
9
+ "author": "",
10
+ "license": "ISC",
11
+ "description": "",
12
+ "dependencies": {
13
+ "mongoose": "^8.9.3"
14
+ }
15
+ }