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.
- package/models/Bill.js +110 -0
- package/models/Cart.js +57 -0
- package/models/Category.js +33 -0
- package/models/FlashDeal.js +63 -0
- package/models/Notification.js +35 -0
- package/models/Offer.js +76 -0
- package/models/Order.js +217 -0
- package/models/OrderOld.js +74 -0
- package/models/Payment.js +117 -0
- package/models/PaymentType.js +14 -0
- package/models/Plan.js +42 -0
- package/models/Policy.js +94 -0
- package/models/Product.js +197 -0
- package/models/ReductionOffer.js +89 -0
- package/models/ResetPassword.js +23 -0
- package/models/Sale.js +11 -0
- package/models/Store.js +260 -0
- package/models/StoreCategory.js +15 -0
- package/models/StoreRate.js +23 -0
- package/models/Subscription.js +129 -0
- package/models/SubscriptionOffer.js +18 -0
- package/models/User.js +211 -0
- package/models/View.js +13 -0
- package/models/index.js +35 -0
- package/package.json +15 -0
package/models/Bill.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
const { Timestamp } = require('mongodb');
|
|
2
|
+
const mongoose = require('mongoose');
|
|
3
|
+
const BillSchema = 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: 'Store',
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
paymentId: {
|
|
17
|
+
type: String,
|
|
18
|
+
},
|
|
19
|
+
paymentMethod: {
|
|
20
|
+
type: String,
|
|
21
|
+
},
|
|
22
|
+
products: [
|
|
23
|
+
{
|
|
24
|
+
productId: { type: String, required: true },
|
|
25
|
+
variantId: { type: String, required: true },
|
|
26
|
+
quantity: { type: Number, required: true, default: 1 },
|
|
27
|
+
discountQuantity: { type: Number, required: true, default: 0 },
|
|
28
|
+
totalPrice: { type: Number, required: true },
|
|
29
|
+
discount: { type: Number, required: true },
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
timestamps: true,
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
origin: {
|
|
36
|
+
city: { type: String },
|
|
37
|
+
streetName: { type: String },
|
|
38
|
+
country: { type: String },
|
|
39
|
+
countryCode: { type: String },
|
|
40
|
+
postalCode: { type: String },
|
|
41
|
+
region: { type: String },
|
|
42
|
+
phone: { type: String },
|
|
43
|
+
fullAdress: { type: String },
|
|
44
|
+
street1: { type: String },
|
|
45
|
+
street2: { type: String },
|
|
46
|
+
},
|
|
47
|
+
billingAdress: {
|
|
48
|
+
city: { type: String },
|
|
49
|
+
streetName: { type: String },
|
|
50
|
+
country: { type: String },
|
|
51
|
+
countryCode: { type: String },
|
|
52
|
+
postalCode: { type: String },
|
|
53
|
+
region: { type: String },
|
|
54
|
+
phone: { type: String },
|
|
55
|
+
fullAdress: { type: String },
|
|
56
|
+
street1: { type: String },
|
|
57
|
+
street2: { type: String },
|
|
58
|
+
},
|
|
59
|
+
shippingStatus: {
|
|
60
|
+
type: String,
|
|
61
|
+
enum: ['none', 'pending', 'shipped', 'delivered'],
|
|
62
|
+
default: 'pending',
|
|
63
|
+
},
|
|
64
|
+
totalPrice: {
|
|
65
|
+
type: Number,
|
|
66
|
+
required: true,
|
|
67
|
+
},
|
|
68
|
+
discount: {
|
|
69
|
+
type: Number,
|
|
70
|
+
required: true,
|
|
71
|
+
},
|
|
72
|
+
paymentStatus: {
|
|
73
|
+
type: String,
|
|
74
|
+
enum: ['none', 'pending', 'succeeded', 'cancelled'],
|
|
75
|
+
default: 'pending',
|
|
76
|
+
},
|
|
77
|
+
refundStatus: {
|
|
78
|
+
type: String,
|
|
79
|
+
enum: ['none', 'pending', 'succeeded', 'cancelled'],
|
|
80
|
+
default: 'none',
|
|
81
|
+
},
|
|
82
|
+
payed: {
|
|
83
|
+
type: Number,
|
|
84
|
+
required: true,
|
|
85
|
+
default: 0,
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
timestamps: true,
|
|
90
|
+
toJSON: { virtuals: true },
|
|
91
|
+
}
|
|
92
|
+
);
|
|
93
|
+
BillSchema.virtual('needToBePay').get(function () {
|
|
94
|
+
if (this.paymentStatus === 'pending') {
|
|
95
|
+
return this.totalPrice;
|
|
96
|
+
} else if (this.paymentStatus === 'succeeded') {
|
|
97
|
+
return this.totalPrice - this.payed;
|
|
98
|
+
} else {
|
|
99
|
+
return 0;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
BillSchema.virtual('isPayed').get(function () {
|
|
103
|
+
if (this.paymentStatus === 'succeeded') {
|
|
104
|
+
return true;
|
|
105
|
+
} else {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
module.exports = mongoose.model('Bill', BillSchema);
|
package/models/Cart.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const { Schema, model } = require('mongoose');
|
|
2
|
+
const Product = require('./Product');
|
|
3
|
+
const User = require('./User');
|
|
4
|
+
|
|
5
|
+
const itemSchema = new Schema(
|
|
6
|
+
{
|
|
7
|
+
productId: { type: Schema.Types.ObjectId, ref: 'Product', required: true },
|
|
8
|
+
variantId: { type: String, required: true },
|
|
9
|
+
discount: { type: Number, default: 0 },
|
|
10
|
+
quantity: { type: Number, required: true, default: 1 },
|
|
11
|
+
discountQuantity: { type: Number, default: 0 },
|
|
12
|
+
//price: { type: Number, required: true },
|
|
13
|
+
//name: { type: String, required: true },
|
|
14
|
+
//image: { type: String, required: true, default: 'https://via.placeholder.com/150' },
|
|
15
|
+
totalPrice: { type: Number, required: true, default: 0 },
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
timestamps: true,
|
|
19
|
+
}
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
const cartSchema = new Schema(
|
|
23
|
+
{
|
|
24
|
+
userId: {
|
|
25
|
+
type: Schema.Types.ObjectId,
|
|
26
|
+
ref: 'User',
|
|
27
|
+
unique: true,
|
|
28
|
+
},
|
|
29
|
+
items: [itemSchema],
|
|
30
|
+
totalDiscount: {
|
|
31
|
+
type: Number,
|
|
32
|
+
required: true,
|
|
33
|
+
default: 0,
|
|
34
|
+
},
|
|
35
|
+
totalPayable: {
|
|
36
|
+
type: Number,
|
|
37
|
+
required: true,
|
|
38
|
+
default: 0,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
{ timestamps: true, toJSON: { virtuals: true } }
|
|
42
|
+
);
|
|
43
|
+
cartSchema.virtual('totaleQuantity').get(function () {
|
|
44
|
+
const items = this.items;
|
|
45
|
+
console.log(items);
|
|
46
|
+
return items.reduce(function (total, currentValue) {
|
|
47
|
+
return total + currentValue.quantity;
|
|
48
|
+
}, 0);
|
|
49
|
+
});
|
|
50
|
+
cartSchema.virtual('totalPriceForAllProducts').get(function () {
|
|
51
|
+
const items = this.items;
|
|
52
|
+
return items.reduce(function (total, currentValue) {
|
|
53
|
+
return total + currentValue.totalPrice;
|
|
54
|
+
}, 0);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
module.exports = model('Cart', cartSchema);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
const Product = require('./Product');
|
|
3
|
+
|
|
4
|
+
const categorySchema = new mongoose.Schema(
|
|
5
|
+
{
|
|
6
|
+
storeCategoryId : {
|
|
7
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
8
|
+
ref: 'StoreCategory',
|
|
9
|
+
} ,
|
|
10
|
+
name: {
|
|
11
|
+
type: String,
|
|
12
|
+
required: true,
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
confirmed : { type : Boolean , default : false } ,
|
|
16
|
+
|
|
17
|
+
subCategories: [
|
|
18
|
+
{
|
|
19
|
+
name: {
|
|
20
|
+
type: String,
|
|
21
|
+
required: true,
|
|
22
|
+
},
|
|
23
|
+
confirmed : { type : Boolean , default : false } ,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
timestamps: true,
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
{ timestamps: true, toJSON: { virtuals: true } }
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
module.exports = mongoose.model('Category', categorySchema);
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const { Timestamp } = require('mongodb');
|
|
2
|
+
const mongoose = require('mongoose');
|
|
3
|
+
const FlashDealSchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
name: {
|
|
6
|
+
type: String,
|
|
7
|
+
required: true,
|
|
8
|
+
},
|
|
9
|
+
description: {
|
|
10
|
+
type: String,
|
|
11
|
+
required: true,
|
|
12
|
+
},
|
|
13
|
+
image: {
|
|
14
|
+
type: String,
|
|
15
|
+
},
|
|
16
|
+
startDate: {
|
|
17
|
+
type: Date,
|
|
18
|
+
required: true,
|
|
19
|
+
default: Date.now(),
|
|
20
|
+
},
|
|
21
|
+
endDate: {
|
|
22
|
+
type: Date,
|
|
23
|
+
required: true,
|
|
24
|
+
default: Date.now() + 86400000,
|
|
25
|
+
},
|
|
26
|
+
discountType: {
|
|
27
|
+
type: String,
|
|
28
|
+
required: true,
|
|
29
|
+
enum: ['percentage', 'amount'],
|
|
30
|
+
default: 'percentage',
|
|
31
|
+
},
|
|
32
|
+
discount: {
|
|
33
|
+
type: Number,
|
|
34
|
+
required: true,
|
|
35
|
+
default: 0,
|
|
36
|
+
},
|
|
37
|
+
productIds: [
|
|
38
|
+
{
|
|
39
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
40
|
+
ref: 'Product',
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
discountCode: {
|
|
44
|
+
type: String,
|
|
45
|
+
required: true,
|
|
46
|
+
},
|
|
47
|
+
qauntiyFlashDeal: {
|
|
48
|
+
type: Number,
|
|
49
|
+
required: true,
|
|
50
|
+
default: 0,
|
|
51
|
+
},
|
|
52
|
+
active: {
|
|
53
|
+
type: Boolean,
|
|
54
|
+
required: true,
|
|
55
|
+
default: true,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
timestamps: true,
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
module.exports = mongoose.model('FlashDeal', FlashDealSchema);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const { Timestamp } = require('mongodb');
|
|
2
|
+
const mongoose = require('mongoose');
|
|
3
|
+
|
|
4
|
+
const NotificationSchema = new mongoose.Schema(
|
|
5
|
+
{
|
|
6
|
+
owner_id: {
|
|
7
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
8
|
+
ref: 'User',
|
|
9
|
+
required: true,
|
|
10
|
+
},
|
|
11
|
+
title: {type: String, required: true },
|
|
12
|
+
content: {type: String, required: true },
|
|
13
|
+
id: {type: String, required: true },
|
|
14
|
+
type: { type: String, required: true, enum: [
|
|
15
|
+
'order',
|
|
16
|
+
'offer',
|
|
17
|
+
], default: '' },
|
|
18
|
+
sub_type: { type: String, required: true, enum: [
|
|
19
|
+
'Delivery',
|
|
20
|
+
'Pickup',
|
|
21
|
+
'Reservation',
|
|
22
|
+
'Return',
|
|
23
|
+
'Refund',
|
|
24
|
+
'Cancel' ,
|
|
25
|
+
'offer',
|
|
26
|
+
'product'
|
|
27
|
+
], default: 'Cancel' },
|
|
28
|
+
seend : { type : Boolean , default : false } ,
|
|
29
|
+
seendInList : { type : Boolean , default : false }
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
{ timestamps: true }
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
module.exports = mongoose.model('Notification', NotificationSchema);
|
package/models/Offer.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const { Timestamp } = require('mongodb');
|
|
2
|
+
const mongoose = require('mongoose');
|
|
3
|
+
const User = require('./User');
|
|
4
|
+
|
|
5
|
+
const OfferSchema = new mongoose.Schema(
|
|
6
|
+
{
|
|
7
|
+
sellerId: {
|
|
8
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
9
|
+
ref: 'User',
|
|
10
|
+
required: true,
|
|
11
|
+
},
|
|
12
|
+
storeId: {
|
|
13
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
14
|
+
ref: 'Store',
|
|
15
|
+
required: true,
|
|
16
|
+
},
|
|
17
|
+
productId: {
|
|
18
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
19
|
+
ref: 'Product',
|
|
20
|
+
required: true,
|
|
21
|
+
},
|
|
22
|
+
offerDiscount: {
|
|
23
|
+
type: Number,
|
|
24
|
+
required: true,
|
|
25
|
+
default: 0,
|
|
26
|
+
},
|
|
27
|
+
offerStock: {
|
|
28
|
+
type: Number,
|
|
29
|
+
required: true,
|
|
30
|
+
default: 0,
|
|
31
|
+
},
|
|
32
|
+
offerExpiration: {
|
|
33
|
+
type: Date,
|
|
34
|
+
|
|
35
|
+
default: Date.now() + 86400000,
|
|
36
|
+
},
|
|
37
|
+
offerStatus: {
|
|
38
|
+
type: String,
|
|
39
|
+
default:'active',
|
|
40
|
+
|
|
41
|
+
enum: ['pending', 'active', 'rejected', 'expired'],
|
|
42
|
+
},
|
|
43
|
+
offerDeleted: {
|
|
44
|
+
type: Boolean,
|
|
45
|
+
required: true,
|
|
46
|
+
default: false,
|
|
47
|
+
},
|
|
48
|
+
offerName: {
|
|
49
|
+
type: String,
|
|
50
|
+
|
|
51
|
+
},
|
|
52
|
+
offerImage: {
|
|
53
|
+
type: String,
|
|
54
|
+
|
|
55
|
+
},
|
|
56
|
+
offerDescription: {
|
|
57
|
+
type: String,
|
|
58
|
+
|
|
59
|
+
},
|
|
60
|
+
discountType: {
|
|
61
|
+
type: String,
|
|
62
|
+
required: true,
|
|
63
|
+
enum: ['percentage', 'amount'],
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
timestamps: true,
|
|
68
|
+
toJSON: { virtuals: true },
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
OfferSchema.virtual('active').get(function () {
|
|
73
|
+
return this.offerExpiration > Date.now();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
module.exports = mongoose.model('Offer', OfferSchema);
|
package/models/Order.js
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
var ObjectId = require('mongodb').ObjectID;
|
|
3
|
+
|
|
4
|
+
const { policySchema } = require('./Policy');
|
|
5
|
+
const orderSchema = new mongoose.Schema(
|
|
6
|
+
{
|
|
7
|
+
clientId: {
|
|
8
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
9
|
+
required: true,
|
|
10
|
+
ref: 'User',
|
|
11
|
+
},
|
|
12
|
+
storeId: {
|
|
13
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
14
|
+
required: true,
|
|
15
|
+
ref: 'Store',
|
|
16
|
+
},
|
|
17
|
+
pickupPerson : {
|
|
18
|
+
type : {
|
|
19
|
+
name : {type : String, required: true } ,
|
|
20
|
+
} ,
|
|
21
|
+
default : null
|
|
22
|
+
} ,
|
|
23
|
+
deliveryLocation : {
|
|
24
|
+
type: {
|
|
25
|
+
type: String,
|
|
26
|
+
enum: ['Point'],
|
|
27
|
+
},
|
|
28
|
+
coordinates: [
|
|
29
|
+
{
|
|
30
|
+
type: Number,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
type: Number,
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
deliveryAddresse : {
|
|
38
|
+
city: {
|
|
39
|
+
type: String,
|
|
40
|
+
// required: true,
|
|
41
|
+
},
|
|
42
|
+
streetName: {
|
|
43
|
+
type: String,
|
|
44
|
+
//required: true,
|
|
45
|
+
},
|
|
46
|
+
postalCode: {
|
|
47
|
+
type: String,
|
|
48
|
+
//required: true,
|
|
49
|
+
},
|
|
50
|
+
country: {
|
|
51
|
+
type: String,
|
|
52
|
+
//required: true,
|
|
53
|
+
},
|
|
54
|
+
fullAdress: {
|
|
55
|
+
type: String,
|
|
56
|
+
//required: true,
|
|
57
|
+
},
|
|
58
|
+
region: {
|
|
59
|
+
type: String,
|
|
60
|
+
//required: true,
|
|
61
|
+
},
|
|
62
|
+
countryCode: {
|
|
63
|
+
type: String,
|
|
64
|
+
//required: true,
|
|
65
|
+
},
|
|
66
|
+
phone: {
|
|
67
|
+
type: String,
|
|
68
|
+
//required: true,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
distance : {
|
|
72
|
+
type : Number , default : null
|
|
73
|
+
} ,
|
|
74
|
+
items: [
|
|
75
|
+
{
|
|
76
|
+
productId: { type: String, required: true },
|
|
77
|
+
variantId: { type: String, required: true },
|
|
78
|
+
name: { type: String, required: true },
|
|
79
|
+
image: { type: String, required: true },
|
|
80
|
+
price: { type: Number, required: true },
|
|
81
|
+
discount: { type: Number, required: true },
|
|
82
|
+
reservation: { type: Number},
|
|
83
|
+
quantity: { type: Number, required: true, default: 1 },
|
|
84
|
+
policy: policySchema,
|
|
85
|
+
|
|
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} ,
|
|
94
|
+
},
|
|
95
|
+
} ,
|
|
96
|
+
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
timestamps: true,
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
return : { type : Boolean , default : null } ,
|
|
105
|
+
|
|
106
|
+
returnItems: [
|
|
107
|
+
{
|
|
108
|
+
productId: { type: String, required: true },
|
|
109
|
+
variantId: { type: String, required: true },
|
|
110
|
+
name: { type: String, required: true },
|
|
111
|
+
image: { type: String, required: true },
|
|
112
|
+
price: { type: Number, required: true },
|
|
113
|
+
discount: { type: Number, required: true },
|
|
114
|
+
quantity: { type: Number, required: true, default: 1 },
|
|
115
|
+
orderQuantity: { type: Number, required: true, default: 1 },
|
|
116
|
+
policy: policySchema,
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
timestamps: true,
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
|
|
123
|
+
returnedItems: [
|
|
124
|
+
{
|
|
125
|
+
productId: { type: String, required: true },
|
|
126
|
+
variantId: { type: String, required: true },
|
|
127
|
+
name: { type: String, required: true },
|
|
128
|
+
image: { type: String, required: true },
|
|
129
|
+
price: { type: Number, required: true },
|
|
130
|
+
discount: { type: Number, required: true },
|
|
131
|
+
quantity: { type: Number, required: true, default: 1 },
|
|
132
|
+
orderQuantity: { type: Number, required: true, default: 1 },
|
|
133
|
+
policy: policySchema,
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
timestamps: true,
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
|
|
140
|
+
refundPaymentInfos : {
|
|
141
|
+
type : {
|
|
142
|
+
totalAmount: { type: Number, required: true },
|
|
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 : {
|
|
155
|
+
totalAmount: { type: Number, required: true },
|
|
156
|
+
paymentMethodeId: { type: Number, required: true, },
|
|
157
|
+
card : {
|
|
158
|
+
cardNumber : { type: String, default : null },
|
|
159
|
+
ccv: { type: String, default : null },
|
|
160
|
+
expdate: { type: String, default : null},
|
|
161
|
+
name: { type: String, required: true },
|
|
162
|
+
phone: { type: String, required: true },
|
|
163
|
+
postalCode: { type: String, required: true },
|
|
164
|
+
address_city: { type: String, required: true },
|
|
165
|
+
address_line1: { type: String, required: true },
|
|
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 : {
|
|
178
|
+
userId: { type: mongoose.Schema.Types.ObjectId },
|
|
179
|
+
motif: { type: String },
|
|
180
|
+
} ,
|
|
181
|
+
status: { type: String, required: true, enum: [
|
|
182
|
+
'Pending',
|
|
183
|
+
'InPreparation',
|
|
184
|
+
'LoadingDelivery',
|
|
185
|
+
'OnTheWay',
|
|
186
|
+
'Delivered',
|
|
187
|
+
'AwaitingRecovery',
|
|
188
|
+
'Recovered',
|
|
189
|
+
'Reserved',
|
|
190
|
+
'WaitingForReturn',
|
|
191
|
+
'Returned',
|
|
192
|
+
'UnderRefund' ,
|
|
193
|
+
'Refunded',
|
|
194
|
+
'succeeded'
|
|
195
|
+
], default: 'Pending' },
|
|
196
|
+
},
|
|
197
|
+
{ timestamps: true }
|
|
198
|
+
);
|
|
199
|
+
orderSchema.post('save', async function (doc) {
|
|
200
|
+
try {
|
|
201
|
+
// Create a new Sale document for each item in the order
|
|
202
|
+
for (const item of doc.items) {
|
|
203
|
+
const newSale = new Sale({
|
|
204
|
+
sellerId: doc.sellerId, // Replace with the actual sellerId
|
|
205
|
+
storeId: doc.storeId, // Replace with the actual storeId
|
|
206
|
+
productId: item.productId,
|
|
207
|
+
date: doc.createdAt,
|
|
208
|
+
region: doc.deliveryAddresse.city} // Replace with the actual region field from the order
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
await newSale.save();
|
|
212
|
+
}
|
|
213
|
+
} catch (error) {
|
|
214
|
+
console.error('Error creating sale records:', error);
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
module.exports = mongoose.model('Order', orderSchema);
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
var ObjectId = require('mongodb').ObjectID;
|
|
3
|
+
|
|
4
|
+
const orderSchema = new mongoose.Schema(
|
|
5
|
+
{
|
|
6
|
+
userId: {
|
|
7
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
8
|
+
required: true,
|
|
9
|
+
ref: 'User',
|
|
10
|
+
},
|
|
11
|
+
storeId: {
|
|
12
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
13
|
+
required: true,
|
|
14
|
+
ref: 'Store',
|
|
15
|
+
},
|
|
16
|
+
billId: {
|
|
17
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
18
|
+
required: true,
|
|
19
|
+
ref: 'Bill',
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
clientSecret: {
|
|
23
|
+
type: String,
|
|
24
|
+
},
|
|
25
|
+
paymentId: {
|
|
26
|
+
type: String,
|
|
27
|
+
},
|
|
28
|
+
paymentMethod: {
|
|
29
|
+
type: String,
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
items: [
|
|
33
|
+
{
|
|
34
|
+
productId: { type: String, required: true },
|
|
35
|
+
variantId: { type: String, required: true },
|
|
36
|
+
quantity: { type: Number, required: true, default: 1 },
|
|
37
|
+
discountQuantity: { type: Number, required: true, default: 0 },
|
|
38
|
+
totalPrice: { type: Number, required: true },
|
|
39
|
+
discount: { type: Number, required: true },
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
timestamps: true,
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
|
|
46
|
+
origin: {
|
|
47
|
+
city: { type: String },
|
|
48
|
+
state: { type: String },
|
|
49
|
+
country: { type: String },
|
|
50
|
+
postalCode: { type: String },
|
|
51
|
+
phone: { type: String },
|
|
52
|
+
street1: { type: String },
|
|
53
|
+
street2: { type: String },
|
|
54
|
+
longitude: { type: Number },
|
|
55
|
+
latitude: { type: Number },
|
|
56
|
+
},
|
|
57
|
+
billingAdress: {
|
|
58
|
+
city: { type: String },
|
|
59
|
+
state: { type: String },
|
|
60
|
+
country: { type: String },
|
|
61
|
+
postalCode: { type: String },
|
|
62
|
+
phone: { type: String },
|
|
63
|
+
street1: { type: String },
|
|
64
|
+
street2: { type: String },
|
|
65
|
+
longitude: { type: Number },
|
|
66
|
+
latitude: { type: Number },
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
total: { type: Number, required: true, default: 0 },
|
|
70
|
+
status: { type: String, required: true, enum: ['pending', 'succeeded', 'cancelled', 'delivered'], default: 'pending' },
|
|
71
|
+
},
|
|
72
|
+
{ timestamps: true }
|
|
73
|
+
);
|
|
74
|
+
// module.exports = mongoose.model('Order', orderSchema);
|