database-connector 2.3.7 → 2.3.9

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/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # Changelog - Database Connector Models Refactoring
2
2
 
3
+ ## [Unreleased]
4
+
5
+ ### Added
6
+ - **Rayon Model**: Created new independent `Rayon` model for product and store organization
7
+ - Schema includes `name` field and `subRayons` array for hierarchical organization
8
+ - Added Swagger documentation for API endpoints
9
+ - Indexed `name` field for performance optimization
10
+ - Exported Rayon model in `models/index.js`
11
+
12
+ ### Changed
13
+ - **Product Model**: Updated `rayonId` field to reference the new `Rayon` model
14
+ - Changed from untyped ObjectId to proper `ref: 'Rayon'` reference
15
+ - Updated Swagger documentation to reflect model reference
16
+ - Added `subRayonId` field (ObjectId, nullable) to reference sub-rayons within Rayon model
17
+ - **Store Model**: Refactored `storeRayons` field from embedded objects to ObjectId references
18
+ - Changed from array of embedded objects with `name` field to array of ObjectId references
19
+ - Now references the `Rayon` model for better data normalization
20
+ - **Database Schema Documentation**: Updated `DATABASE_SCHEMA.md`
21
+ - Added Rayon entity to ER diagram
22
+ - Added Rayon model description in Catalog Models section
23
+ - Updated relationship documentation to include Rayon relationships
24
+ - Added Rayon relationships section showing connections to Product and Store models
25
+
3
26
  ## Database Indexes Optimization
4
27
 
5
28
  ### Added
package/models/Product.js CHANGED
@@ -41,7 +41,10 @@ const { policySchema } = require('database-connector/models/Policy');
41
41
  * description: Reference to sub-category
42
42
  * rayonId:
43
43
  * type: string
44
- * description: Reference to rayon
44
+ * description: Reference to Rayon model
45
+ * subRayonId:
46
+ * type: string
47
+ * description: Reference to sub-rayon within Rayon model
45
48
  * images:
46
49
  * type: array
47
50
  * items:
@@ -120,7 +123,12 @@ const productSchema = new mongoose.Schema(
120
123
  },
121
124
  rayonId: {
122
125
  type: mongoose.Schema.Types.ObjectId,
123
- required: true,
126
+ ref: 'Rayon',
127
+ // required: true,
128
+ },
129
+ subRayonId: {
130
+ type: mongoose.Schema.Types.ObjectId,
131
+ default: null
124
132
  },
125
133
  //customCategory: { type: String, required: true },
126
134
  //customCategoryId: { type: String, required: true },
@@ -0,0 +1,67 @@
1
+ const mongoose = require('mongoose');
2
+
3
+ /**
4
+ * @swagger
5
+ * components:
6
+ * schemas:
7
+ * Rayon:
8
+ * type: object
9
+ * required:
10
+ * - name
11
+ * properties:
12
+ * id:
13
+ * type: string
14
+ * description: The rayon identifier
15
+ * name:
16
+ * type: string
17
+ * description: Rayon name
18
+ * subRayons:
19
+ * type: array
20
+ * items:
21
+ * type: object
22
+ * properties:
23
+ * name:
24
+ * type: string
25
+ * description: Sub-rayon name
26
+ * description: List of sub-rayons within this rayon
27
+ * createdAt:
28
+ * type: string
29
+ * format: date-time
30
+ * updatedAt:
31
+ * type: string
32
+ * format: date-time
33
+ * example:
34
+ * id: "507f1f77bcf86cd799439011"
35
+ * name: "Electronics"
36
+ * subRayons:
37
+ * - name: "Mobile Phones"
38
+ * - name: "Laptops"
39
+ * - name: "Accessories"
40
+ * createdAt: "2025-11-01T10:30:00.000Z"
41
+ * updatedAt: "2025-12-01T15:45:00.000Z"
42
+ */
43
+ const rayonSchema = new mongoose.Schema(
44
+ {
45
+ name: {
46
+ type: String,
47
+ required: true,
48
+ },
49
+ subRayons: [
50
+ {
51
+ name: {
52
+ type: String,
53
+ required: true,
54
+ },
55
+ },
56
+ ],
57
+ },
58
+ {
59
+ timestamps: true,
60
+ toJSON: { virtuals: true },
61
+ }
62
+ );
63
+
64
+ // Indexes for performance optimization
65
+ rayonSchema.index({ name: 1 });
66
+
67
+ module.exports = mongoose.model('Rayon', rayonSchema);
package/models/Store.js CHANGED
@@ -342,10 +342,8 @@ const storeSchema = new mongoose.Schema(
342
342
  ],
343
343
  storeRayons: [
344
344
  {
345
- name: {
346
- type: String,
347
- required: true,
348
- },
345
+ type: mongoose.Schema.Types.ObjectId,
346
+ ref: 'Rayon',
349
347
  },
350
348
  ],
351
349
  templateId: {
package/models/index.js CHANGED
@@ -63,6 +63,7 @@ const StoreCategory = require('./StoreCategory');
63
63
  const UserAction = require('./UserAction.js');
64
64
  const Advertisement = require('./Advertisement');
65
65
  const Settings = require('./Settings');
66
+ const Rayon = require('./Rayon');
66
67
 
67
68
 
68
69
  module.exports = {
@@ -97,5 +98,6 @@ module.exports = {
97
98
  UserAction,
98
99
  Advertisement,
99
100
  Settings,
101
+ Rayon,
100
102
  ObjectId: mongoose.Types.ObjectId,
101
103
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "database-connector",
3
- "version": "2.3.7",
3
+ "version": "2.3.9",
4
4
  "description": "MongoDB models package with Mongoose schemas for e-commerce applications. Includes User, Product, Store, Order and more with built-in validation and virtual properties.",
5
5
  "main": "models/index.js",
6
6
  "scripts": {