database-connector 1.0.6 → 1.0.7
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.
- package/models/Cart.js +0 -2
- package/models/Category.js +4 -7
- package/models/FlashDeal.js +1 -1
- package/models/Offer.js +4 -5
- package/models/Order.js +89 -87
- package/models/Product.js +18 -18
- package/models/Store.js +5 -5
- package/models/User.js +8 -2
- package/models/UserAction.js +33 -0
- package/models/View.js +2 -1
- package/models/index.js +4 -3
- package/package.json +1 -1
package/models/Cart.js
CHANGED
package/models/Category.js
CHANGED
|
@@ -1,26 +1,23 @@
|
|
|
1
1
|
const mongoose = require('mongoose');
|
|
2
|
-
const Product = require('./Product');
|
|
3
2
|
|
|
4
3
|
const categorySchema = new mongoose.Schema(
|
|
5
4
|
{
|
|
6
|
-
storeCategoryId
|
|
5
|
+
storeCategoryId: {
|
|
7
6
|
type: mongoose.Schema.Types.ObjectId,
|
|
8
7
|
ref: 'StoreCategory',
|
|
9
|
-
}
|
|
8
|
+
},
|
|
10
9
|
name: {
|
|
11
10
|
type: String,
|
|
12
11
|
required: true,
|
|
13
12
|
},
|
|
14
|
-
|
|
15
|
-
confirmed : { type : Boolean , default : false } ,
|
|
16
|
-
|
|
13
|
+
confirmed: { type: Boolean, default: false },
|
|
17
14
|
subCategories: [
|
|
18
15
|
{
|
|
19
16
|
name: {
|
|
20
17
|
type: String,
|
|
21
18
|
required: true,
|
|
22
19
|
},
|
|
23
|
-
confirmed
|
|
20
|
+
confirmed: { type: Boolean, default: false },
|
|
24
21
|
},
|
|
25
22
|
{
|
|
26
23
|
timestamps: true,
|
package/models/FlashDeal.js
CHANGED
package/models/Offer.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const { Timestamp } = require('mongodb');
|
|
2
2
|
const mongoose = require('mongoose');
|
|
3
|
-
const User = require('./User');
|
|
4
3
|
|
|
5
4
|
const OfferSchema = new mongoose.Schema(
|
|
6
5
|
{
|
|
@@ -31,12 +30,12 @@ const OfferSchema = new mongoose.Schema(
|
|
|
31
30
|
},
|
|
32
31
|
offerExpiration: {
|
|
33
32
|
type: Date,
|
|
34
|
-
|
|
33
|
+
|
|
35
34
|
default: Date.now() + 86400000,
|
|
36
35
|
},
|
|
37
36
|
offerStatus: {
|
|
38
37
|
type: String,
|
|
39
|
-
default:'active',
|
|
38
|
+
default: 'active',
|
|
40
39
|
|
|
41
40
|
enum: ['pending', 'active', 'rejected', 'expired'],
|
|
42
41
|
},
|
|
@@ -47,7 +46,7 @@ const OfferSchema = new mongoose.Schema(
|
|
|
47
46
|
},
|
|
48
47
|
offerName: {
|
|
49
48
|
type: String,
|
|
50
|
-
|
|
49
|
+
|
|
51
50
|
},
|
|
52
51
|
offerImage: {
|
|
53
52
|
type: String,
|
|
@@ -55,7 +54,7 @@ const OfferSchema = new mongoose.Schema(
|
|
|
55
54
|
},
|
|
56
55
|
offerDescription: {
|
|
57
56
|
type: String,
|
|
58
|
-
|
|
57
|
+
|
|
59
58
|
},
|
|
60
59
|
discountType: {
|
|
61
60
|
type: String,
|
package/models/Order.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const mongoose = require('mongoose');
|
|
2
|
-
var ObjectId = require('mongodb').ObjectID;
|
|
3
2
|
const Sale = require('./Sale');
|
|
4
3
|
|
|
5
4
|
const { policySchema } = require('./Policy');
|
|
@@ -15,13 +14,13 @@ const orderSchema = new mongoose.Schema(
|
|
|
15
14
|
required: true,
|
|
16
15
|
ref: 'Store',
|
|
17
16
|
},
|
|
18
|
-
pickupPerson
|
|
19
|
-
type
|
|
20
|
-
name
|
|
21
|
-
}
|
|
22
|
-
default
|
|
23
|
-
}
|
|
24
|
-
deliveryLocation
|
|
17
|
+
pickupPerson: {
|
|
18
|
+
type: {
|
|
19
|
+
name: { type: String, required: true },
|
|
20
|
+
},
|
|
21
|
+
default: null
|
|
22
|
+
},
|
|
23
|
+
deliveryLocation: {
|
|
25
24
|
type: {
|
|
26
25
|
type: String,
|
|
27
26
|
enum: ['Point'],
|
|
@@ -35,7 +34,7 @@ const orderSchema = new mongoose.Schema(
|
|
|
35
34
|
},
|
|
36
35
|
],
|
|
37
36
|
},
|
|
38
|
-
deliveryAddresse
|
|
37
|
+
deliveryAddresse: {
|
|
39
38
|
city: {
|
|
40
39
|
type: String,
|
|
41
40
|
// required: true,
|
|
@@ -69,9 +68,9 @@ const orderSchema = new mongoose.Schema(
|
|
|
69
68
|
//required: true,
|
|
70
69
|
},
|
|
71
70
|
},
|
|
72
|
-
distance
|
|
73
|
-
type
|
|
74
|
-
}
|
|
71
|
+
distance: {
|
|
72
|
+
type: Number, default: null
|
|
73
|
+
},
|
|
75
74
|
items: [
|
|
76
75
|
{
|
|
77
76
|
productId: { type: String, required: true },
|
|
@@ -80,29 +79,29 @@ const orderSchema = new mongoose.Schema(
|
|
|
80
79
|
image: { type: String, required: true },
|
|
81
80
|
price: { type: Number, required: true },
|
|
82
81
|
discount: { type: Number, required: true },
|
|
83
|
-
reservation: { type: Number},
|
|
82
|
+
reservation: { type: Number },
|
|
84
83
|
quantity: { type: Number, required: true, default: 1 },
|
|
85
84
|
policy: policySchema,
|
|
86
85
|
|
|
87
|
-
refund
|
|
88
|
-
order
|
|
89
|
-
fixe
|
|
90
|
-
percentage
|
|
91
|
-
}
|
|
92
|
-
shipping
|
|
93
|
-
fixe
|
|
94
|
-
percentage
|
|
86
|
+
refund: {
|
|
87
|
+
order: {
|
|
88
|
+
fixe: { type: Number, default: null },
|
|
89
|
+
percentage: { type: Number, default: null },
|
|
90
|
+
},
|
|
91
|
+
shipping: {
|
|
92
|
+
fixe: { type: Number, default: null },
|
|
93
|
+
percentage: { type: Number, default: null },
|
|
95
94
|
},
|
|
96
|
-
}
|
|
97
|
-
|
|
95
|
+
},
|
|
96
|
+
|
|
98
97
|
},
|
|
99
98
|
{
|
|
100
99
|
timestamps: true,
|
|
101
100
|
},
|
|
102
101
|
],
|
|
103
102
|
|
|
104
|
-
|
|
105
|
-
return
|
|
103
|
+
|
|
104
|
+
return: { type: Boolean, default: null },
|
|
106
105
|
|
|
107
106
|
returnItems: [
|
|
108
107
|
{
|
|
@@ -114,7 +113,7 @@ const orderSchema = new mongoose.Schema(
|
|
|
114
113
|
discount: { type: Number, required: true },
|
|
115
114
|
quantity: { type: Number, required: true, default: 1 },
|
|
116
115
|
orderQuantity: { type: Number, required: true, default: 1 },
|
|
117
|
-
policy: policySchema,
|
|
116
|
+
policy: policySchema,
|
|
118
117
|
},
|
|
119
118
|
{
|
|
120
119
|
timestamps: true,
|
|
@@ -131,88 +130,91 @@ const orderSchema = new mongoose.Schema(
|
|
|
131
130
|
discount: { type: Number, required: true },
|
|
132
131
|
quantity: { type: Number, required: true, default: 1 },
|
|
133
132
|
orderQuantity: { type: Number, required: true, default: 1 },
|
|
134
|
-
policy: policySchema,
|
|
133
|
+
policy: policySchema,
|
|
135
134
|
},
|
|
136
135
|
{
|
|
137
136
|
timestamps: true,
|
|
138
137
|
},
|
|
139
138
|
],
|
|
140
139
|
|
|
141
|
-
refundPaymentInfos
|
|
142
|
-
type
|
|
140
|
+
refundPaymentInfos: {
|
|
141
|
+
type: {
|
|
143
142
|
totalAmount: { type: Number, required: true },
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
default
|
|
147
|
-
}
|
|
148
|
-
returnMotif
|
|
149
|
-
|
|
150
|
-
waitingforReturn
|
|
151
|
-
|
|
152
|
-
returned
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
paymentInfos
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
default: null
|
|
146
|
+
},
|
|
147
|
+
returnMotif: { type: String, default: null },
|
|
148
|
+
|
|
149
|
+
waitingforReturn: { type: Boolean, default: null },
|
|
150
|
+
|
|
151
|
+
returned: { type: Boolean, default: null },
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
paymentInfos: {
|
|
156
155
|
totalAmount: { type: Number, required: true },
|
|
157
156
|
paymentMethodeId: { type: Number, required: true, },
|
|
158
|
-
card
|
|
159
|
-
cardNumber
|
|
160
|
-
ccv: { type: String, default
|
|
161
|
-
expdate: { type: String, default
|
|
157
|
+
card: {
|
|
158
|
+
cardNumber: { type: String, default: null },
|
|
159
|
+
ccv: { type: String, default: null },
|
|
160
|
+
expdate: { type: String, default: null },
|
|
162
161
|
name: { type: String, required: true },
|
|
163
162
|
phone: { type: String, required: true },
|
|
164
163
|
postalCode: { type: String, required: true },
|
|
165
164
|
address_city: { type: String, required: true },
|
|
166
165
|
address_line1: { type: String, required: true },
|
|
167
|
-
address_line2: { type: String, default: ""},
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
pickUp
|
|
171
|
-
delivery
|
|
172
|
-
|
|
173
|
-
refund
|
|
174
|
-
|
|
175
|
-
timeLimit
|
|
176
|
-
|
|
177
|
-
canceled
|
|
178
|
-
canceledBy
|
|
166
|
+
address_line2: { type: String, default: "" },
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
pickUp: { type: Boolean, required: true, default: null },
|
|
170
|
+
delivery: { type: Boolean, required: true, default: null },
|
|
171
|
+
|
|
172
|
+
refund: { type: Boolean, default: null },
|
|
173
|
+
|
|
174
|
+
timeLimit: { type: Number, default: null },
|
|
175
|
+
|
|
176
|
+
canceled: { type: Boolean, default: null },
|
|
177
|
+
canceledBy: {
|
|
179
178
|
userId: { type: mongoose.Schema.Types.ObjectId },
|
|
180
179
|
motif: { type: String },
|
|
181
|
-
}
|
|
182
|
-
status: {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
180
|
+
},
|
|
181
|
+
status: {
|
|
182
|
+
type: String, required: true, enum: [
|
|
183
|
+
'Pending',
|
|
184
|
+
'InPreparation',
|
|
185
|
+
'LoadingDelivery',
|
|
186
|
+
'OnTheWay',
|
|
187
|
+
'Delivered',
|
|
188
|
+
'AwaitingRecovery',
|
|
189
|
+
'Recovered',
|
|
190
|
+
'Reserved',
|
|
191
|
+
'WaitingForReturn',
|
|
192
|
+
'Returned',
|
|
193
|
+
'UnderRefund',
|
|
194
|
+
'Refunded',
|
|
195
|
+
'succeeded'
|
|
196
|
+
], default: 'Pending'
|
|
197
|
+
},
|
|
197
198
|
},
|
|
198
199
|
{ timestamps: true }
|
|
199
200
|
);
|
|
200
201
|
orderSchema.post('save', async function (doc) {
|
|
201
202
|
try {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
203
|
+
// Create a new Sale document for each item in the order
|
|
204
|
+
for (const item of doc.items) {
|
|
205
|
+
const newSale = new Sale({
|
|
206
|
+
sellerId: doc.sellerId, // Replace with the actual sellerId
|
|
207
|
+
storeId: doc.storeId, // Replace with the actual storeId
|
|
208
|
+
productId: item.productId,
|
|
209
|
+
date: doc.createdAt,
|
|
210
|
+
region: doc.deliveryAddresse.city
|
|
211
|
+
} // Replace with the actual region field from the order
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
await newSale.save();
|
|
215
|
+
}
|
|
214
216
|
} catch (error) {
|
|
215
|
-
|
|
217
|
+
console.error('Error creating sale records:', error);
|
|
216
218
|
}
|
|
217
|
-
|
|
219
|
+
});
|
|
218
220
|
module.exports = mongoose.model('Order', orderSchema);
|
package/models/Product.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const mongoose = require('mongoose');
|
|
2
|
-
const { policySchema } = require('
|
|
2
|
+
const { policySchema } = require('database-connector/models/Policy');
|
|
3
3
|
var ObjectId = require('mongodb').ObjectID;
|
|
4
4
|
|
|
5
5
|
const productSchema = new mongoose.Schema(
|
|
@@ -10,11 +10,11 @@ const productSchema = new mongoose.Schema(
|
|
|
10
10
|
},
|
|
11
11
|
description: { type: String, required: true },
|
|
12
12
|
price: { type: Number, required: true },
|
|
13
|
-
storeCategoryId
|
|
13
|
+
storeCategoryId: {
|
|
14
14
|
type: mongoose.Schema.Types.ObjectId,
|
|
15
15
|
ref: 'StoreCategory',
|
|
16
16
|
required: true,
|
|
17
|
-
}
|
|
17
|
+
},
|
|
18
18
|
categoryId: {
|
|
19
19
|
type: mongoose.Schema.Types.ObjectId,
|
|
20
20
|
ref: 'Category',
|
|
@@ -98,24 +98,24 @@ const productSchema = new mongoose.Schema(
|
|
|
98
98
|
type: mongoose.Schema.Types.ObjectId,
|
|
99
99
|
ref: 'Offer',
|
|
100
100
|
},
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
|
|
102
|
+
|
|
103
103
|
numberOfSales: {
|
|
104
104
|
type: Number,
|
|
105
105
|
default: 0,
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
},
|
|
107
|
+
numberOfViews: {
|
|
108
108
|
type: Number,
|
|
109
109
|
default: 0,
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
},
|
|
111
|
+
numberOfSearches: {
|
|
112
112
|
type: Number,
|
|
113
113
|
default: 0,
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
},
|
|
115
|
+
averageRating: {
|
|
116
116
|
type: Number,
|
|
117
117
|
default: 0,
|
|
118
|
-
|
|
118
|
+
},
|
|
119
119
|
|
|
120
120
|
reports: [
|
|
121
121
|
{
|
|
@@ -135,7 +135,7 @@ const productSchema = new mongoose.Schema(
|
|
|
135
135
|
policy: policySchema,
|
|
136
136
|
},
|
|
137
137
|
{
|
|
138
|
-
|
|
138
|
+
timestamps: true,
|
|
139
139
|
toJSON: { virtuals: true },
|
|
140
140
|
}
|
|
141
141
|
);/*
|
|
@@ -172,13 +172,13 @@ productSchema.virtual('imagesss').get(function () {
|
|
|
172
172
|
productSchema.virtual('discounted').get(function () {
|
|
173
173
|
if (this.offer) {
|
|
174
174
|
console.log('Disount')
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
175
|
+
|
|
176
|
+
return this.offer.discount;
|
|
177
|
+
|
|
178
178
|
} else {
|
|
179
|
-
|
|
179
|
+
return this.price;
|
|
180
180
|
}
|
|
181
|
-
|
|
181
|
+
});
|
|
182
182
|
//virtual array for all the images of the variants
|
|
183
183
|
productSchema.virtual('variantImages').get(function () {
|
|
184
184
|
if (this.variants != null) {
|
package/models/Store.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const mongoose = require('mongoose');
|
|
2
|
-
const User = require('
|
|
3
|
-
const Product = require('
|
|
4
|
-
const { policySchema } = require('
|
|
2
|
+
const User = require('database-connector/models/User');
|
|
3
|
+
const Product = require('database-connector/models/Product');
|
|
4
|
+
const { policySchema } = require('database-connector/models/Policy');
|
|
5
5
|
var ObjectId = require('mongodb').ObjectID;
|
|
6
6
|
|
|
7
7
|
const storeSchema = new mongoose.Schema(
|
|
@@ -237,8 +237,8 @@ const storeSchema = new mongoose.Schema(
|
|
|
237
237
|
ref: 'Subscription',
|
|
238
238
|
},
|
|
239
239
|
},
|
|
240
|
-
|
|
241
|
-
|
|
240
|
+
|
|
241
|
+
{ timestamps: true, toJSON: { virtuals: true } }
|
|
242
242
|
);
|
|
243
243
|
//virtual image url
|
|
244
244
|
storeSchema.virtual('imageUrl').get(function () {
|
package/models/User.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const mongoose = require('mongoose');
|
|
2
|
-
const { policySchema } = require('
|
|
2
|
+
const { policySchema } = require('database-connector/models/Policy');
|
|
3
3
|
var ObjectId = require('mongodb').ObjectID;
|
|
4
4
|
|
|
5
5
|
const userSchema = new mongoose.Schema(
|
|
@@ -20,7 +20,7 @@ const userSchema = new mongoose.Schema(
|
|
|
20
20
|
},
|
|
21
21
|
role: {
|
|
22
22
|
type: String,
|
|
23
|
-
enum: ['user', 'admin', 'seller', 'paymentManager','manager','SuperManager'],
|
|
23
|
+
enum: ['user', 'admin', 'seller', 'paymentManager', 'manager', 'SuperManager'],
|
|
24
24
|
default: 'user',
|
|
25
25
|
},
|
|
26
26
|
isAdmin: { type: Boolean, default: false },
|
|
@@ -93,6 +93,12 @@ const userSchema = new mongoose.Schema(
|
|
|
93
93
|
ref: 'StoreCategory',
|
|
94
94
|
},
|
|
95
95
|
],
|
|
96
|
+
storeSubs: [
|
|
97
|
+
{
|
|
98
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
99
|
+
ref: 'Store',
|
|
100
|
+
},
|
|
101
|
+
],
|
|
96
102
|
productCategorieIds: [
|
|
97
103
|
{
|
|
98
104
|
categoryId: {
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
|
|
3
|
+
const UserActionSchema = new mongoose.Schema({
|
|
4
|
+
userId: {
|
|
5
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
6
|
+
ref: "User",
|
|
7
|
+
required: false
|
|
8
|
+
},
|
|
9
|
+
type: {
|
|
10
|
+
type: String,
|
|
11
|
+
required: true
|
|
12
|
+
},
|
|
13
|
+
deviceId: {
|
|
14
|
+
type: String,
|
|
15
|
+
required: false
|
|
16
|
+
},
|
|
17
|
+
sessionId: {
|
|
18
|
+
type: String,
|
|
19
|
+
required: false
|
|
20
|
+
},
|
|
21
|
+
details: {
|
|
22
|
+
type: mongoose.Schema.Types.Mixed,
|
|
23
|
+
required: false
|
|
24
|
+
},
|
|
25
|
+
timestamp: {
|
|
26
|
+
type: Date,
|
|
27
|
+
default: Date.now
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const UserAction = mongoose.model("UserAction", UserActionSchema);
|
|
32
|
+
|
|
33
|
+
module.exports = UserAction;
|
package/models/View.js
CHANGED
|
@@ -2,12 +2,13 @@ const mongoose = require('mongoose');
|
|
|
2
2
|
|
|
3
3
|
const viewsSchema = new mongoose.Schema({
|
|
4
4
|
sellerId: { type: mongoose.Schema.Types.ObjectId, ref: 'Seller' },
|
|
5
|
+
clientId: { type: mongoose.Schema.Types.ObjectId, ref: 'Client' },
|
|
5
6
|
storeId: { type: mongoose.Schema.Types.ObjectId, ref: 'Store' },
|
|
6
7
|
productId: { type: mongoose.Schema.Types.ObjectId, ref: 'Product' },
|
|
7
8
|
date: { type: Date, required: true },
|
|
8
9
|
region: { type: String }, // If you want to track region for each view
|
|
9
10
|
});
|
|
10
11
|
|
|
11
|
-
module.exports
|
|
12
|
+
module.exports = mongoose.model('View', viewsSchema);
|
|
12
13
|
|
|
13
14
|
|
package/models/index.js
CHANGED
|
@@ -31,11 +31,11 @@ const SubscriptionOffer = require('./SubscriptionOffer');
|
|
|
31
31
|
const FlashDeal = require('./FlashDeal');
|
|
32
32
|
const Notification = require('./Notification');
|
|
33
33
|
const PaymentType = require('./PaymentType');
|
|
34
|
-
const {policySchema} = require('./Policy');
|
|
34
|
+
const { policySchema } = require('./Policy');
|
|
35
35
|
const ReductionOffer = require('./ReductionOffer');
|
|
36
36
|
const Sale = require('./Sale');
|
|
37
37
|
const StoreCategory = require('./StoreCategory');
|
|
38
|
-
|
|
38
|
+
const UserAction = require('./UserAction.js');
|
|
39
39
|
|
|
40
40
|
|
|
41
41
|
module.exports = {
|
|
@@ -62,5 +62,6 @@ module.exports = {
|
|
|
62
62
|
Subscription,
|
|
63
63
|
Plan,
|
|
64
64
|
SubscriptionOffer,
|
|
65
|
-
|
|
65
|
+
UserAction,
|
|
66
|
+
ObjectId: mongoose.Types.ObjectId,
|
|
66
67
|
};
|