database-connector 1.0.7 → 2.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/Policy.js CHANGED
@@ -1,96 +1,214 @@
1
1
  const { Schema, model } = require('mongoose');
2
2
 
3
+ /**
4
+ * @swagger
5
+ * components:
6
+ * schemas:
7
+ * Policy:
8
+ * type: object
9
+ * properties:
10
+ * workingTime:
11
+ * type: object
12
+ * properties:
13
+ * openTime:
14
+ * type: string
15
+ * default: ""
16
+ * closeTime:
17
+ * type: string
18
+ * default: ""
19
+ * pickup:
20
+ * type: object
21
+ * properties:
22
+ * timeLimit:
23
+ * type: number
24
+ * delivery:
25
+ * type: object
26
+ * properties:
27
+ * delivery:
28
+ * type: boolean
29
+ * zone:
30
+ * type: object
31
+ * properties:
32
+ * centerPoint:
33
+ * type: object
34
+ * properties:
35
+ * latitude:
36
+ * type: number
37
+ * longitude:
38
+ * type: number
39
+ * radius:
40
+ * type: number
41
+ * pricing:
42
+ * type: object
43
+ * properties:
44
+ * fixe:
45
+ * type: number
46
+ * km:
47
+ * type: number
48
+ * reservation:
49
+ * type: object
50
+ * properties:
51
+ * duration:
52
+ * type: number
53
+ * payment:
54
+ * type: object
55
+ * properties:
56
+ * free:
57
+ * type: boolean
58
+ * partial:
59
+ * type: object
60
+ * properties:
61
+ * fixe:
62
+ * type: number
63
+ * percentage:
64
+ * type: number
65
+ * total:
66
+ * type: boolean
67
+ * cancelation:
68
+ * type: object
69
+ * properties:
70
+ * restrictions:
71
+ * type: object
72
+ * properties:
73
+ * fixe:
74
+ * type: number
75
+ * percentage:
76
+ * type: number
77
+ * return:
78
+ * type: object
79
+ * properties:
80
+ * duration:
81
+ * type: number
82
+ * productStatus:
83
+ * type: string
84
+ * returnMethod:
85
+ * type: string
86
+ * refund:
87
+ * type: object
88
+ * properties:
89
+ * order:
90
+ * type: object
91
+ * properties:
92
+ * fixe:
93
+ * type: number
94
+ * percentage:
95
+ * type: number
96
+ * shipping:
97
+ * type: object
98
+ * properties:
99
+ * fixe:
100
+ * type: number
101
+ * percentage:
102
+ * type: number
103
+ * order:
104
+ * type: object
105
+ * properties:
106
+ * notification:
107
+ * type: object
108
+ * properties:
109
+ * realtime:
110
+ * type: boolean
111
+ * time:
112
+ * type: number
113
+ * perOrdersNbr:
114
+ * type: number
115
+ * sendMode:
116
+ * type: object
117
+ * properties:
118
+ * mail:
119
+ * type: boolean
120
+ * sms:
121
+ * type: boolean
122
+ * popup:
123
+ * type: boolean
124
+ * vibration:
125
+ * type: boolean
126
+ * ringing:
127
+ * type: boolean
128
+ */
3
129
  exports.policySchema = new Schema(
4
- {
5
-
6
- workingTime : {
7
- type : {
8
- openTime: { type: String , default : ""},
9
- closeTime: { type: String , default : ""} ,
10
- } ,
11
- },
12
- pickup: {
13
- type : {
14
- timeLimit : { type: Number , default : null} ,
15
- } ,
16
- },
17
- delivery: {
18
- type : {
19
- delivery : {type : Boolean, default : null } ,
20
- zone : {
21
- centerPoint : {
22
- latitude : { type : Number , default : null} ,
23
- longitude : { type : Number , default : null} ,
24
- } ,
25
- radius : { type : Number , default : null } ,
26
- } ,
27
- pricing : {
28
- fixe : {type : Number , default : null} ,
29
- km : {type : Number , default : null} ,
30
- } ,
31
- }
32
-
33
- } ,
34
-
35
- reservation : {
36
- type : {
37
- duration : {type : Number , default : null} ,
38
- payment : {
39
- free : {type : Boolean , default : null} ,
40
- partial : {
41
- fixe : {type : Number , default : null} ,
42
- percentage : {type : Number , default : null} ,
43
- } ,
44
- total : {type : Boolean , default : null} ,
45
- } ,
46
- cancelation : {
47
- restrictions : {
48
- fixe : {type : Number , default : null} ,
49
- percentage : {type : Number , default : null} ,
50
- }
51
- } ,
52
- } ,
53
- } ,
54
- return : {
55
- type : {
56
- duration : {type : Number , default : null} ,
57
- productStatus : {type : String , default : ""} ,
58
- returnMethod : {type : String , default : ""} ,
59
- refund : {
60
- order : {
61
- fixe : {type : Number , default : null} ,
62
- percentage : {type : Number , default : null} ,
63
- } ,
64
- shipping : {
65
- fixe : {type : Number , default : null} ,
66
- percentage : {type : Number , default : null} ,
67
- },
68
- } ,
69
- } ,
70
-
71
- } ,
72
- order : {
73
- type : {
74
-
75
- notification : {
76
- realtime :{type : Boolean , default : null} ,
77
- time :{type : Number , default : null} ,
78
- perOrdersNbr :{type : Number , default : null} ,
79
- sendMode : {
80
- mail :{type : Boolean , default : null} ,
81
- sms :{type : Boolean , default : null} ,
82
- popup :{type : Boolean , default : null} ,
83
- vibration :{type : Boolean , default : null} ,
84
- ringing :{type : Boolean , default : null} ,
85
- } ,
86
- }
87
-
88
- }
89
- }
90
- },
91
130
  {
92
-
93
- }
131
+ workingTime: {
132
+ type: {
133
+ openTime: { type: String, default: '' },
134
+ closeTime: { type: String, default: '' }
135
+ }
136
+ },
137
+ pickup: {
138
+ type: {
139
+ timeLimit: { type: Number, default: null }
140
+ }
141
+ },
142
+ delivery: {
143
+ type: {
144
+ delivery: { type: Boolean, default: null },
145
+ zone: {
146
+ centerPoint: {
147
+ latitude: { type: Number, default: null },
148
+ longitude: { type: Number, default: null }
149
+ },
150
+ radius: { type: Number, default: null }
151
+ },
152
+ pricing: {
153
+ fixe: { type: Number, default: null },
154
+ km: { type: Number, default: null }
155
+ }
156
+ }
157
+ },
158
+ reservation: {
159
+ type: {
160
+ duration: { type: Number, default: null },
161
+ payment: {
162
+ free: { type: Boolean, default: null },
163
+ partial: {
164
+ fixe: { type: Number, default: null },
165
+ percentage: { type: Number, default: null }
166
+ },
167
+ total: { type: Boolean, default: null }
168
+ },
169
+ cancelation: {
170
+ restrictions: {
171
+ fixe: { type: Number, default: null },
172
+ percentage: { type: Number, default: null }
173
+ }
174
+ }
175
+ }
176
+ },
177
+ return: {
178
+ type: {
179
+ duration: { type: Number, default: null },
180
+ productStatus: { type: String, default: '' },
181
+ returnMethod: { type: String, default: '' },
182
+ refund: {
183
+ order: {
184
+ fixe: { type: Number, default: null },
185
+ percentage: { type: Number, default: null }
186
+ },
187
+ shipping: {
188
+ fixe: { type: Number, default: null },
189
+ percentage: { type: Number, default: null }
190
+ }
191
+ }
192
+ }
193
+ },
194
+ order: {
195
+ type: {
196
+ notification: {
197
+ realtime: { type: Boolean, default: null },
198
+ time: { type: Number, default: null },
199
+ perOrdersNbr: { type: Number, default: null },
200
+ sendMode: {
201
+ mail: { type: Boolean, default: null },
202
+ sms: { type: Boolean, default: null },
203
+ popup: { type: Boolean, default: null },
204
+ vibration: { type: Boolean, default: null },
205
+ ringing: { type: Boolean, default: null }
206
+ }
207
+ }
208
+ }
209
+ }
210
+ },
211
+ {}
94
212
  );
95
213
 
96
-
214
+ module.exports = model('Policy', planSchema);
package/models/Product.js CHANGED
@@ -1,7 +1,101 @@
1
1
  const mongoose = require('mongoose');
2
2
  const { policySchema } = require('database-connector/models/Policy');
3
- var ObjectId = require('mongodb').ObjectID;
3
+ const { getBaseURL, getDefaultImagePath } = require('../config');
4
4
 
5
+ /**
6
+ * @swagger
7
+ * components:
8
+ * schemas:
9
+ * Product:
10
+ * type: object
11
+ * required:
12
+ * - name
13
+ * - description
14
+ * - price
15
+ * - storeCategoryId
16
+ * - categoryId
17
+ * - rayonId
18
+ * - sellerId
19
+ * - storeId
20
+ * properties:
21
+ * id:
22
+ * type: string
23
+ * description: The product identifier
24
+ * name:
25
+ * type: string
26
+ * description: Product name
27
+ * description:
28
+ * type: string
29
+ * description: Product description
30
+ * price:
31
+ * type: number
32
+ * description: Product price
33
+ * storeCategoryId:
34
+ * type: string
35
+ * description: Reference to store category
36
+ * categoryId:
37
+ * type: string
38
+ * description: Reference to category
39
+ * subCategoryId:
40
+ * type: string
41
+ * description: Reference to sub-category
42
+ * rayonId:
43
+ * type: string
44
+ * description: Reference to rayon
45
+ * images:
46
+ * type: array
47
+ * items:
48
+ * type: string
49
+ * description: Product images
50
+ * tags:
51
+ * type: array
52
+ * items:
53
+ * type: string
54
+ * description: Product tags
55
+ * sellerId:
56
+ * type: string
57
+ * description: Reference to seller
58
+ * storeId:
59
+ * type: string
60
+ * description: Reference to store
61
+ * deleted:
62
+ * type: boolean
63
+ * default: false
64
+ * description: Whether the product is deleted
65
+ * discount:
66
+ * type: number
67
+ * default: 0
68
+ * description: Product discount
69
+ * numberOfSales:
70
+ * type: number
71
+ * default: 0
72
+ * description: Number of sales
73
+ * numberOfViews:
74
+ * type: number
75
+ * default: 0
76
+ * description: Number of views
77
+ * averageRating:
78
+ * type: number
79
+ * default: 0
80
+ * description: Average rating
81
+ * createdAt:
82
+ * type: string
83
+ * format: date-time
84
+ * updatedAt:
85
+ * type: string
86
+ * format: date-time
87
+ * example:
88
+ * id: "507f1f77bcf86cd799439011"
89
+ * name: "Wireless Headphones"
90
+ * description: "High-quality wireless headphones"
91
+ * price: 99.99
92
+ * discount: 10
93
+ * numberOfSales: 50
94
+ * numberOfViews: 250
95
+ * averageRating: 4.5
96
+ * createdAt: "2025-11-01T10:30:00.000Z"
97
+ * updatedAt: "2025-12-01T15:45:00.000Z"
98
+ */
5
99
  const productSchema = new mongoose.Schema(
6
100
  {
7
101
  name: {
@@ -136,15 +230,19 @@ const productSchema = new mongoose.Schema(
136
230
  },
137
231
  {
138
232
  timestamps: true,
139
- toJSON: { virtuals: true },
233
+ toJSON: { virtuals: true }
140
234
  }
141
- );/*
235
+ );
236
+
237
+ // Virtual properties for quantity calculations (commented out)
238
+ /*
142
239
  productSchema.virtual('quantity').get(function () {
143
240
  const variants = this.variants;
144
241
  return variants.reduce(function (total, currentValue) {
145
242
  return total + currentValue.quantity;
146
243
  }, 0);
147
244
  });
245
+
148
246
  productSchema.virtual('PriceMin').get(function () {
149
247
  const variants = this.variants;
150
248
  return variants.reduce(function (prev, curr) {
@@ -157,38 +255,41 @@ productSchema.virtual('PriceMax').get(function () {
157
255
  return variants.reduce(function (prev, curr) {
158
256
  return prev.price > curr.price ? prev : curr;
159
257
  }).price;
160
- });*/
161
- //virtual array of all the images of the product
258
+ });
259
+ */
260
+
261
+ // Virtual: array of all product images with full URLs
162
262
  productSchema.virtual('imagesss').get(function () {
163
263
  if (this.images != null) {
164
264
  const images = this.images;
165
265
  console.log(images);
166
266
  console.log('images');
167
267
  return images.map(function (image) {
168
- return `${process.env.APP_URL}/${image}`;
268
+ return `${getBaseURL()}/${image}`;
169
269
  });
170
270
  }
171
271
  });
272
+
273
+ // Virtual: discounted price
172
274
  productSchema.virtual('discounted').get(function () {
173
275
  if (this.offer) {
174
- console.log('Disount')
175
-
276
+ console.log('Discount');
176
277
  return this.offer.discount;
177
-
178
278
  } else {
179
279
  return this.price;
180
280
  }
181
281
  });
182
- //virtual array for all the images of the variants
282
+
283
+ // Virtual: array of all variant images with full URLs
183
284
  productSchema.virtual('variantImages').get(function () {
184
285
  if (this.variants != null) {
185
286
  const variants = this.variants;
186
287
  console.log(variants);
187
288
  return variants.map(function (variant) {
188
289
  if (variant.img != null) {
189
- return `${process.env.APP_URL}/${variant.img}`;
290
+ return `${getBaseURL()}/${variant.img}`;
190
291
  } else {
191
- return `${process.env.APP_URL}/images/default.png`;
292
+ return `${getBaseURL()}${getDefaultImagePath()}`;
192
293
  }
193
294
  });
194
295
  }
@@ -1,5 +1,63 @@
1
1
  const mongoose = require('mongoose');
2
2
 
3
+ /**
4
+ * @swagger
5
+ * components:
6
+ * schemas:
7
+ * ReductionOffer:
8
+ * type: object
9
+ * required:
10
+ * - name
11
+ * - discount
12
+ * - storesNumber
13
+ * - plan
14
+ * properties:
15
+ * id:
16
+ * type: string
17
+ * description: The reduction offer identifier
18
+ * name:
19
+ * type: string
20
+ * description: Unique offer name
21
+ * discount:
22
+ * type: number
23
+ * description: Discount amount or percentage
24
+ * storesNumber:
25
+ * type: number
26
+ * description: Number of stores included
27
+ * plan:
28
+ * type: string
29
+ * description: Reference to the plan
30
+ * StartDate:
31
+ * type: string
32
+ * format: date-time
33
+ * description: Start date of the offer
34
+ * EndDate:
35
+ * type: string
36
+ * format: date-time
37
+ * description: End date of the offer
38
+ * description:
39
+ * type: string
40
+ * description: Offer description
41
+ * status:
42
+ * type: string
43
+ * enum: [inactive, active, expired]
44
+ * default: inactive
45
+ * description: Offer status
46
+ * createdAt:
47
+ * type: string
48
+ * format: date-time
49
+ * updatedAt:
50
+ * type: string
51
+ * format: date-time
52
+ * example:
53
+ * id: "507f1f77bcf86cd799439011"
54
+ * name: "Holiday Special"
55
+ * discount: 15
56
+ * storesNumber: 5
57
+ * status: "active"
58
+ * createdAt: "2025-11-01T10:30:00.000Z"
59
+ * updatedAt: "2025-12-01T15:45:00.000Z"
60
+ */
3
61
  const ReductionOfferSchema = new mongoose.Schema(
4
62
  {
5
63
  name: {
@@ -1,5 +1,34 @@
1
1
  const mongoose = require('mongoose');
2
2
 
3
+ /**
4
+ * @swagger
5
+ * components:
6
+ * schemas:
7
+ * ResetPassword:
8
+ * type: object
9
+ * required:
10
+ * - userId
11
+ * - token
12
+ * properties:
13
+ * id:
14
+ * type: string
15
+ * description: The reset password identifier
16
+ * userId:
17
+ * type: string
18
+ * description: Reference to the user
19
+ * token:
20
+ * type: string
21
+ * description: Reset token
22
+ * createAt:
23
+ * type: string
24
+ * format: date-time
25
+ * description: Creation timestamp (expires after 1 hour)
26
+ * example:
27
+ * id: "507f1f77bcf86cd799439011"
28
+ * userId: "507f1f77bcf86cd799439012"
29
+ * token: "abc123xyz789"
30
+ * createAt: "2025-12-07T10:30:00.000Z"
31
+ */
3
32
  const resetPasswordSchema = new mongoose.Schema(
4
33
  {
5
34
  userId: {
@@ -9,12 +38,12 @@ const resetPasswordSchema = new mongoose.Schema(
9
38
  },
10
39
  token: {
11
40
  type: String,
12
- required: true,
41
+ required: true
13
42
  },
14
43
  createAt: {
15
44
  type: Date,
16
45
  default: Date.now,
17
- expires : 3600
46
+ expires: 3600
18
47
  }
19
48
  },
20
49
  { toJSON: { virtuals: true } }
package/models/Sale.js CHANGED
@@ -1,11 +1,47 @@
1
1
  const mongoose = require('mongoose');
2
2
 
3
+ /**
4
+ * @swagger
5
+ * components:
6
+ * schemas:
7
+ * Sale:
8
+ * type: object
9
+ * required:
10
+ * - date
11
+ * properties:
12
+ * id:
13
+ * type: string
14
+ * description: The sale identifier
15
+ * sellerId:
16
+ * type: string
17
+ * description: Reference to the seller
18
+ * storeId:
19
+ * type: string
20
+ * description: Reference to the store
21
+ * productId:
22
+ * type: string
23
+ * description: Reference to the product
24
+ * date:
25
+ * type: string
26
+ * format: date-time
27
+ * description: Date of the sale
28
+ * region:
29
+ * type: string
30
+ * description: Region where the sale occurred
31
+ * example:
32
+ * id: "507f1f77bcf86cd799439011"
33
+ * sellerId: "507f1f77bcf86cd799439012"
34
+ * storeId: "507f1f77bcf86cd799439013"
35
+ * productId: "507f1f77bcf86cd799439014"
36
+ * date: "2025-12-07T10:30:00.000Z"
37
+ * region: "North Region"
38
+ */
3
39
  const Sale = 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 sale
40
+ sellerId: { type: mongoose.Schema.Types.ObjectId, ref: 'Seller' },
41
+ storeId: { type: mongoose.Schema.Types.ObjectId, ref: 'Store' },
42
+ productId: { type: mongoose.Schema.Types.ObjectId, ref: 'Product' },
43
+ date: { type: Date, required: true },
44
+ region: { type: String }
9
45
  });
10
46
 
11
47
  module.exports = mongoose.model('Sale', Sale);