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/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,100 @@
1
1
  const mongoose = require('mongoose');
2
- const { policySchema } = require('./Policy');
3
- var ObjectId = require('mongodb').ObjectID;
2
+ const { policySchema } = require('database-connector/models/Policy');
4
3
 
4
+ /**
5
+ * @swagger
6
+ * components:
7
+ * schemas:
8
+ * Product:
9
+ * type: object
10
+ * required:
11
+ * - name
12
+ * - description
13
+ * - price
14
+ * - storeCategoryId
15
+ * - categoryId
16
+ * - rayonId
17
+ * - sellerId
18
+ * - storeId
19
+ * properties:
20
+ * id:
21
+ * type: string
22
+ * description: The product identifier
23
+ * name:
24
+ * type: string
25
+ * description: Product name
26
+ * description:
27
+ * type: string
28
+ * description: Product description
29
+ * price:
30
+ * type: number
31
+ * description: Product price
32
+ * storeCategoryId:
33
+ * type: string
34
+ * description: Reference to store category
35
+ * categoryId:
36
+ * type: string
37
+ * description: Reference to category
38
+ * subCategoryId:
39
+ * type: string
40
+ * description: Reference to sub-category
41
+ * rayonId:
42
+ * type: string
43
+ * description: Reference to rayon
44
+ * images:
45
+ * type: array
46
+ * items:
47
+ * type: string
48
+ * description: Product images
49
+ * tags:
50
+ * type: array
51
+ * items:
52
+ * type: string
53
+ * description: Product tags
54
+ * sellerId:
55
+ * type: string
56
+ * description: Reference to seller
57
+ * storeId:
58
+ * type: string
59
+ * description: Reference to store
60
+ * deleted:
61
+ * type: boolean
62
+ * default: false
63
+ * description: Whether the product is deleted
64
+ * discount:
65
+ * type: number
66
+ * default: 0
67
+ * description: Product discount
68
+ * numberOfSales:
69
+ * type: number
70
+ * default: 0
71
+ * description: Number of sales
72
+ * numberOfViews:
73
+ * type: number
74
+ * default: 0
75
+ * description: Number of views
76
+ * averageRating:
77
+ * type: number
78
+ * default: 0
79
+ * description: Average rating
80
+ * createdAt:
81
+ * type: string
82
+ * format: date-time
83
+ * updatedAt:
84
+ * type: string
85
+ * format: date-time
86
+ * example:
87
+ * id: "507f1f77bcf86cd799439011"
88
+ * name: "Wireless Headphones"
89
+ * description: "High-quality wireless headphones"
90
+ * price: 99.99
91
+ * discount: 10
92
+ * numberOfSales: 50
93
+ * numberOfViews: 250
94
+ * averageRating: 4.5
95
+ * createdAt: "2025-11-01T10:30:00.000Z"
96
+ * updatedAt: "2025-12-01T15:45:00.000Z"
97
+ */
5
98
  const productSchema = new mongoose.Schema(
6
99
  {
7
100
  name: {
@@ -10,11 +103,11 @@ const productSchema = new mongoose.Schema(
10
103
  },
11
104
  description: { type: String, required: true },
12
105
  price: { type: Number, required: true },
13
- storeCategoryId : {
106
+ storeCategoryId: {
14
107
  type: mongoose.Schema.Types.ObjectId,
15
108
  ref: 'StoreCategory',
16
109
  required: true,
17
- } ,
110
+ },
18
111
  categoryId: {
19
112
  type: mongoose.Schema.Types.ObjectId,
20
113
  ref: 'Category',
@@ -98,24 +191,24 @@ const productSchema = new mongoose.Schema(
98
191
  type: mongoose.Schema.Types.ObjectId,
99
192
  ref: 'Offer',
100
193
  },
101
-
102
-
194
+
195
+
103
196
  numberOfSales: {
104
197
  type: Number,
105
198
  default: 0,
106
- },
107
- numberOfViews: {
199
+ },
200
+ numberOfViews: {
108
201
  type: Number,
109
202
  default: 0,
110
- },
111
- numberOfSearches: {
203
+ },
204
+ numberOfSearches: {
112
205
  type: Number,
113
206
  default: 0,
114
- },
115
- averageRating: {
207
+ },
208
+ averageRating: {
116
209
  type: Number,
117
210
  default: 0,
118
- },
211
+ },
119
212
 
120
213
  reports: [
121
214
  {
@@ -135,16 +228,20 @@ const productSchema = new mongoose.Schema(
135
228
  policy: policySchema,
136
229
  },
137
230
  {
138
- timestamp: true,
139
- toJSON: { virtuals: true },
231
+ timestamps: true,
232
+ toJSON: { virtuals: true }
140
233
  }
141
- );/*
234
+ );
235
+
236
+ // Virtual properties for quantity calculations (commented out)
237
+ /*
142
238
  productSchema.virtual('quantity').get(function () {
143
239
  const variants = this.variants;
144
240
  return variants.reduce(function (total, currentValue) {
145
241
  return total + currentValue.quantity;
146
242
  }, 0);
147
243
  });
244
+
148
245
  productSchema.virtual('PriceMin').get(function () {
149
246
  const variants = this.variants;
150
247
  return variants.reduce(function (prev, curr) {
@@ -157,8 +254,10 @@ productSchema.virtual('PriceMax').get(function () {
157
254
  return variants.reduce(function (prev, curr) {
158
255
  return prev.price > curr.price ? prev : curr;
159
256
  }).price;
160
- });*/
161
- //virtual array of all the images of the product
257
+ });
258
+ */
259
+
260
+ // Virtual: array of all product images with full URLs
162
261
  productSchema.virtual('imagesss').get(function () {
163
262
  if (this.images != null) {
164
263
  const images = this.images;
@@ -169,17 +268,18 @@ productSchema.virtual('imagesss').get(function () {
169
268
  });
170
269
  }
171
270
  });
271
+
272
+ // Virtual: discounted price
172
273
  productSchema.virtual('discounted').get(function () {
173
274
  if (this.offer) {
174
- console.log('Disount')
175
-
176
- return this.offer.discount;
177
-
275
+ console.log('Discount');
276
+ return this.offer.discount;
178
277
  } else {
179
- return this.price;
278
+ return this.price;
180
279
  }
181
- });
182
- //virtual array for all the images of the variants
280
+ });
281
+
282
+ // Virtual: array of all variant images with full URLs
183
283
  productSchema.virtual('variantImages').get(function () {
184
284
  if (this.variants != null) {
185
285
  const variants = this.variants;
@@ -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);