database-connector 2.5.15 → 2.5.17

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,111 +1,9 @@
1
1
  # Changelog - Database Connector Models Refactoring
2
2
 
3
- ## [Unreleased]
4
-
5
- ### Changed
6
- - **Categorization Hierarchy Restructure**: Refactored category models to implement new hierarchy: StoreCategory → Rayon → Sub-rayon → Category → Sub-category
7
- - **StoreCategory Model**: Removed `rayonId` field as StoreCategory is now the top-level category
8
- - **Rayon Model**: Added `storeCategoryId` field (required) to associate rayons with store categories
9
- - **Category Model**: Added `rayonId` field (required) to associate categories with rayons or sub-rayons
10
- - **Product Model**: Maintains `storeCategoryId`, `categoryId`, `subCategoryId`, `rayonId`, and `subRayonId` for full hierarchy tracking
11
- - Updated Swagger documentation for all affected models
12
- - Updated DATABASE_SCHEMA.md to reflect new relationships in ER diagram
13
-
14
- ### Added
15
- - **PlanType Model**: Created new `PlanType` model for plan categorization and feature management
16
- - Schema includes `name` (unique, required), `endDate` (optional, nullable), `active` (boolean, default: true), and `features` (Map of string keys to Mixed values - boolean or number)
17
- - Features can be boolean flags (enabled/disabled) or numeric limits/quotas (e.g., maxProducts: 100)
18
- - Used to categorize subscription plans and manage feature sets (lock/unlock features)
19
- - Added Swagger documentation for API endpoints
20
- - Indexed `active` and `name` fields for performance optimization
21
- - Exported PlanType model in `models/index.js`
22
-
23
- - **Plan Model**: Added `additionalStoreReductionPercentage` field
24
- - Type: Number (default: 0, range: 0-100)
25
- - Represents the percentage of reduction applied when adding additional stores to a subscription
26
- - Base price is for one store; this field controls discounts for multi-store subscriptions
27
- - Updated Swagger documentation to reflect new field
28
-
29
- - **ReductionOffer Model**: Added `additionalStoreReductionPercentage` field
30
- - Type: Number (nullable, default: null, range: 0-100)
31
- - Allows reduction offers to override the plan's additional store reduction percentage
32
- - Null value means no reduction on additional stores for this offer
33
- - Updated Swagger documentation to reflect new field
34
-
35
- - **User Model**: Added `preferredLang` field
36
- - Type: String, enum: ['ar', 'en', 'fr'], default: 'en'
37
- - Stores user's preferred language for interface and communications
38
- - Updated Swagger documentation to reflect new field
39
-
40
- - **Subscription Model**: Added multiple new fields and improvements
41
- - **BREAKING CHANGE**: Changed `storeId` to `sellerId` - now references User (seller) instead of Store
42
- - Updated all occurrences in main schema, subscriptionsHistory, and upcomingSubscriptions
43
- - Updated indexes to use `sellerId` instead of `storeId`
44
- - **BREAKING CHANGE**: Removed `histories` field and SubscriptionHistory collection tracking
45
- - Simplified to use only embedded `subscriptionsHistory` array
46
- - Automatic history snapshot creation now pushes to embedded subscriptionsHistory array on save/update
47
- - History snapshots include all subscription fields (sellerId, planId, planTypeId, paymentTypeId, paymentIntentId, reductionOfferId, numberOfStores, billingAddress, invoiceRecipient, invoiceLink, status, dates, notes)
48
- - Removed cascade delete logic (embedded arrays are deleted automatically with parent document)
49
- - All history tracking done via embedded subscriptionsHistory and upcomingSubscriptions arrays
50
- - `planTypeId`: ObjectId reference to PlanType model
51
- - `numberOfStores`: Number (default: 1, minimum: 1) - tracks number of stores in subscription
52
- - `stores`: Array of ObjectIds referencing Store - tracks which specific stores are included in this subscription
53
- - `billingAddress`: Mixed object for billing address (Adresse de facturation)
54
- - `invoiceRecipient`: Object with type (Person/Company enum) and name fields (Facture au nom de)
55
- - `invoiceLink`: String (nullable, default: null) - link to the invoice document
56
- - Updated `subscriptionsHistory` and `upcomingSubscriptions` arrays to include complete subscription snapshots
57
- - Both now include all fields: storeId, planId, planTypeId, paymentTypeId, paymentIntentId, reductionOfferId, numberOfStores, stores, billingAddress, invoiceRecipient, invoiceLink
58
- - Makes history tracking consistent and comprehensive
59
- - Added `planTypeId` index for performance optimization
60
- - Updated history snapshot builder to include all new fields including invoiceLink
61
- - Updated Swagger documentation to reflect all new fields
62
-
63
- - **Order Model**: Added invoice link field
64
- - `invoiceLink`: String (nullable, default: null) - link to the invoice document
65
- - Updated Swagger documentation to reflect new field
66
-
67
- - **Rayon Model**: Created new independent `Rayon` model for product and store organization
68
- - Schema includes `name` field and `subRayons` array for hierarchical organization
69
- - Added `confirmed` boolean on rayon and sub-rayons (default: false)
70
- - Added Swagger documentation for API endpoints
71
- - Indexed `name` field for performance optimization
72
- - Exported Rayon model in `models/index.js`
73
-
74
- ### Changed
75
- - **Product Model**: Updated `rayonId` field to reference the new `Rayon` model
76
- - Changed from untyped ObjectId to proper `ref: 'Rayon'` reference
77
- - Updated Swagger documentation to reflect model reference
78
- - Added `subRayonId` field (ObjectId, nullable) to reference sub-rayons within Rayon model
79
- - **Store Model**: Refactored `storeRayons` field from embedded objects to ObjectId references
80
- - Changed from array of embedded objects with `name` field to structured array with `rayonId` and `subRayons`
81
- - Now references the `Rayon` model with support for sub-rayons (similar to `productCategorieIds` structure)
82
- - Structure: `{ rayonId: ObjectId, subRayons: [ObjectId] }`
83
- - **Database Schema Documentation**: Updated `DATABASE_SCHEMA.md`
84
- - Added PlanType entity to ER diagram with relationships to Plan and Subscription models
85
- - Updated PlanType to show features support both boolean and number values
86
- - Added PlanType model description in Subscription & Payment Models section
87
- - Updated Plan model documentation to include `additionalStoreReductionPercentage` field
88
- - Updated ReductionOffer model documentation to include `additionalStoreReductionPercentage` field
89
- - Updated User entity to include `preferredLang` field
90
- - Updated User model description to include `preferredLang` field
91
- - Updated Subscription entity to include `planTypeId`, `numberOfStores`, `billingAddress`, and `invoiceRecipient` fields
92
- - Updated Subscription model description with comprehensive details on new fields and improved history tracking
93
- - Added `planTypeId` to Subscription indexes section
94
- - Updated subscription chain relationships to include Plan → PlanType and Subscription → PlanType
95
- - Added PlanType indexes section (active, name)
96
- - Updated subscription chain relationships to include Plan → PlanType
97
- - Added Rayon entity to ER diagram
98
- - Added Rayon model description in Catalog Models section
99
- - Updated relationship documentation to include Rayon relationships
100
- - Added Rayon relationships section showing connections to Product and Store models
101
-
102
3
  ## Database Indexes Optimization
103
4
 
104
5
  ### Added
105
6
 
106
- #### Added Transaction method to all models
107
- - Added a static `withTransaction(fn)` method to all models to facilitate running operations within MongoDB transactions. This method accepts a function `fn` that contains the operations to be executed in a transaction.
108
-
109
7
  #### Database Indexes for Performance Optimization
110
8
 
111
9
  After comprehensive analysis of model usage across all microservices (AuthService, CartService, CategoryService, NotificationService, OfferService, OrderService, ProductService, SalesAnalyticsService, SearchExplorationService, StoreService, SubscriptionService, and UserService), the following database indexes have been added to optimize query performance:
@@ -234,8 +132,7 @@ After comprehensive analysis of model usage across all microservices (AuthServic
234
132
  - `paymentManagerId`: For payment manager tracking
235
133
  - `storeId, status` (compound): For store subscription status
236
134
  - `status, endDate` (compound): For active subscription expiration monitoring
237
- - `stores`: For queries filtering by specific stores in the subscription
238
- - **Justification:** SubscriptionService queries subscriptions by store, status, and expiration dates. Compound indexes optimize active subscription monitoring and store subscription management. The stores index enables efficient queries to find subscriptions containing specific stores.
135
+ - **Justification:** SubscriptionService queries subscriptions by store, status, and expiration dates. Compound indexes optimize active subscription monitoring and store subscription management.
239
136
 
240
137
  **13. UserAction Model** (`UserAction.js`)
241
138
  - **Indexes Added:**
package/models/Payment.js CHANGED
@@ -32,6 +32,7 @@ const mongoose = require('mongoose');
32
32
  * type: string
33
33
  * description: Status of the payment
34
34
  * enum:
35
+ * - requested
35
36
  * - pending
36
37
  * - processing
37
38
  * - completed
@@ -94,7 +95,7 @@ const paymentSchema = new mongoose.Schema(
94
95
  paymentStatus: {
95
96
  type: String,
96
97
  required: true,
97
- enum: ['pending', 'processing', 'completed', 'failed', 'refunded'],
98
+ enum: ['requested', 'pending', 'processing', 'completed', 'failed', 'refunded'],
98
99
  default: 'pending',
99
100
  },
100
101
  paymentAmount: {
@@ -22,6 +22,13 @@ const mongoose = require('mongoose');
22
22
  * type: number
23
23
  * default: 10
24
24
  * description: Maximum number of stores allowed in a plan
25
+ * contact_number:
26
+ * type: string
27
+ * description: Contact phone number for support
28
+ * email:
29
+ * type: string
30
+ * format: email
31
+ * description: Contact email address for support
25
32
  * createdAt:
26
33
  * type: string
27
34
  * format: date-time
@@ -33,6 +40,8 @@ const mongoose = require('mongoose');
33
40
  * max_pollution_threshold: 20
34
41
  * max_targeted_users: 15
35
42
  * max_stores_in_plan: 10
43
+ * contact_number: "+213555123456"
44
+ * email: "support@example.com"
36
45
  * createdAt: "2025-11-01T10:30:00.000Z"
37
46
  * updatedAt: "2025-12-01T15:45:00.000Z"
38
47
  */
@@ -50,6 +59,14 @@ const SettingsSchema = new mongoose.Schema(
50
59
  type: Number,
51
60
  default: 10,
52
61
  },
62
+ contact_number: {
63
+ type: String,
64
+ default: null,
65
+ },
66
+ email: {
67
+ type: String,
68
+ default: null,
69
+ },
53
70
  },
54
71
  {
55
72
  timestamps: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "database-connector",
3
- "version": "2.5.15",
3
+ "version": "2.5.17",
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": {