database-connector 1.0.6 → 1.1.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/Offer.js CHANGED
@@ -1,7 +1,80 @@
1
- const { Timestamp } = require('mongodb');
2
1
  const mongoose = require('mongoose');
3
- const User = require('./User');
4
2
 
3
+ /**
4
+ * @swagger
5
+ * components:
6
+ * schemas:
7
+ * Offer:
8
+ * type: object
9
+ * required:
10
+ * - sellerId
11
+ * - storeId
12
+ * - productId
13
+ * - discountType
14
+ * properties:
15
+ * id:
16
+ * type: string
17
+ * description: The offer identifier
18
+ * sellerId:
19
+ * type: string
20
+ * description: Reference to the seller
21
+ * storeId:
22
+ * type: string
23
+ * description: Reference to the store
24
+ * productId:
25
+ * type: string
26
+ * description: Reference to the product
27
+ * offerDiscount:
28
+ * type: number
29
+ * default: 0
30
+ * description: Discount amount or percentage
31
+ * offerStock:
32
+ * type: number
33
+ * default: 0
34
+ * description: Stock available for this offer
35
+ * offerExpiration:
36
+ * type: string
37
+ * format: date-time
38
+ * description: Offer expiration date
39
+ * offerStatus:
40
+ * type: string
41
+ * enum: [pending, active, rejected, expired]
42
+ * default: active
43
+ * description: Status of the offer
44
+ * offerDeleted:
45
+ * type: boolean
46
+ * default: false
47
+ * description: Whether the offer is deleted
48
+ * offerName:
49
+ * type: string
50
+ * description: Offer name
51
+ * offerImage:
52
+ * type: string
53
+ * description: Offer image
54
+ * offerDescription:
55
+ * type: string
56
+ * description: Offer description
57
+ * discountType:
58
+ * type: string
59
+ * enum: [percentage, amount]
60
+ * description: Type of discount
61
+ * createdAt:
62
+ * type: string
63
+ * format: date-time
64
+ * updatedAt:
65
+ * type: string
66
+ * format: date-time
67
+ * example:
68
+ * id: "507f1f77bcf86cd799439011"
69
+ * sellerId: "507f1f77bcf86cd799439012"
70
+ * storeId: "507f1f77bcf86cd799439013"
71
+ * productId: "507f1f77bcf86cd799439014"
72
+ * offerDiscount: 25
73
+ * discountType: "percentage"
74
+ * offerStatus: "active"
75
+ * createdAt: "2025-12-07T10:30:00.000Z"
76
+ * updatedAt: "2025-12-07T10:30:00.000Z"
77
+ */
5
78
  const OfferSchema = new mongoose.Schema(
6
79
  {
7
80
  sellerId: {
@@ -31,12 +104,12 @@ const OfferSchema = new mongoose.Schema(
31
104
  },
32
105
  offerExpiration: {
33
106
  type: Date,
34
-
107
+
35
108
  default: Date.now() + 86400000,
36
109
  },
37
110
  offerStatus: {
38
111
  type: String,
39
- default:'active',
112
+ default: 'active',
40
113
 
41
114
  enum: ['pending', 'active', 'rejected', 'expired'],
42
115
  },
@@ -47,7 +120,7 @@ const OfferSchema = new mongoose.Schema(
47
120
  },
48
121
  offerName: {
49
122
  type: String,
50
-
123
+
51
124
  },
52
125
  offerImage: {
53
126
  type: String,
@@ -55,7 +128,7 @@ const OfferSchema = new mongoose.Schema(
55
128
  },
56
129
  offerDescription: {
57
130
  type: String,
58
-
131
+
59
132
  },
60
133
  discountType: {
61
134
  type: String,
package/models/Order.js CHANGED
@@ -1,8 +1,104 @@
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');
5
+
6
+ /**
7
+ * @swagger
8
+ * components:
9
+ * schemas:
10
+ * Order:
11
+ * type: object
12
+ * required:
13
+ * - clientId
14
+ * - storeId
15
+ * - items
16
+ * - paymentInfos
17
+ * - pickUp
18
+ * - delivery
19
+ * - status
20
+ * properties:
21
+ * id:
22
+ * type: string
23
+ * description: The order identifier
24
+ * clientId:
25
+ * type: string
26
+ * description: Reference to the client
27
+ * storeId:
28
+ * type: string
29
+ * description: Reference to the store
30
+ * pickupPerson:
31
+ * type: object
32
+ * properties:
33
+ * name:
34
+ * type: string
35
+ * deliveryAddresse:
36
+ * type: object
37
+ * properties:
38
+ * city:
39
+ * type: string
40
+ * streetName:
41
+ * type: string
42
+ * postalCode:
43
+ * type: string
44
+ * country:
45
+ * type: string
46
+ * region:
47
+ * type: string
48
+ * items:
49
+ * type: array
50
+ * items:
51
+ * type: object
52
+ * properties:
53
+ * productId:
54
+ * type: string
55
+ * variantId:
56
+ * type: string
57
+ * name:
58
+ * type: string
59
+ * price:
60
+ * type: number
61
+ * quantity:
62
+ * type: number
63
+ * discount:
64
+ * type: number
65
+ * paymentInfos:
66
+ * type: object
67
+ * properties:
68
+ * totalAmount:
69
+ * type: number
70
+ * paymentMethodeId:
71
+ * type: number
72
+ * pickUp:
73
+ * type: boolean
74
+ * description: Whether order is pickup
75
+ * delivery:
76
+ * type: boolean
77
+ * description: Whether order is delivery
78
+ * canceled:
79
+ * type: boolean
80
+ * description: Whether order is canceled
81
+ * status:
82
+ * type: string
83
+ * enum: [Pending, InPreparation, LoadingDelivery, OnTheWay, Delivered, AwaitingRecovery, Recovered, Reserved, WaitingForReturn, Returned, UnderRefund, Refunded, succeeded]
84
+ * default: Pending
85
+ * description: Order status
86
+ * createdAt:
87
+ * type: string
88
+ * format: date-time
89
+ * updatedAt:
90
+ * type: string
91
+ * format: date-time
92
+ * example:
93
+ * id: "507f1f77bcf86cd799439011"
94
+ * clientId: "507f1f77bcf86cd799439012"
95
+ * storeId: "507f1f77bcf86cd799439013"
96
+ * status: "Pending"
97
+ * pickUp: false
98
+ * delivery: true
99
+ * createdAt: "2025-12-07T10:30:00.000Z"
100
+ * updatedAt: "2025-12-07T10:30:00.000Z"
101
+ */
6
102
  const orderSchema = new mongoose.Schema(
7
103
  {
8
104
  clientId: {
@@ -15,13 +111,13 @@ const orderSchema = new mongoose.Schema(
15
111
  required: true,
16
112
  ref: 'Store',
17
113
  },
18
- pickupPerson : {
19
- type : {
20
- name : {type : String, required: true } ,
21
- } ,
22
- default : null
23
- } ,
24
- deliveryLocation : {
114
+ pickupPerson: {
115
+ type: {
116
+ name: { type: String, required: true },
117
+ },
118
+ default: null
119
+ },
120
+ deliveryLocation: {
25
121
  type: {
26
122
  type: String,
27
123
  enum: ['Point'],
@@ -35,7 +131,7 @@ const orderSchema = new mongoose.Schema(
35
131
  },
36
132
  ],
37
133
  },
38
- deliveryAddresse : {
134
+ deliveryAddresse: {
39
135
  city: {
40
136
  type: String,
41
137
  // required: true,
@@ -69,9 +165,9 @@ const orderSchema = new mongoose.Schema(
69
165
  //required: true,
70
166
  },
71
167
  },
72
- distance : {
73
- type : Number , default : null
74
- } ,
168
+ distance: {
169
+ type: Number, default: null
170
+ },
75
171
  items: [
76
172
  {
77
173
  productId: { type: String, required: true },
@@ -80,29 +176,29 @@ const orderSchema = new mongoose.Schema(
80
176
  image: { type: String, required: true },
81
177
  price: { type: Number, required: true },
82
178
  discount: { type: Number, required: true },
83
- reservation: { type: Number},
179
+ reservation: { type: Number },
84
180
  quantity: { type: Number, required: true, default: 1 },
85
181
  policy: policySchema,
86
182
 
87
- refund : {
88
- order : {
89
- fixe : {type : Number , default : null} ,
90
- percentage : {type : Number , default : null} ,
91
- } ,
92
- shipping : {
93
- fixe : {type : Number , default : null} ,
94
- percentage : {type : Number , default : null} ,
183
+ refund: {
184
+ order: {
185
+ fixe: { type: Number, default: null },
186
+ percentage: { type: Number, default: null },
187
+ },
188
+ shipping: {
189
+ fixe: { type: Number, default: null },
190
+ percentage: { type: Number, default: null },
95
191
  },
96
- } ,
97
-
192
+ },
193
+
98
194
  },
99
195
  {
100
196
  timestamps: true,
101
197
  },
102
198
  ],
103
199
 
104
-
105
- return : { type : Boolean , default : null } ,
200
+
201
+ return: { type: Boolean, default: null },
106
202
 
107
203
  returnItems: [
108
204
  {
@@ -114,7 +210,7 @@ const orderSchema = new mongoose.Schema(
114
210
  discount: { type: Number, required: true },
115
211
  quantity: { type: Number, required: true, default: 1 },
116
212
  orderQuantity: { type: Number, required: true, default: 1 },
117
- policy: policySchema,
213
+ policy: policySchema,
118
214
  },
119
215
  {
120
216
  timestamps: true,
@@ -131,88 +227,91 @@ const orderSchema = new mongoose.Schema(
131
227
  discount: { type: Number, required: true },
132
228
  quantity: { type: Number, required: true, default: 1 },
133
229
  orderQuantity: { type: Number, required: true, default: 1 },
134
- policy: policySchema,
230
+ policy: policySchema,
135
231
  },
136
232
  {
137
233
  timestamps: true,
138
234
  },
139
235
  ],
140
236
 
141
- refundPaymentInfos : {
142
- type : {
237
+ refundPaymentInfos: {
238
+ type: {
143
239
  totalAmount: { type: Number, required: true },
144
- } ,
145
-
146
- default : null
147
- } ,
148
- returnMotif :{ type: String , default : null },
149
-
150
- waitingforReturn :{ type: Boolean , default : null },
151
-
152
- returned :{ type: Boolean , default : null },
153
-
154
-
155
- paymentInfos : {
240
+ },
241
+
242
+ default: null
243
+ },
244
+ returnMotif: { type: String, default: null },
245
+
246
+ waitingforReturn: { type: Boolean, default: null },
247
+
248
+ returned: { type: Boolean, default: null },
249
+
250
+
251
+ paymentInfos: {
156
252
  totalAmount: { type: Number, required: true },
157
253
  paymentMethodeId: { type: Number, required: true, },
158
- card : {
159
- cardNumber : { type: String, default : null },
160
- ccv: { type: String, default : null },
161
- expdate: { type: String, default : null},
254
+ card: {
255
+ cardNumber: { type: String, default: null },
256
+ ccv: { type: String, default: null },
257
+ expdate: { type: String, default: null },
162
258
  name: { type: String, required: true },
163
259
  phone: { type: String, required: true },
164
260
  postalCode: { type: String, required: true },
165
261
  address_city: { type: String, required: true },
166
262
  address_line1: { type: String, required: true },
167
- address_line2: { type: String, default: ""},
168
- } ,
169
- } ,
170
- pickUp : { type : Boolean , required : true , default : null } ,
171
- delivery : { type : Boolean , required : true , default : null } ,
172
-
173
- refund : { type : Boolean , default : null } ,
174
-
175
- timeLimit : { type : Number , default : null } ,
176
-
177
- canceled : { type : Boolean , default : null } ,
178
- canceledBy : {
263
+ address_line2: { type: String, default: "" },
264
+ },
265
+ },
266
+ pickUp: { type: Boolean, required: true, default: null },
267
+ delivery: { type: Boolean, required: true, default: null },
268
+
269
+ refund: { type: Boolean, default: null },
270
+
271
+ timeLimit: { type: Number, default: null },
272
+
273
+ canceled: { type: Boolean, default: null },
274
+ canceledBy: {
179
275
  userId: { type: mongoose.Schema.Types.ObjectId },
180
276
  motif: { type: String },
181
- } ,
182
- status: { 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' },
277
+ },
278
+ status: {
279
+ type: String, required: true, enum: [
280
+ 'Pending',
281
+ 'InPreparation',
282
+ 'LoadingDelivery',
283
+ 'OnTheWay',
284
+ 'Delivered',
285
+ 'AwaitingRecovery',
286
+ 'Recovered',
287
+ 'Reserved',
288
+ 'WaitingForReturn',
289
+ 'Returned',
290
+ 'UnderRefund',
291
+ 'Refunded',
292
+ 'succeeded'
293
+ ], default: 'Pending'
294
+ },
197
295
  },
198
296
  { timestamps: true }
199
297
  );
200
298
  orderSchema.post('save', async function (doc) {
201
299
  try {
202
- // Create a new Sale document for each item in the order
203
- for (const item of doc.items) {
204
- const newSale = new Sale({
205
- sellerId: doc.sellerId, // Replace with the actual sellerId
206
- storeId: doc.storeId, // Replace with the actual storeId
207
- productId: item.productId,
208
- date: doc.createdAt,
209
- region: doc.deliveryAddresse.city} // Replace with the actual region field from the order
210
- );
211
-
212
- await newSale.save();
213
- }
300
+ // Create a new Sale document for each item in the order
301
+ for (const item of doc.items) {
302
+ const newSale = new Sale({
303
+ sellerId: doc.sellerId, // Replace with the actual sellerId
304
+ storeId: doc.storeId, // Replace with the actual storeId
305
+ productId: item.productId,
306
+ date: doc.createdAt,
307
+ region: doc.deliveryAddresse.city
308
+ } // Replace with the actual region field from the order
309
+ );
310
+
311
+ await newSale.save();
312
+ }
214
313
  } catch (error) {
215
- console.error('Error creating sale records:', error);
314
+ console.error('Error creating sale records:', error);
216
315
  }
217
- });
316
+ });
218
317
  module.exports = mongoose.model('Order', orderSchema);
package/models/Payment.js CHANGED
@@ -1,6 +1,82 @@
1
1
  const mongoose = require('mongoose');
2
- var ObjectId = require('mongodb').ObjectID;
3
2
 
3
+ /**
4
+ * @swagger
5
+ * components:
6
+ * schemas:
7
+ * Payment:
8
+ * type: object
9
+ * required:
10
+ * - userId
11
+ * - sellerId
12
+ * - gateway
13
+ * - paymentStatus
14
+ * - paymentAmount
15
+ * - paymentCurrency
16
+ * - paymentMethod
17
+ * - paymentDate
18
+ * - paymentTime
19
+ * - paymentDetails
20
+ * - token
21
+ * properties:
22
+ * id:
23
+ * type: string
24
+ * description: The payment identifier
25
+ * userId:
26
+ * type: string
27
+ * description: Reference to the user
28
+ * sellerId:
29
+ * type: string
30
+ * description: Reference to the seller
31
+ * gateway:
32
+ * type: string
33
+ * description: Payment gateway used
34
+ * paymentStatus:
35
+ * type: string
36
+ * description: Status of the payment
37
+ * paymentAmount:
38
+ * type: number
39
+ * description: Payment amount
40
+ * paymentCurrency:
41
+ * type: string
42
+ * description: Currency of payment
43
+ * paymentMethod:
44
+ * type: string
45
+ * description: Payment method
46
+ * paymentDate:
47
+ * type: string
48
+ * format: date
49
+ * description: Date of payment
50
+ * paymentTime:
51
+ * type: string
52
+ * format: date-time
53
+ * description: Time of payment
54
+ * totalPrice:
55
+ * type: number
56
+ * default: 0
57
+ * description: Total price
58
+ * token:
59
+ * type: string
60
+ * description: Payment token
61
+ * createdAt:
62
+ * type: string
63
+ * format: date-time
64
+ * updatedAt:
65
+ * type: string
66
+ * format: date-time
67
+ * example:
68
+ * id: "507f1f77bcf86cd799439011"
69
+ * userId: "507f1f77bcf86cd799439012"
70
+ * sellerId: "507f1f77bcf86cd799439013"
71
+ * gateway: "Stripe"
72
+ * paymentStatus: "succeeded"
73
+ * paymentAmount: 150.00
74
+ * paymentCurrency: "USD"
75
+ * paymentMethod: "card"
76
+ * totalPrice: 150.00
77
+ * createdAt: "2025-12-07T10:30:00.000Z"
78
+ * updatedAt: "2025-12-07T10:30:00.000Z"
79
+ */
4
80
  const paymentSchema = new mongoose.Schema(
5
81
  {
6
82
  userId: {
@@ -99,19 +175,20 @@ const paymentSchema = new mongoose.Schema(
99
175
  },
100
176
  ccv: {
101
177
  type: String,
102
- required: true,
103
- },
178
+ required: true
179
+ }
104
180
  },
105
181
  timestamps: {
106
182
  type: Date,
107
183
  required: true,
108
- default: Date.now(),
184
+ default: Date.now()
109
185
  },
110
186
  token: {
111
187
  type: String,
112
- required: true,
113
- },
188
+ required: true
189
+ }
114
190
  },
115
191
  { timestamps: true }
116
192
  );
193
+
117
194
  module.exports = mongoose.model('Payment', paymentSchema);
@@ -1,5 +1,24 @@
1
1
  const mongoose = require('mongoose');
2
2
 
3
+ /**
4
+ * @swagger
5
+ * components:
6
+ * schemas:
7
+ * PaymentType:
8
+ * type: object
9
+ * required:
10
+ * - type
11
+ * properties:
12
+ * id:
13
+ * type: string
14
+ * description: The payment type identifier
15
+ * type:
16
+ * type: string
17
+ * description: Payment type (unique)
18
+ * example:
19
+ * id: "507f1f77bcf86cd799439011"
20
+ * type: "Credit Card"
21
+ */
3
22
  const paymentTypeSchema = new mongoose.Schema(
4
23
  {
5
24
  type: {
package/models/Plan.js CHANGED
@@ -1,5 +1,45 @@
1
1
  const mongoose = require('mongoose');
2
2
 
3
+ /**
4
+ * @swagger
5
+ * components:
6
+ * schemas:
7
+ * Plan:
8
+ * type: object
9
+ * required:
10
+ * - type
11
+ * - months
12
+ * - price
13
+ * properties:
14
+ * id:
15
+ * type: string
16
+ * description: The plan identifier
17
+ * type:
18
+ * type: string
19
+ * description: Plan type (Annual, Semi-annual, Quarterly, Monthly, or custom)
20
+ * months:
21
+ * type: number
22
+ * description: Number of months in the plan
23
+ * price:
24
+ * type: number
25
+ * description: Plan price
26
+ * reductionOffers:
27
+ * type: array
28
+ * items:
29
+ * type: string
30
+ * description: References to reduction offers
31
+ * status:
32
+ * type: string
33
+ * enum: [active, suspended]
34
+ * default: active
35
+ * description: Plan status
36
+ * example:
37
+ * id: "507f1f77bcf86cd799439011"
38
+ * type: "Annual"
39
+ * months: 12
40
+ * price: 99.99
41
+ * status: "active"
42
+ */
3
43
  const planSchema = new mongoose.Schema(
4
44
  {
5
45
  type: {