database-connector 2.3.7 → 2.3.8
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 +22 -0
- package/models/Product.js +3 -2
- package/models/Rayon.js +67 -0
- package/models/Store.js +2 -4
- package/models/index.js +2 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
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
|
+
- **Store Model**: Refactored `storeRayons` field from embedded objects to ObjectId references
|
|
17
|
+
- Changed from array of embedded objects with `name` field to array of ObjectId references
|
|
18
|
+
- Now references the `Rayon` model for better data normalization
|
|
19
|
+
- **Database Schema Documentation**: Updated `DATABASE_SCHEMA.md`
|
|
20
|
+
- Added Rayon entity to ER diagram
|
|
21
|
+
- Added Rayon model description in Catalog Models section
|
|
22
|
+
- Updated relationship documentation to include Rayon relationships
|
|
23
|
+
- Added Rayon relationships section showing connections to Product and Store models
|
|
24
|
+
|
|
3
25
|
## Database Indexes Optimization
|
|
4
26
|
|
|
5
27
|
### Added
|
package/models/Product.js
CHANGED
|
@@ -41,7 +41,7 @@ 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
|
|
44
|
+
* description: Reference to Rayon model
|
|
45
45
|
* images:
|
|
46
46
|
* type: array
|
|
47
47
|
* items:
|
|
@@ -120,7 +120,8 @@ const productSchema = new mongoose.Schema(
|
|
|
120
120
|
},
|
|
121
121
|
rayonId: {
|
|
122
122
|
type: mongoose.Schema.Types.ObjectId,
|
|
123
|
-
|
|
123
|
+
ref: 'Rayon',
|
|
124
|
+
// required: true,
|
|
124
125
|
},
|
|
125
126
|
//customCategory: { type: String, required: true },
|
|
126
127
|
//customCategoryId: { type: String, required: true },
|
package/models/Rayon.js
ADDED
|
@@ -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
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.
|
|
3
|
+
"version": "2.3.8",
|
|
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": {
|