@blackcode_sa/metaestetics-api 1.12.50 → 1.12.51

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.
@@ -98,6 +98,18 @@ declare class BrandService extends BaseService {
98
98
  * Gets a brand by ID
99
99
  */
100
100
  getById(brandId: string): Promise<Brand | null>;
101
+ /**
102
+ * Exports brands to CSV string, suitable for Excel/Sheets.
103
+ * Includes headers and optional UTF-8 BOM.
104
+ * By default exports only active brands (set includeInactive to true to export all).
105
+ */
106
+ exportToCsv(options?: {
107
+ includeInactive?: boolean;
108
+ includeBom?: boolean;
109
+ }): Promise<string>;
110
+ private brandToCsvRow;
111
+ private formatDateIso;
112
+ private formatCsvValue;
101
113
  }
102
114
 
103
115
  /**
@@ -277,6 +289,18 @@ declare class CategoryService extends BaseService implements ICategoryService {
277
289
  * @returns Kategorija ili null ako ne postoji
278
290
  */
279
291
  getById(id: string): Promise<Category | null>;
292
+ /**
293
+ * Exports categories to CSV string, suitable for Excel/Sheets.
294
+ * Includes headers and optional UTF-8 BOM.
295
+ * By default exports only active categories (set includeInactive to true to export all).
296
+ */
297
+ exportToCsv(options?: {
298
+ includeInactive?: boolean;
299
+ includeBom?: boolean;
300
+ }): Promise<string>;
301
+ private categoryToCsvRow;
302
+ private formatDateIso;
303
+ private formatCsvValue;
280
304
  }
281
305
 
282
306
  /**
@@ -581,9 +605,10 @@ interface UpdateDocumentTemplateData {
581
605
  *
582
606
  * @property id - Unique identifier of the product
583
607
  * @property name - Name of the product
584
- * @property description - Detailed description of the product and its purpose
585
608
  * @property brandId - ID of the brand that manufactures this product
586
- * @property technologyId - ID of the technology this product is used with
609
+ * @property brandName - Name of the brand (denormalized for display)
610
+ * @property assignedTechnologyIds - Array of technology IDs this product is assigned to
611
+ * @property description - Detailed description of the product and its purpose
587
612
  * @property technicalDetails - Technical details and specifications
588
613
  * @property warnings - List of warnings related to product use
589
614
  * @property dosage - Dosage information (if applicable)
@@ -599,10 +624,7 @@ interface Product {
599
624
  name: string;
600
625
  brandId: string;
601
626
  brandName: string;
602
- technologyId: string;
603
- technologyName: string;
604
- categoryId: string;
605
- subcategoryId: string;
627
+ assignedTechnologyIds?: string[];
606
628
  createdAt: Date;
607
629
  updatedAt: Date;
608
630
  isActive: boolean;
@@ -613,6 +635,14 @@ interface Product {
613
635
  composition?: string;
614
636
  indications?: string[];
615
637
  contraindications?: ContraindicationDynamic[];
638
+ /** Present only in subcollections - synced from technology metadata */
639
+ technologyId?: string;
640
+ /** Present only in subcollections - synced from technology name */
641
+ technologyName?: string;
642
+ /** Present only in subcollections - synced from technology categoryId */
643
+ categoryId?: string;
644
+ /** Present only in subcollections - synced from technology subcategoryId */
645
+ subcategoryId?: string;
616
646
  }
617
647
  /**
618
648
  * Collection in Firestore database where products are stored
@@ -620,9 +650,75 @@ interface Product {
620
650
  declare const PRODUCTS_COLLECTION = "products";
621
651
  /**
622
652
  * Interface for the ProductService class
653
+ *
654
+ * NOTE: This interface maintains backward compatibility while adding new top-level collection methods.
655
+ * Old methods using technologyId are kept for existing code, new methods work with top-level collection.
623
656
  */
624
657
  interface IProductService {
625
658
  /**
659
+ * Creates a new product in the top-level collection
660
+ * @param brandId - ID of the brand that manufactures this product
661
+ * @param product - Product data
662
+ * @param technologyIds - Optional array of technology IDs to assign this product to
663
+ */
664
+ createTopLevel(brandId: string, product: Omit<Product, 'id' | 'createdAt' | 'updatedAt' | 'brandId' | 'assignedTechnologyIds'>, technologyIds?: string[]): Promise<Product>;
665
+ /**
666
+ * Gets all products from the top-level collection
667
+ * @param options - Query options
668
+ */
669
+ getAllTopLevel(options: {
670
+ rowsPerPage: number;
671
+ lastVisible?: any;
672
+ brandId?: string;
673
+ }): Promise<{
674
+ products: Product[];
675
+ lastVisible: any;
676
+ }>;
677
+ /**
678
+ * Gets a product by ID from the top-level collection
679
+ * @param productId - ID of the product
680
+ */
681
+ getByIdTopLevel(productId: string): Promise<Product | null>;
682
+ /**
683
+ * Updates a product in the top-level collection
684
+ * @param productId - ID of the product to update
685
+ * @param product - Updated product data
686
+ */
687
+ updateTopLevel(productId: string, product: Partial<Omit<Product, 'id' | 'createdAt' | 'brandId'>>): Promise<Product | null>;
688
+ /**
689
+ * Deletes a product from the top-level collection (soft delete)
690
+ * @param productId - ID of the product to delete
691
+ */
692
+ deleteTopLevel(productId: string): Promise<void>;
693
+ /**
694
+ * Assigns a product to a technology
695
+ * @param productId - ID of the product
696
+ * @param technologyId - ID of the technology
697
+ */
698
+ assignToTechnology(productId: string, technologyId: string): Promise<void>;
699
+ /**
700
+ * Unassigns a product from a technology
701
+ * @param productId - ID of the product
702
+ * @param technologyId - ID of the technology
703
+ */
704
+ unassignFromTechnology(productId: string, technologyId: string): Promise<void>;
705
+ /**
706
+ * Gets products assigned to a specific technology
707
+ * @param technologyId - ID of the technology
708
+ */
709
+ getAssignedProducts(technologyId: string): Promise<Product[]>;
710
+ /**
711
+ * Gets products NOT assigned to a specific technology
712
+ * @param technologyId - ID of the technology
713
+ */
714
+ getUnassignedProducts(technologyId: string): Promise<Product[]>;
715
+ /**
716
+ * Gets all products for a brand
717
+ * @param brandId - ID of the brand
718
+ */
719
+ getByBrand(brandId: string): Promise<Product[]>;
720
+ /**
721
+ * @deprecated Use createTopLevel instead
626
722
  * Creates a new product
627
723
  * @param technologyId - ID of the technology this product is used with
628
724
  * @param brandId - ID of the brand that manufactures this product
@@ -630,6 +726,7 @@ interface IProductService {
630
726
  */
631
727
  create(technologyId: string, brandId: string, product: Omit<Product, 'id' | 'createdAt' | 'updatedAt' | 'brandId' | 'technologyId'>): Promise<Product>;
632
728
  /**
729
+ * @deprecated Use getAllTopLevel instead
633
730
  * Gets a paginated list of all products, with optional filters.
634
731
  */
635
732
  getAll(options: {
@@ -643,6 +740,7 @@ interface IProductService {
643
740
  lastVisible: any;
644
741
  }>;
645
742
  /**
743
+ * @deprecated Use alternative counting methods
646
744
  * Gets the total count of active products, with optional filters.
647
745
  */
648
746
  getProductsCount(options: {
@@ -651,6 +749,7 @@ interface IProductService {
651
749
  technologyId?: string;
652
750
  }): Promise<number>;
653
751
  /**
752
+ * @deprecated Use alternative counting methods
654
753
  * Gets counts of active products grouped by category, subcategory, and technology.
655
754
  */
656
755
  getProductCounts(): Promise<{
@@ -659,16 +758,19 @@ interface IProductService {
659
758
  byTechnology: Record<string, number>;
660
759
  }>;
661
760
  /**
761
+ * @deprecated Use getAssignedProducts instead
662
762
  * Gets all products for a specific technology (non-paginated, for filters/dropdowns)
663
763
  * @param technologyId - ID of the technology
664
764
  */
665
765
  getAllByTechnology(technologyId: string): Promise<Product[]>;
666
766
  /**
767
+ * @deprecated Use getByBrand instead
667
768
  * Gets all products for a brand
668
769
  * @param brandId - ID of the brand
669
770
  */
670
771
  getAllByBrand(brandId: string): Promise<Product[]>;
671
772
  /**
773
+ * @deprecated Use updateTopLevel instead
672
774
  * Updates a product
673
775
  * @param technologyId - ID of the technology
674
776
  * @param productId - ID of the product to update
@@ -676,12 +778,14 @@ interface IProductService {
676
778
  */
677
779
  update(technologyId: string, productId: string, product: Partial<Omit<Product, 'id' | 'createdAt' | 'brandId' | 'technologyId'>>): Promise<Product | null>;
678
780
  /**
781
+ * @deprecated Use deleteTopLevel instead
679
782
  * Deletes a product (soft delete)
680
783
  * @param technologyId - ID of the technology
681
784
  * @param productId - ID of the product to delete
682
785
  */
683
786
  delete(technologyId: string, productId: string): Promise<void>;
684
787
  /**
788
+ * @deprecated Use getByIdTopLevel instead
685
789
  * Gets a product by ID
686
790
  * @param technologyId - ID of the technology
687
791
  * @param productId - ID of the product
@@ -1468,7 +1572,12 @@ declare class DocumentationTemplateServiceBackoffice {
1468
1572
 
1469
1573
  declare class ProductService extends BaseService implements IProductService {
1470
1574
  /**
1471
- * Gets reference to products collection under a technology
1575
+ * Gets reference to top-level products collection (source of truth)
1576
+ * @returns Firestore collection reference
1577
+ */
1578
+ private getTopLevelProductsRef;
1579
+ /**
1580
+ * Gets reference to products collection under a technology (backward compatibility)
1472
1581
  * @param technologyId - ID of the technology
1473
1582
  * @returns Firestore collection reference
1474
1583
  */
@@ -1501,7 +1610,7 @@ declare class ProductService extends BaseService implements IProductService {
1501
1610
  }): Promise<number>;
1502
1611
  /**
1503
1612
  * Gets counts of active products grouped by category, subcategory, and technology.
1504
- * This uses a single collectionGroup query for efficiency.
1613
+ * Queries technology subcollections which have the legacy fields synced by Cloud Functions.
1505
1614
  */
1506
1615
  getProductCounts(): Promise<{
1507
1616
  byCategory: Record<string, number>;
@@ -1528,6 +1637,65 @@ declare class ProductService extends BaseService implements IProductService {
1528
1637
  * Gets a product by ID
1529
1638
  */
1530
1639
  getById(technologyId: string, productId: string): Promise<Product | null>;
1640
+ /**
1641
+ * Creates a new product in the top-level collection
1642
+ */
1643
+ createTopLevel(brandId: string, product: Omit<Product, 'id' | 'createdAt' | 'updatedAt' | 'brandId' | 'assignedTechnologyIds'>, technologyIds?: string[]): Promise<Product>;
1644
+ /**
1645
+ * Gets all products from the top-level collection
1646
+ */
1647
+ getAllTopLevel(options: {
1648
+ rowsPerPage: number;
1649
+ lastVisible?: any;
1650
+ brandId?: string;
1651
+ }): Promise<{
1652
+ products: Product[];
1653
+ lastVisible: any;
1654
+ }>;
1655
+ /**
1656
+ * Gets a product by ID from the top-level collection
1657
+ */
1658
+ getByIdTopLevel(productId: string): Promise<Product | null>;
1659
+ /**
1660
+ * Updates a product in the top-level collection
1661
+ */
1662
+ updateTopLevel(productId: string, product: Partial<Omit<Product, 'id' | 'createdAt' | 'brandId'>>): Promise<Product | null>;
1663
+ /**
1664
+ * Deletes a product from the top-level collection (soft delete)
1665
+ */
1666
+ deleteTopLevel(productId: string): Promise<void>;
1667
+ /**
1668
+ * Assigns a product to a technology
1669
+ */
1670
+ assignToTechnology(productId: string, technologyId: string): Promise<void>;
1671
+ /**
1672
+ * Unassigns a product from a technology
1673
+ */
1674
+ unassignFromTechnology(productId: string, technologyId: string): Promise<void>;
1675
+ /**
1676
+ * Gets products assigned to a specific technology
1677
+ */
1678
+ getAssignedProducts(technologyId: string): Promise<Product[]>;
1679
+ /**
1680
+ * Gets products NOT assigned to a specific technology
1681
+ */
1682
+ getUnassignedProducts(technologyId: string): Promise<Product[]>;
1683
+ /**
1684
+ * Gets all products for a brand (from top-level collection)
1685
+ */
1686
+ getByBrand(brandId: string): Promise<Product[]>;
1687
+ /**
1688
+ * Exports products to CSV string, suitable for Excel/Sheets.
1689
+ * Includes headers and optional UTF-8 BOM.
1690
+ * By default exports only active products (set includeInactive to true to export all).
1691
+ */
1692
+ exportToCsv(options?: {
1693
+ includeInactive?: boolean;
1694
+ includeBom?: boolean;
1695
+ }): Promise<string>;
1696
+ private productToCsvRow;
1697
+ private formatDateIso;
1698
+ private formatCsvValue;
1531
1699
  }
1532
1700
 
1533
1701
  /**
@@ -1608,6 +1776,18 @@ declare class RequirementService extends BaseService {
1608
1776
  * @returns Zahtev ili null ako ne postoji
1609
1777
  */
1610
1778
  getById(id: string): Promise<Requirement | null>;
1779
+ /**
1780
+ * Exports requirements to CSV string, suitable for Excel/Sheets.
1781
+ * Includes headers and optional UTF-8 BOM.
1782
+ * By default exports only active requirements (set includeInactive to true to export all).
1783
+ */
1784
+ exportToCsv(options?: {
1785
+ includeInactive?: boolean;
1786
+ includeBom?: boolean;
1787
+ }): Promise<string>;
1788
+ private requirementToCsvRow;
1789
+ private formatDateIso;
1790
+ private formatCsvValue;
1611
1791
  }
1612
1792
 
1613
1793
  /**
@@ -1718,6 +1898,18 @@ declare class SubcategoryService extends BaseService {
1718
1898
  * @returns Podkategorija ili null ako ne postoji
1719
1899
  */
1720
1900
  getById(categoryId: string, subcategoryId: string): Promise<Subcategory | null>;
1901
+ /**
1902
+ * Exports subcategories to CSV string, suitable for Excel/Sheets.
1903
+ * Includes headers and optional UTF-8 BOM.
1904
+ * By default exports only active subcategories (set includeInactive to true to export all).
1905
+ */
1906
+ exportToCsv(options?: {
1907
+ includeInactive?: boolean;
1908
+ includeBom?: boolean;
1909
+ }): Promise<string>;
1910
+ private subcategoryToCsvRow;
1911
+ private formatDateIso;
1912
+ private formatCsvValue;
1721
1913
  }
1722
1914
 
1723
1915
  /**
@@ -1740,10 +1932,10 @@ declare class TechnologyService extends BaseService implements ITechnologyServic
1740
1932
  isActive: boolean;
1741
1933
  description: string;
1742
1934
  family: ProcedureFamily;
1743
- categoryId: string;
1744
- subcategoryId: string;
1745
1935
  technicalDetails?: string | undefined;
1746
1936
  contraindications: ContraindicationDynamic[];
1937
+ categoryId: string;
1938
+ subcategoryId: string;
1747
1939
  requirements: {
1748
1940
  pre: Requirement[];
1749
1941
  post: Requirement[];
@@ -2012,6 +2204,54 @@ declare class TechnologyService extends BaseService implements ITechnologyServic
2012
2204
  * Gets all active technologies for filter dropdowns.
2013
2205
  */
2014
2206
  getAllForFilter(): Promise<Technology[]>;
2207
+ /**
2208
+ * Assigns multiple products to a technology
2209
+ * Updates each product's assignedTechnologyIds array
2210
+ */
2211
+ assignProducts(technologyId: string, productIds: string[]): Promise<void>;
2212
+ /**
2213
+ * Unassigns multiple products from a technology
2214
+ * Updates each product's assignedTechnologyIds array
2215
+ */
2216
+ unassignProducts(technologyId: string, productIds: string[]): Promise<void>;
2217
+ /**
2218
+ * Gets products assigned to a specific technology
2219
+ * Reads from top-level collection for immediate consistency (Cloud Functions may lag)
2220
+ */
2221
+ getAssignedProducts(technologyId: string): Promise<Product[]>;
2222
+ /**
2223
+ * Gets products NOT assigned to a specific technology
2224
+ */
2225
+ getUnassignedProducts(technologyId: string): Promise<Product[]>;
2226
+ /**
2227
+ * Gets product assignment statistics for a technology
2228
+ */
2229
+ getProductStats(technologyId: string): Promise<{
2230
+ totalAssigned: number;
2231
+ byBrand: Record<string, number>;
2232
+ }>;
2233
+ /**
2234
+ * Updates products in technology subcollection when technology metadata changes
2235
+ * @param technologyId - ID of the technology
2236
+ * @param updates - Fields to update (categoryId, subcategoryId, technologyName)
2237
+ */
2238
+ private updateProductsInSubcollection;
2239
+ /**
2240
+ * Exports technologies to CSV string, suitable for Excel/Sheets.
2241
+ * Includes headers and optional UTF-8 BOM.
2242
+ * By default exports only active technologies (set includeInactive to true to export all).
2243
+ * Includes product names from subcollections.
2244
+ */
2245
+ exportToCsv(options?: {
2246
+ includeInactive?: boolean;
2247
+ includeBom?: boolean;
2248
+ }): Promise<string>;
2249
+ /**
2250
+ * Gets product names from the technology's product subcollection
2251
+ */
2252
+ private getProductNamesForTechnology;
2253
+ private technologyToCsvRow;
2254
+ private formatCsvValue;
2015
2255
  }
2016
2256
 
2017
2257
  /**
@@ -2131,6 +2371,23 @@ declare class ConstantsService extends BaseService {
2131
2371
  * @returns {Promise<void>}
2132
2372
  */
2133
2373
  deleteContraindication(contraindicationId: string): Promise<void>;
2374
+ /**
2375
+ * Exports treatment benefits to CSV string, suitable for Excel/Sheets.
2376
+ * Includes headers and optional UTF-8 BOM.
2377
+ */
2378
+ exportBenefitsToCsv(options?: {
2379
+ includeBom?: boolean;
2380
+ }): Promise<string>;
2381
+ /**
2382
+ * Exports contraindications to CSV string, suitable for Excel/Sheets.
2383
+ * Includes headers and optional UTF-8 BOM.
2384
+ */
2385
+ exportContraindicationsToCsv(options?: {
2386
+ includeBom?: boolean;
2387
+ }): Promise<string>;
2388
+ private benefitToCsvRow;
2389
+ private contraindicationToCsvRow;
2390
+ private formatCsvValue;
2134
2391
  }
2135
2392
 
2136
2393
  declare const documentElementSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
@@ -4825,13 +5082,13 @@ declare const technologySchema: z.ZodObject<{
4825
5082
  name: string;
4826
5083
  isActive: boolean;
4827
5084
  family: ProcedureFamily;
4828
- categoryId: string;
4829
- subcategoryId: string;
4830
5085
  contraindications: {
4831
5086
  id: string;
4832
5087
  name: string;
4833
5088
  description?: string | undefined;
4834
5089
  }[];
5090
+ categoryId: string;
5091
+ subcategoryId: string;
4835
5092
  requirements: {
4836
5093
  pre: {
4837
5094
  name: string;
@@ -4970,13 +5227,13 @@ declare const technologySchema: z.ZodObject<{
4970
5227
  }, {
4971
5228
  name: string;
4972
5229
  family: ProcedureFamily;
4973
- categoryId: string;
4974
- subcategoryId: string;
4975
5230
  contraindications: {
4976
5231
  id: string;
4977
5232
  name: string;
4978
5233
  description?: string | undefined;
4979
5234
  }[];
5235
+ categoryId: string;
5236
+ subcategoryId: string;
4980
5237
  blockingConditions: BlockingCondition[];
4981
5238
  benefits: {
4982
5239
  id: string;
@@ -5839,14 +6096,14 @@ declare const technologyUpdateSchema: z.ZodObject<{
5839
6096
  isActive?: boolean | undefined;
5840
6097
  description?: string | undefined;
5841
6098
  family?: ProcedureFamily | undefined;
5842
- categoryId?: string | undefined;
5843
- subcategoryId?: string | undefined;
5844
6099
  technicalDetails?: string | undefined;
5845
6100
  contraindications?: {
5846
6101
  id: string;
5847
6102
  name: string;
5848
6103
  description?: string | undefined;
5849
6104
  }[] | undefined;
6105
+ categoryId?: string | undefined;
6106
+ subcategoryId?: string | undefined;
5850
6107
  requirements?: {
5851
6108
  pre: {
5852
6109
  name: string;
@@ -5985,14 +6242,14 @@ declare const technologyUpdateSchema: z.ZodObject<{
5985
6242
  isActive?: boolean | undefined;
5986
6243
  description?: string | undefined;
5987
6244
  family?: ProcedureFamily | undefined;
5988
- categoryId?: string | undefined;
5989
- subcategoryId?: string | undefined;
5990
6245
  technicalDetails?: string | undefined;
5991
6246
  contraindications?: {
5992
6247
  id: string;
5993
6248
  name: string;
5994
6249
  description?: string | undefined;
5995
6250
  }[] | undefined;
6251
+ categoryId?: string | undefined;
6252
+ subcategoryId?: string | undefined;
5996
6253
  requirements?: {
5997
6254
  pre: {
5998
6255
  name: string;