@blackcode_sa/metaestetics-api 1.12.42 → 1.12.45

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/dist/index.mjs CHANGED
@@ -1445,11 +1445,11 @@ function calculateItemSubtotal(item) {
1445
1445
  if (item.type === "note") {
1446
1446
  return 0;
1447
1447
  }
1448
+ const quantity = item.quantity || 0;
1448
1449
  if (item.priceOverrideAmount !== void 0 && item.priceOverrideAmount !== null) {
1449
- return item.priceOverrideAmount;
1450
+ return item.priceOverrideAmount * quantity;
1450
1451
  }
1451
1452
  const price = item.price || 0;
1452
- const quantity = item.quantity || 0;
1453
1453
  return price * quantity;
1454
1454
  }
1455
1455
  function calculateFinalBilling(zonesData, taxRate = 0.2) {
@@ -1565,7 +1565,18 @@ async function updateZoneItemUtil(db, appointmentId, zoneId, itemIndex, updates)
1565
1565
  ...updates,
1566
1566
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
1567
1567
  };
1568
+ console.log(`[updateZoneItemUtil] BEFORE recalculation:`, {
1569
+ itemIndex,
1570
+ quantity: items[itemIndex].quantity,
1571
+ priceOverrideAmount: items[itemIndex].priceOverrideAmount,
1572
+ price: items[itemIndex].price,
1573
+ oldSubtotal: items[itemIndex].subtotal
1574
+ });
1568
1575
  items[itemIndex].subtotal = calculateItemSubtotal(items[itemIndex]);
1576
+ console.log(`[updateZoneItemUtil] AFTER recalculation:`, {
1577
+ itemIndex,
1578
+ newSubtotal: items[itemIndex].subtotal
1579
+ });
1569
1580
  const finalbilling = calculateFinalBilling(metadata.zonesData);
1570
1581
  const appointmentRef = doc3(db, APPOINTMENTS_COLLECTION, appointmentId);
1571
1582
  await updateDoc3(appointmentRef, {
@@ -18959,14 +18970,8 @@ import {
18959
18970
  updateDoc as updateDoc38,
18960
18971
  where as where36,
18961
18972
  arrayUnion as arrayUnion9,
18962
- arrayRemove as arrayRemove8,
18963
- writeBatch as writeBatch7
18973
+ arrayRemove as arrayRemove8
18964
18974
  } from "firebase/firestore";
18965
-
18966
- // src/backoffice/types/product.types.ts
18967
- var PRODUCTS_COLLECTION = "products";
18968
-
18969
- // src/backoffice/services/technology.service.ts
18970
18975
  var DEFAULT_CERTIFICATION_REQUIREMENT = {
18971
18976
  minimumLevel: "aesthetician" /* AESTHETICIAN */,
18972
18977
  requiredSpecialties: []
@@ -19128,18 +19133,7 @@ var TechnologyService = class extends BaseService {
19128
19133
  });
19129
19134
  updateData.updatedAt = /* @__PURE__ */ new Date();
19130
19135
  const docRef = doc41(this.technologiesRef, id);
19131
- const beforeTech = await this.getById(id);
19132
19136
  await updateDoc38(docRef, updateData);
19133
- const categoryChanged = beforeTech && updateData.categoryId && beforeTech.categoryId !== updateData.categoryId;
19134
- const subcategoryChanged = beforeTech && updateData.subcategoryId && beforeTech.subcategoryId !== updateData.subcategoryId;
19135
- const nameChanged = beforeTech && updateData.name && beforeTech.name !== updateData.name;
19136
- if (categoryChanged || subcategoryChanged || nameChanged) {
19137
- await this.updateProductsInSubcollection(id, {
19138
- categoryId: updateData.categoryId,
19139
- subcategoryId: updateData.subcategoryId,
19140
- technologyName: updateData.name
19141
- });
19142
- }
19143
19137
  return this.getById(id);
19144
19138
  }
19145
19139
  /**
@@ -19575,125 +19569,6 @@ var TechnologyService = class extends BaseService {
19575
19569
  })
19576
19570
  );
19577
19571
  }
19578
- // ==========================================
19579
- // NEW METHODS: Product assignment management
19580
- // ==========================================
19581
- /**
19582
- * Assigns multiple products to a technology
19583
- * Updates each product's assignedTechnologyIds array
19584
- */
19585
- async assignProducts(technologyId, productIds) {
19586
- const batch = writeBatch7(this.db);
19587
- for (const productId of productIds) {
19588
- const productRef = doc41(this.db, PRODUCTS_COLLECTION, productId);
19589
- batch.update(productRef, {
19590
- assignedTechnologyIds: arrayUnion9(technologyId),
19591
- updatedAt: /* @__PURE__ */ new Date()
19592
- });
19593
- }
19594
- await batch.commit();
19595
- }
19596
- /**
19597
- * Unassigns multiple products from a technology
19598
- * Updates each product's assignedTechnologyIds array
19599
- */
19600
- async unassignProducts(technologyId, productIds) {
19601
- const batch = writeBatch7(this.db);
19602
- for (const productId of productIds) {
19603
- const productRef = doc41(this.db, PRODUCTS_COLLECTION, productId);
19604
- batch.update(productRef, {
19605
- assignedTechnologyIds: arrayRemove8(technologyId),
19606
- updatedAt: /* @__PURE__ */ new Date()
19607
- });
19608
- }
19609
- await batch.commit();
19610
- }
19611
- /**
19612
- * Gets products assigned to a specific technology
19613
- * Reads from top-level collection for immediate consistency (Cloud Functions may lag)
19614
- */
19615
- async getAssignedProducts(technologyId) {
19616
- const q = query36(
19617
- collection36(this.db, PRODUCTS_COLLECTION),
19618
- where36("assignedTechnologyIds", "array-contains", technologyId),
19619
- where36("isActive", "==", true),
19620
- orderBy22("name")
19621
- );
19622
- const snapshot = await getDocs36(q);
19623
- return snapshot.docs.map(
19624
- (doc44) => ({
19625
- id: doc44.id,
19626
- ...doc44.data()
19627
- })
19628
- );
19629
- }
19630
- /**
19631
- * Gets products NOT assigned to a specific technology
19632
- */
19633
- async getUnassignedProducts(technologyId) {
19634
- const q = query36(
19635
- collection36(this.db, PRODUCTS_COLLECTION),
19636
- where36("isActive", "==", true),
19637
- orderBy22("name")
19638
- );
19639
- const snapshot = await getDocs36(q);
19640
- const allProducts = snapshot.docs.map(
19641
- (doc44) => ({
19642
- id: doc44.id,
19643
- ...doc44.data()
19644
- })
19645
- );
19646
- return allProducts.filter(
19647
- (product) => {
19648
- var _a;
19649
- return !((_a = product.assignedTechnologyIds) == null ? void 0 : _a.includes(technologyId));
19650
- }
19651
- );
19652
- }
19653
- /**
19654
- * Gets product assignment statistics for a technology
19655
- */
19656
- async getProductStats(technologyId) {
19657
- const products = await this.getAssignedProducts(technologyId);
19658
- const byBrand = {};
19659
- products.forEach((product) => {
19660
- byBrand[product.brandName] = (byBrand[product.brandName] || 0) + 1;
19661
- });
19662
- return {
19663
- totalAssigned: products.length,
19664
- byBrand
19665
- };
19666
- }
19667
- /**
19668
- * Updates products in technology subcollection when technology metadata changes
19669
- * @param technologyId - ID of the technology
19670
- * @param updates - Fields to update (categoryId, subcategoryId, technologyName)
19671
- */
19672
- async updateProductsInSubcollection(technologyId, updates) {
19673
- const productsRef = collection36(this.db, TECHNOLOGIES_COLLECTION, technologyId, PRODUCTS_COLLECTION);
19674
- const productsSnapshot = await getDocs36(productsRef);
19675
- if (productsSnapshot.empty) {
19676
- return;
19677
- }
19678
- const batch = writeBatch7(this.db);
19679
- for (const productDoc of productsSnapshot.docs) {
19680
- const productRef = productDoc.ref;
19681
- const updateFields = {};
19682
- if (updates.categoryId !== void 0) {
19683
- updateFields.categoryId = updates.categoryId;
19684
- }
19685
- if (updates.subcategoryId !== void 0) {
19686
- updateFields.subcategoryId = updates.subcategoryId;
19687
- }
19688
- if (updates.technologyName !== void 0) {
19689
- updateFields.technologyName = updates.technologyName;
19690
- }
19691
- if (Object.keys(updateFields).length > 0) {
19692
- batch.update(productRef, updateFields);
19693
- }
19694
- }
19695
- await batch.commit();
19696
- }
19697
19572
  };
19698
19573
 
19699
19574
  // src/backoffice/services/product.service.ts
@@ -19710,20 +19585,16 @@ import {
19710
19585
  limit as limit21,
19711
19586
  orderBy as orderBy23,
19712
19587
  startAfter as startAfter19,
19713
- getCountFromServer as getCountFromServer7,
19714
- arrayUnion as arrayUnion10,
19715
- arrayRemove as arrayRemove9
19588
+ getCountFromServer as getCountFromServer7
19716
19589
  } from "firebase/firestore";
19590
+
19591
+ // src/backoffice/types/product.types.ts
19592
+ var PRODUCTS_COLLECTION = "products";
19593
+
19594
+ // src/backoffice/services/product.service.ts
19717
19595
  var ProductService = class extends BaseService {
19718
19596
  /**
19719
- * Gets reference to top-level products collection (source of truth)
19720
- * @returns Firestore collection reference
19721
- */
19722
- getTopLevelProductsRef() {
19723
- return collection37(this.db, PRODUCTS_COLLECTION);
19724
- }
19725
- /**
19726
- * Gets reference to products collection under a technology (backward compatibility)
19597
+ * Gets reference to products collection under a technology
19727
19598
  * @param technologyId - ID of the technology
19728
19599
  * @returns Firestore collection reference
19729
19600
  */
@@ -19739,7 +19610,6 @@ var ProductService = class extends BaseService {
19739
19610
  ...product,
19740
19611
  brandId,
19741
19612
  technologyId,
19742
- // Required for old subcollection structure
19743
19613
  createdAt: now,
19744
19614
  updatedAt: now,
19745
19615
  isActive: true
@@ -19799,26 +19669,30 @@ var ProductService = class extends BaseService {
19799
19669
  }
19800
19670
  /**
19801
19671
  * Gets counts of active products grouped by category, subcategory, and technology.
19802
- * Queries technology subcollections which have the legacy fields synced by Cloud Functions.
19672
+ * This uses a single collectionGroup query for efficiency.
19803
19673
  */
19804
19674
  async getProductCounts() {
19675
+ const q = query37(collectionGroup3(this.db, PRODUCTS_COLLECTION), where37("isActive", "==", true));
19676
+ const snapshot = await getDocs37(q);
19805
19677
  const counts = {
19806
19678
  byCategory: {},
19807
19679
  bySubcategory: {},
19808
19680
  byTechnology: {}
19809
19681
  };
19810
- const q = query37(collectionGroup3(this.db, PRODUCTS_COLLECTION), where37("isActive", "==", true));
19811
- const snapshot = await getDocs37(q);
19682
+ if (snapshot.empty) {
19683
+ return counts;
19684
+ }
19812
19685
  snapshot.docs.forEach((doc44) => {
19813
19686
  const product = doc44.data();
19814
- if (product.categoryId) {
19815
- counts.byCategory[product.categoryId] = (counts.byCategory[product.categoryId] || 0) + 1;
19687
+ const { categoryId, subcategoryId, technologyId } = product;
19688
+ if (categoryId) {
19689
+ counts.byCategory[categoryId] = (counts.byCategory[categoryId] || 0) + 1;
19816
19690
  }
19817
- if (product.subcategoryId) {
19818
- counts.bySubcategory[product.subcategoryId] = (counts.bySubcategory[product.subcategoryId] || 0) + 1;
19691
+ if (subcategoryId) {
19692
+ counts.bySubcategory[subcategoryId] = (counts.bySubcategory[subcategoryId] || 0) + 1;
19819
19693
  }
19820
- if (product.technologyId) {
19821
- counts.byTechnology[product.technologyId] = (counts.byTechnology[product.technologyId] || 0) + 1;
19694
+ if (technologyId) {
19695
+ counts.byTechnology[technologyId] = (counts.byTechnology[technologyId] || 0) + 1;
19822
19696
  }
19823
19697
  });
19824
19698
  return counts;
@@ -19897,166 +19771,12 @@ var ProductService = class extends BaseService {
19897
19771
  ...docSnap.data()
19898
19772
  };
19899
19773
  }
19900
- // ==========================================
19901
- // NEW METHODS: Top-level collection (preferred)
19902
- // ==========================================
19903
- /**
19904
- * Creates a new product in the top-level collection
19905
- */
19906
- async createTopLevel(brandId, product, technologyIds = []) {
19907
- const now = /* @__PURE__ */ new Date();
19908
- const newProduct = {
19909
- ...product,
19910
- brandId,
19911
- assignedTechnologyIds: technologyIds,
19912
- createdAt: now,
19913
- updatedAt: now,
19914
- isActive: true
19915
- };
19916
- const productRef = await addDoc8(this.getTopLevelProductsRef(), newProduct);
19917
- return { id: productRef.id, ...newProduct };
19918
- }
19919
- /**
19920
- * Gets all products from the top-level collection
19921
- */
19922
- async getAllTopLevel(options) {
19923
- const { rowsPerPage, lastVisible, brandId } = options;
19924
- const constraints = [where37("isActive", "==", true), orderBy23("name")];
19925
- if (brandId) {
19926
- constraints.push(where37("brandId", "==", brandId));
19927
- }
19928
- if (lastVisible) {
19929
- constraints.push(startAfter19(lastVisible));
19930
- }
19931
- constraints.push(limit21(rowsPerPage));
19932
- const q = query37(this.getTopLevelProductsRef(), ...constraints);
19933
- const snapshot = await getDocs37(q);
19934
- const products = snapshot.docs.map(
19935
- (doc44) => ({
19936
- id: doc44.id,
19937
- ...doc44.data()
19938
- })
19939
- );
19940
- const newLastVisible = snapshot.docs[snapshot.docs.length - 1];
19941
- return { products, lastVisible: newLastVisible };
19942
- }
19943
- /**
19944
- * Gets a product by ID from the top-level collection
19945
- */
19946
- async getByIdTopLevel(productId) {
19947
- const docRef = doc42(this.getTopLevelProductsRef(), productId);
19948
- const docSnap = await getDoc43(docRef);
19949
- if (!docSnap.exists()) return null;
19950
- return {
19951
- id: docSnap.id,
19952
- ...docSnap.data()
19953
- };
19954
- }
19955
- /**
19956
- * Updates a product in the top-level collection
19957
- */
19958
- async updateTopLevel(productId, product) {
19959
- const updateData = {
19960
- ...product,
19961
- updatedAt: /* @__PURE__ */ new Date()
19962
- };
19963
- const docRef = doc42(this.getTopLevelProductsRef(), productId);
19964
- await updateDoc39(docRef, updateData);
19965
- return this.getByIdTopLevel(productId);
19966
- }
19967
- /**
19968
- * Deletes a product from the top-level collection (soft delete)
19969
- */
19970
- async deleteTopLevel(productId) {
19971
- await this.updateTopLevel(productId, {
19972
- isActive: false
19973
- });
19974
- }
19975
- /**
19976
- * Assigns a product to a technology
19977
- */
19978
- async assignToTechnology(productId, technologyId) {
19979
- const docRef = doc42(this.getTopLevelProductsRef(), productId);
19980
- await updateDoc39(docRef, {
19981
- assignedTechnologyIds: arrayUnion10(technologyId),
19982
- updatedAt: /* @__PURE__ */ new Date()
19983
- });
19984
- }
19985
- /**
19986
- * Unassigns a product from a technology
19987
- */
19988
- async unassignFromTechnology(productId, technologyId) {
19989
- const docRef = doc42(this.getTopLevelProductsRef(), productId);
19990
- await updateDoc39(docRef, {
19991
- assignedTechnologyIds: arrayRemove9(technologyId),
19992
- updatedAt: /* @__PURE__ */ new Date()
19993
- });
19994
- }
19995
- /**
19996
- * Gets products assigned to a specific technology
19997
- */
19998
- async getAssignedProducts(technologyId) {
19999
- const q = query37(
20000
- this.getTopLevelProductsRef(),
20001
- where37("assignedTechnologyIds", "array-contains", technologyId),
20002
- where37("isActive", "==", true),
20003
- orderBy23("name")
20004
- );
20005
- const snapshot = await getDocs37(q);
20006
- return snapshot.docs.map(
20007
- (doc44) => ({
20008
- id: doc44.id,
20009
- ...doc44.data()
20010
- })
20011
- );
20012
- }
20013
- /**
20014
- * Gets products NOT assigned to a specific technology
20015
- */
20016
- async getUnassignedProducts(technologyId) {
20017
- const q = query37(
20018
- this.getTopLevelProductsRef(),
20019
- where37("isActive", "==", true),
20020
- orderBy23("name")
20021
- );
20022
- const snapshot = await getDocs37(q);
20023
- const allProducts = snapshot.docs.map(
20024
- (doc44) => ({
20025
- id: doc44.id,
20026
- ...doc44.data()
20027
- })
20028
- );
20029
- return allProducts.filter(
20030
- (product) => {
20031
- var _a;
20032
- return !((_a = product.assignedTechnologyIds) == null ? void 0 : _a.includes(technologyId));
20033
- }
20034
- );
20035
- }
20036
- /**
20037
- * Gets all products for a brand (from top-level collection)
20038
- */
20039
- async getByBrand(brandId) {
20040
- const q = query37(
20041
- this.getTopLevelProductsRef(),
20042
- where37("brandId", "==", brandId),
20043
- where37("isActive", "==", true),
20044
- orderBy23("name")
20045
- );
20046
- const snapshot = await getDocs37(q);
20047
- return snapshot.docs.map(
20048
- (doc44) => ({
20049
- id: doc44.id,
20050
- ...doc44.data()
20051
- })
20052
- );
20053
- }
20054
19774
  };
20055
19775
 
20056
19776
  // src/backoffice/services/constants.service.ts
20057
19777
  import {
20058
- arrayRemove as arrayRemove10,
20059
- arrayUnion as arrayUnion11,
19778
+ arrayRemove as arrayRemove9,
19779
+ arrayUnion as arrayUnion10,
20060
19780
  doc as doc43,
20061
19781
  getDoc as getDoc44,
20062
19782
  setDoc as setDoc30,
@@ -20124,7 +19844,7 @@ var ConstantsService = class extends BaseService {
20124
19844
  await setDoc30(this.treatmentBenefitsDocRef, { benefits: [newBenefit] });
20125
19845
  } else {
20126
19846
  await updateDoc40(this.treatmentBenefitsDocRef, {
20127
- benefits: arrayUnion11(newBenefit)
19847
+ benefits: arrayUnion10(newBenefit)
20128
19848
  });
20129
19849
  }
20130
19850
  return newBenefit;
@@ -20178,7 +19898,7 @@ var ConstantsService = class extends BaseService {
20178
19898
  return;
20179
19899
  }
20180
19900
  await updateDoc40(this.treatmentBenefitsDocRef, {
20181
- benefits: arrayRemove10(benefitToRemove)
19901
+ benefits: arrayRemove9(benefitToRemove)
20182
19902
  });
20183
19903
  }
20184
19904
  // =================================================================
@@ -20231,7 +19951,7 @@ var ConstantsService = class extends BaseService {
20231
19951
  });
20232
19952
  } else {
20233
19953
  await updateDoc40(this.contraindicationsDocRef, {
20234
- contraindications: arrayUnion11(newContraindication)
19954
+ contraindications: arrayUnion10(newContraindication)
20235
19955
  });
20236
19956
  }
20237
19957
  return newContraindication;
@@ -20287,7 +20007,7 @@ var ConstantsService = class extends BaseService {
20287
20007
  return;
20288
20008
  }
20289
20009
  await updateDoc40(this.contraindicationsDocRef, {
20290
- contraindications: arrayRemove10(toRemove)
20010
+ contraindications: arrayRemove9(toRemove)
20291
20011
  });
20292
20012
  }
20293
20013
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@blackcode_sa/metaestetics-api",
3
3
  "private": false,
4
- "version": "1.12.42",
4
+ "version": "1.12.45",
5
5
  "description": "Firebase authentication service with anonymous upgrade support",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",