@blackcode_sa/metaestetics-api 1.12.0 → 1.12.2

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.
@@ -18,7 +18,8 @@ constructor(
18
18
  categoryService: CategoryService,
19
19
  subcategoryService: SubcategoryService,
20
20
  technologyService: TechnologyService,
21
- productService: ProductService
21
+ productService: ProductService,
22
+ mediaService: MediaService
22
23
  )
23
24
  ```
24
25
 
@@ -31,7 +32,9 @@ Initializes the service with Firestore, Auth, App instances, and required depend
31
32
  - Creates a new procedure document in Firestore.
32
33
  - Validates input data using `createProcedureSchema`.
33
34
  - Fetches full Category, Subcategory, Technology, and Product documents using injected services.
35
+ - **Products Metadata:** Transforms `productsMetadata` from validation format (with `productId` strings) to full `ProcedureProduct` objects (with complete `product` objects).
34
36
  - Retrieves associated Clinic and Practitioner documents to embed `clinicInfo` and `doctorInfo`.
37
+ - Processes and uploads media files using the MediaService.
35
38
  - Embeds treatment details from the technology (blocking conditions, benefits, requirements).
36
39
  - Initializes default `reviewInfo` with zero values.
37
40
  - Sets `isActive` to `true` by default.
@@ -56,11 +59,13 @@ Initializes the service with Firestore, Auth, App instances, and required depend
56
59
 
57
60
  - Updates an existing procedure document with partial data.
58
61
  - Validates input data using `updateProcedureSchema`.
62
+ - **Products Metadata:** If `productsMetadata` is provided, transforms from validation format to full `ProcedureProduct` objects.
59
63
  - Handles complex updates of related entities:
60
64
  - If practitioner changes: Fetches new practitioner data and updates embedded `doctorInfo`.
61
65
  - If clinic changes: Fetches new clinic data and updates embedded `clinicInfo`.
62
66
  - If category/subcategory changes: Fetches and updates embedded objects.
63
67
  - If technology/product changes: Fetches and updates embedded objects plus derived fields.
68
+ - Processes and uploads media files if photos are provided.
64
69
  - Updates the `updatedAt` timestamp.
65
70
  - **Aggregation Note:** Updating aggregated data in related entities is handled by Cloud Functions.
66
71
 
@@ -83,6 +88,76 @@ Initializes the service with Firestore, Auth, App instances, and required depend
83
88
  - Returns an object containing arrays of allowed technologies, families, categories, and subcategories.
84
89
 
85
90
  - **`getAllProcedures(pagination?: number, lastDoc?: any): Promise<{ procedures: Procedure[]; lastDoc: any }>`**
91
+
86
92
  - Retrieves all procedures, ordered by name.
87
93
  - Supports optional pagination with `limit` and `startAfter`.
88
94
  - Returns both the procedures array and the last document for cursor-based pagination.
95
+
96
+ - **`bulkCreateProcedures(baseData: Omit<CreateProcedureData, "practitionerId">, practitionerIds: string[]): Promise<Procedure[]>`**
97
+
98
+ - Creates multiple procedures for different practitioners using common base data.
99
+ - Optimized for bulk creation to reduce database reads and writes.
100
+ - Uses Firestore batch writes for atomic creation.
101
+ - Transforms `productsMetadata` once and reuses for all procedures.
102
+
103
+ - **`createConsultationProcedure(data: Omit<CreateProcedureData, "productId">): Promise<Procedure>`**
104
+ - Special method for consultation procedures that don't require specific products.
105
+ - Creates a placeholder product for consultation procedures.
106
+ - Transforms `productsMetadata` from validation format to full objects.
107
+
108
+ ### Private Helper Methods
109
+
110
+ - **`transformProductsMetadata(productsMetadata, technologyId): Promise<ProcedureProduct[]>`**
111
+
112
+ - Converts validation format (with `productId` strings) to full `ProcedureProduct` objects.
113
+ - Fetches complete product objects for each product ID.
114
+ - Essential for maintaining type safety between validation and storage formats.
115
+
116
+ - **`processMedia(media, ownerId, collectionName): Promise<string | null>`**
117
+
118
+ - Handles media file uploads using MediaService.
119
+ - Supports string URLs, File objects, and Blob objects.
120
+
121
+ - **`processMediaArray(mediaArray, ownerId, collectionName): Promise<string[]>`**
122
+ - Processes arrays of media resources.
123
+ - Used for handling procedure photos.
124
+
125
+ ## Data Transformation
126
+
127
+ The service handles a critical data transformation between input and storage:
128
+
129
+ - **Input (`CreateProcedureData`/`UpdateProcedureData`):** `productsMetadata` contains objects with `productId: string`
130
+
131
+ ```typescript
132
+ productsMetadata: {
133
+ productId: string;
134
+ price: number;
135
+ currency: Currency;
136
+ pricingMeasure: PricingMeasure;
137
+ isDefault?: boolean;
138
+ }[]
139
+ ```
140
+
141
+ - **Storage (Firestore `Procedure`):** `productsMetadata` contains objects with `product: Product` (full object)
142
+ ```typescript
143
+ productsMetadata: ProcedureProduct[] // where ProcedureProduct contains full Product object
144
+ ```
145
+
146
+ This transformation ensures:
147
+
148
+ 1. **Type safety** throughout the application
149
+ 2. **Denormalized data** for efficient queries (no need to fetch products separately)
150
+ 3. **Consistent API contract** for clients (input uses IDs, storage uses full objects)
151
+ 4. **Performance optimization** (embedded product data in procedures)
152
+
153
+ ## Validation Schemas
154
+
155
+ The service uses different validation schemas for different stages:
156
+
157
+ - **`procedureProductDataSchema`**: Validates input data with `productId` strings (used in `createProcedureSchema`/`updateProcedureSchema`)
158
+ - **`storedProcedureProductSchema`**: Validates stored data with full `Product` objects (used in `procedureSchema`)
159
+ - **`createProcedureSchema`**: Validates procedure creation data (input format)
160
+ - **`updateProcedureSchema`**: Validates procedure update data (input format)
161
+ - **`procedureSchema`**: Validates complete stored procedure documents (storage format)
162
+
163
+ This ensures validation matches the actual data format at each stage of the process.