@blackcode_sa/metaestetics-api 1.5.9 → 1.5.11

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.js CHANGED
@@ -6432,22 +6432,14 @@ var procedureSchema = createProcedureSchema.extend({
6432
6432
  updatedAt: import_zod16.z.date()
6433
6433
  });
6434
6434
 
6435
- // src/backoffice/types/category.types.ts
6436
- var CATEGORIES_COLLECTION = "backoffice_categories";
6437
-
6438
- // src/backoffice/types/subcategory.types.ts
6439
- var SUBCATEGORIES_COLLECTION = "subcategories";
6440
-
6441
- // src/backoffice/types/technology.types.ts
6442
- var TECHNOLOGIES_COLLECTION = "technologies";
6443
-
6444
- // src/backoffice/types/product.types.ts
6445
- var PRODUCTS_COLLECTION = "products";
6446
-
6447
6435
  // src/services/procedure/procedure.service.ts
6448
6436
  var ProcedureService = class extends BaseService {
6449
- constructor(db, auth, app) {
6437
+ constructor(db, auth, app, categoryService, subcategoryService, technologyService, productService) {
6450
6438
  super(db, auth, app);
6439
+ this.categoryService = categoryService;
6440
+ this.subcategoryService = subcategoryService;
6441
+ this.technologyService = technologyService;
6442
+ this.productService = productService;
6451
6443
  }
6452
6444
  /**
6453
6445
  * Creates a new procedure
@@ -6457,10 +6449,18 @@ var ProcedureService = class extends BaseService {
6457
6449
  async createProcedure(data) {
6458
6450
  const validatedData = createProcedureSchema.parse(data);
6459
6451
  const [category, subcategory, technology, product] = await Promise.all([
6460
- this.getCategory(validatedData.categoryId),
6461
- this.getSubcategory(validatedData.subcategoryId),
6462
- this.getTechnology(validatedData.technologyId),
6463
- this.getProduct(validatedData.productId)
6452
+ this.categoryService.getById(validatedData.categoryId),
6453
+ this.subcategoryService.getById(
6454
+ validatedData.categoryId,
6455
+ validatedData.subcategoryId
6456
+ ),
6457
+ this.technologyService.getById(validatedData.technologyId),
6458
+ this.productService.getById(
6459
+ validatedData.categoryId,
6460
+ validatedData.subcategoryId,
6461
+ validatedData.technologyId,
6462
+ validatedData.productId
6463
+ )
6464
6464
  ]);
6465
6465
  if (!category || !subcategory || !technology || !product) {
6466
6466
  throw new Error("One or more required entities not found");
@@ -6567,40 +6567,46 @@ var ProcedureService = class extends BaseService {
6567
6567
  });
6568
6568
  }
6569
6569
  /**
6570
- * Gets a category by ID
6571
- * @private
6572
- */
6573
- async getCategory(id) {
6574
- const docRef = (0, import_firestore21.doc)(this.db, CATEGORIES_COLLECTION, id);
6575
- const docSnap = await (0, import_firestore21.getDoc)(docRef);
6576
- return docSnap.exists() ? docSnap.data() : null;
6577
- }
6578
- /**
6579
- * Gets a subcategory by ID
6580
- * @private
6581
- */
6582
- async getSubcategory(id) {
6583
- const docRef = (0, import_firestore21.doc)(this.db, SUBCATEGORIES_COLLECTION, id);
6584
- const docSnap = await (0, import_firestore21.getDoc)(docRef);
6585
- return docSnap.exists() ? docSnap.data() : null;
6586
- }
6587
- /**
6588
- * Gets a technology by ID
6589
- * @private
6590
- */
6591
- async getTechnology(id) {
6592
- const docRef = (0, import_firestore21.doc)(this.db, TECHNOLOGIES_COLLECTION, id);
6593
- const docSnap = await (0, import_firestore21.getDoc)(docRef);
6594
- return docSnap.exists() ? docSnap.data() : null;
6595
- }
6596
- /**
6597
- * Gets a product by ID
6598
- * @private
6599
- */
6600
- async getProduct(id) {
6601
- const docRef = (0, import_firestore21.doc)(this.db, PRODUCTS_COLLECTION, id);
6602
- const docSnap = await (0, import_firestore21.getDoc)(docRef);
6603
- return docSnap.exists() ? docSnap.data() : null;
6570
+ * Gets all procedures that a practitioner is certified to perform
6571
+ * @param practitioner - The practitioner's profile
6572
+ * @returns Object containing:
6573
+ * - procedures: List of procedures the practitioner can perform
6574
+ * - families: List of procedure families the practitioner can perform
6575
+ * - categories: List of category IDs the practitioner can perform
6576
+ * - subcategories: List of subcategory IDs the practitioner can perform
6577
+ *
6578
+ * @example
6579
+ * const practitioner = {
6580
+ * certification: {
6581
+ * level: CertificationLevel.DOCTOR,
6582
+ * specialties: [CertificationSpecialty.INJECTABLES]
6583
+ * }
6584
+ * };
6585
+ * const allowedProcedures = await procedureService.getAllowedProcedures(practitioner);
6586
+ * console.log(allowedProcedures.families); // [ProcedureFamily.AESTHETICS]
6587
+ * console.log(allowedProcedures.categories); // ["category1", "category2"]
6588
+ * console.log(allowedProcedures.subcategories); // ["subcategory1", "subcategory2"]
6589
+ */
6590
+ async getAllowedProcedures(practitioner) {
6591
+ const { technologies, families, categories, subcategories } = await this.technologyService.getAllowedTechnologies(practitioner);
6592
+ const procedures = await Promise.all(
6593
+ technologies.map(async (technology) => {
6594
+ const q = (0, import_firestore21.query)(
6595
+ (0, import_firestore21.collection)(this.db, PROCEDURES_COLLECTION),
6596
+ (0, import_firestore21.where)("technologyId", "==", technology.id),
6597
+ (0, import_firestore21.where)("isActive", "==", true)
6598
+ );
6599
+ const snapshot = await (0, import_firestore21.getDocs)(q);
6600
+ return snapshot.docs.map((doc26) => doc26.data());
6601
+ })
6602
+ );
6603
+ const flattenedProcedures = procedures.flat();
6604
+ return {
6605
+ procedures: flattenedProcedures,
6606
+ families,
6607
+ categories,
6608
+ subcategories
6609
+ };
6604
6610
  }
6605
6611
  };
6606
6612
 
@@ -9616,6 +9622,11 @@ var BrandService = class extends BaseService {
9616
9622
 
9617
9623
  // src/backoffice/services/category.service.ts
9618
9624
  var import_firestore35 = require("firebase/firestore");
9625
+
9626
+ // src/backoffice/types/category.types.ts
9627
+ var CATEGORIES_COLLECTION = "backoffice_categories";
9628
+
9629
+ // src/backoffice/services/category.service.ts
9619
9630
  var CategoryService = class extends BaseService {
9620
9631
  /**
9621
9632
  * Referenca na Firestore kolekciju kategorija
@@ -9712,6 +9723,11 @@ var CategoryService = class extends BaseService {
9712
9723
 
9713
9724
  // src/backoffice/services/subcategory.service.ts
9714
9725
  var import_firestore36 = require("firebase/firestore");
9726
+
9727
+ // src/backoffice/types/subcategory.types.ts
9728
+ var SUBCATEGORIES_COLLECTION = "subcategories";
9729
+
9730
+ // src/backoffice/services/subcategory.service.ts
9715
9731
  var SubcategoryService = class extends BaseService {
9716
9732
  /**
9717
9733
  * Vraća referencu na Firestore kolekciju podkategorija za određenu kategoriju
@@ -9807,66 +9823,108 @@ var SubcategoryService = class extends BaseService {
9807
9823
 
9808
9824
  // src/backoffice/services/technology.service.ts
9809
9825
  var import_firestore37 = require("firebase/firestore");
9826
+
9827
+ // src/backoffice/types/technology.types.ts
9828
+ var TECHNOLOGIES_COLLECTION = "technologies";
9829
+
9830
+ // src/backoffice/services/technology.service.ts
9810
9831
  var DEFAULT_CERTIFICATION_REQUIREMENT = {
9811
9832
  minimumLevel: "aesthetician" /* AESTHETICIAN */,
9812
9833
  requiredSpecialties: []
9813
9834
  };
9814
9835
  var TechnologyService = class extends BaseService {
9815
9836
  /**
9816
- * Vraća referencu na Firestore kolekciju tehnologija za određenu podkategoriju
9817
- * @param categoryId - ID kategorije
9818
- * @param subcategoryId - ID podkategorije
9837
+ * Vraća referencu na Firestore kolekciju tehnologija
9819
9838
  */
9820
- getTechnologiesRef(categoryId, subcategoryId) {
9821
- return (0, import_firestore37.collection)(
9822
- this.db,
9823
- CATEGORIES_COLLECTION,
9824
- categoryId,
9825
- SUBCATEGORIES_COLLECTION,
9826
- subcategoryId,
9827
- TECHNOLOGIES_COLLECTION
9828
- );
9839
+ getTechnologiesRef() {
9840
+ return (0, import_firestore37.collection)(this.db, TECHNOLOGIES_COLLECTION);
9829
9841
  }
9830
9842
  /**
9831
- * Kreira novu tehnologiju u okviru podkategorije
9832
- * @param categoryId - ID kategorije
9833
- * @param subcategoryId - ID podkategorije
9843
+ * Kreira novu tehnologiju
9834
9844
  * @param technology - Podaci za novu tehnologiju
9835
9845
  * @returns Kreirana tehnologija sa generisanim ID-em
9836
9846
  */
9837
- async create(categoryId, subcategoryId, technology) {
9847
+ async create(technology) {
9838
9848
  const now = /* @__PURE__ */ new Date();
9839
9849
  const newTechnology = {
9840
9850
  ...technology,
9841
- subcategoryId,
9842
9851
  createdAt: now,
9843
9852
  updatedAt: now,
9844
9853
  isActive: true,
9845
- requirements: {
9854
+ requirements: technology.requirements || {
9846
9855
  pre: [],
9847
9856
  post: []
9848
9857
  },
9849
- blockingConditions: [],
9850
- contraindications: [],
9851
- benefits: [],
9858
+ blockingConditions: technology.blockingConditions || [],
9859
+ contraindications: technology.contraindications || [],
9860
+ benefits: technology.benefits || [],
9852
9861
  certificationRequirement: technology.certificationRequirement || DEFAULT_CERTIFICATION_REQUIREMENT
9853
9862
  };
9854
- const docRef = await (0, import_firestore37.addDoc)(
9855
- this.getTechnologiesRef(categoryId, subcategoryId),
9856
- newTechnology
9857
- );
9863
+ const docRef = await (0, import_firestore37.addDoc)(this.getTechnologiesRef(), newTechnology);
9858
9864
  return { id: docRef.id, ...newTechnology };
9859
9865
  }
9860
9866
  /**
9861
- * Vraća sve aktivne tehnologije za određenu podkategoriju
9867
+ * Vraća sve aktivne tehnologije
9868
+ * @returns Lista aktivnih tehnologija
9869
+ */
9870
+ async getAll() {
9871
+ const q = (0, import_firestore37.query)(this.getTechnologiesRef(), (0, import_firestore37.where)("isActive", "==", true));
9872
+ const snapshot = await (0, import_firestore37.getDocs)(q);
9873
+ return snapshot.docs.map(
9874
+ (doc26) => ({
9875
+ id: doc26.id,
9876
+ ...doc26.data()
9877
+ })
9878
+ );
9879
+ }
9880
+ /**
9881
+ * Vraća sve aktivne tehnologije za određenu familiju
9882
+ * @param family - Familija procedura
9883
+ * @returns Lista aktivnih tehnologija
9884
+ */
9885
+ async getAllByFamily(family) {
9886
+ const q = (0, import_firestore37.query)(
9887
+ this.getTechnologiesRef(),
9888
+ (0, import_firestore37.where)("isActive", "==", true),
9889
+ (0, import_firestore37.where)("family", "==", family)
9890
+ );
9891
+ const snapshot = await (0, import_firestore37.getDocs)(q);
9892
+ return snapshot.docs.map(
9893
+ (doc26) => ({
9894
+ id: doc26.id,
9895
+ ...doc26.data()
9896
+ })
9897
+ );
9898
+ }
9899
+ /**
9900
+ * Vraća sve aktivne tehnologije za određenu kategoriju
9862
9901
  * @param categoryId - ID kategorije
9902
+ * @returns Lista aktivnih tehnologija
9903
+ */
9904
+ async getAllByCategoryId(categoryId) {
9905
+ const q = (0, import_firestore37.query)(
9906
+ this.getTechnologiesRef(),
9907
+ (0, import_firestore37.where)("isActive", "==", true),
9908
+ (0, import_firestore37.where)("categoryId", "==", categoryId)
9909
+ );
9910
+ const snapshot = await (0, import_firestore37.getDocs)(q);
9911
+ return snapshot.docs.map(
9912
+ (doc26) => ({
9913
+ id: doc26.id,
9914
+ ...doc26.data()
9915
+ })
9916
+ );
9917
+ }
9918
+ /**
9919
+ * Vraća sve aktivne tehnologije za određenu podkategoriju
9863
9920
  * @param subcategoryId - ID podkategorije
9864
9921
  * @returns Lista aktivnih tehnologija
9865
9922
  */
9866
- async getAllBySubcategoryId(categoryId, subcategoryId) {
9923
+ async getAllBySubcategoryId(subcategoryId) {
9867
9924
  const q = (0, import_firestore37.query)(
9868
- this.getTechnologiesRef(categoryId, subcategoryId),
9869
- (0, import_firestore37.where)("isActive", "==", true)
9925
+ this.getTechnologiesRef(),
9926
+ (0, import_firestore37.where)("isActive", "==", true),
9927
+ (0, import_firestore37.where)("subcategoryId", "==", subcategoryId)
9870
9928
  );
9871
9929
  const snapshot = await (0, import_firestore37.getDocs)(q);
9872
9930
  return snapshot.docs.map(
@@ -9878,47 +9936,35 @@ var TechnologyService = class extends BaseService {
9878
9936
  }
9879
9937
  /**
9880
9938
  * Ažurira postojeću tehnologiju
9881
- * @param categoryId - ID kategorije
9882
- * @param subcategoryId - ID podkategorije
9883
9939
  * @param technologyId - ID tehnologije
9884
9940
  * @param technology - Novi podaci za tehnologiju
9885
9941
  * @returns Ažurirana tehnologija
9886
9942
  */
9887
- async update(categoryId, subcategoryId, technologyId, technology) {
9943
+ async update(technologyId, technology) {
9888
9944
  const updateData = {
9889
9945
  ...technology,
9890
9946
  updatedAt: /* @__PURE__ */ new Date()
9891
9947
  };
9892
- const docRef = (0, import_firestore37.doc)(
9893
- this.getTechnologiesRef(categoryId, subcategoryId),
9894
- technologyId
9895
- );
9948
+ const docRef = (0, import_firestore37.doc)(this.getTechnologiesRef(), technologyId);
9896
9949
  await (0, import_firestore37.updateDoc)(docRef, updateData);
9897
- return this.getById(categoryId, subcategoryId, technologyId);
9950
+ return this.getById(technologyId);
9898
9951
  }
9899
9952
  /**
9900
9953
  * Soft delete tehnologije (postavlja isActive na false)
9901
- * @param categoryId - ID kategorije
9902
- * @param subcategoryId - ID podkategorije
9903
9954
  * @param technologyId - ID tehnologije koja se briše
9904
9955
  */
9905
- async delete(categoryId, subcategoryId, technologyId) {
9906
- await this.update(categoryId, subcategoryId, technologyId, {
9956
+ async delete(technologyId) {
9957
+ await this.update(technologyId, {
9907
9958
  isActive: false
9908
9959
  });
9909
9960
  }
9910
9961
  /**
9911
9962
  * Vraća tehnologiju po ID-u
9912
- * @param categoryId - ID kategorije
9913
- * @param subcategoryId - ID podkategorije
9914
9963
  * @param technologyId - ID tražene tehnologije
9915
9964
  * @returns Tehnologija ili null ako ne postoji
9916
9965
  */
9917
- async getById(categoryId, subcategoryId, technologyId) {
9918
- const docRef = (0, import_firestore37.doc)(
9919
- this.getTechnologiesRef(categoryId, subcategoryId),
9920
- technologyId
9921
- );
9966
+ async getById(technologyId) {
9967
+ const docRef = (0, import_firestore37.doc)(this.getTechnologiesRef(), technologyId);
9922
9968
  const docSnap = await (0, import_firestore37.getDoc)(docRef);
9923
9969
  if (!docSnap.exists()) return null;
9924
9970
  return {
@@ -9928,58 +9974,42 @@ var TechnologyService = class extends BaseService {
9928
9974
  }
9929
9975
  /**
9930
9976
  * Dodaje novi zahtev tehnologiji
9931
- * @param categoryId - ID kategorije
9932
- * @param subcategoryId - ID podkategorije
9933
9977
  * @param technologyId - ID tehnologije
9934
9978
  * @param requirement - Zahtev koji se dodaje
9935
9979
  * @returns Ažurirana tehnologija sa novim zahtevom
9936
9980
  */
9937
- async addRequirement(categoryId, subcategoryId, technologyId, requirement) {
9938
- const docRef = (0, import_firestore37.doc)(
9939
- this.getTechnologiesRef(categoryId, subcategoryId),
9940
- technologyId
9941
- );
9981
+ async addRequirement(technologyId, requirement) {
9982
+ const docRef = (0, import_firestore37.doc)(this.getTechnologiesRef(), technologyId);
9942
9983
  const requirementType = requirement.type === "pre" ? "requirements.pre" : "requirements.post";
9943
9984
  await (0, import_firestore37.updateDoc)(docRef, {
9944
9985
  [requirementType]: (0, import_firestore37.arrayUnion)(requirement),
9945
9986
  updatedAt: /* @__PURE__ */ new Date()
9946
9987
  });
9947
- return this.getById(categoryId, subcategoryId, technologyId);
9988
+ return this.getById(technologyId);
9948
9989
  }
9949
9990
  /**
9950
9991
  * Uklanja zahtev iz tehnologije
9951
- * @param categoryId - ID kategorije
9952
- * @param subcategoryId - ID podkategorije
9953
9992
  * @param technologyId - ID tehnologije
9954
9993
  * @param requirement - Zahtev koji se uklanja
9955
9994
  * @returns Ažurirana tehnologija bez uklonjenog zahteva
9956
9995
  */
9957
- async removeRequirement(categoryId, subcategoryId, technologyId, requirement) {
9958
- const docRef = (0, import_firestore37.doc)(
9959
- this.getTechnologiesRef(categoryId, subcategoryId),
9960
- technologyId
9961
- );
9996
+ async removeRequirement(technologyId, requirement) {
9997
+ const docRef = (0, import_firestore37.doc)(this.getTechnologiesRef(), technologyId);
9962
9998
  const requirementType = requirement.type === "pre" ? "requirements.pre" : "requirements.post";
9963
9999
  await (0, import_firestore37.updateDoc)(docRef, {
9964
10000
  [requirementType]: (0, import_firestore37.arrayRemove)(requirement),
9965
10001
  updatedAt: /* @__PURE__ */ new Date()
9966
10002
  });
9967
- return this.getById(categoryId, subcategoryId, technologyId);
10003
+ return this.getById(technologyId);
9968
10004
  }
9969
10005
  /**
9970
10006
  * Vraća sve zahteve za tehnologiju
9971
- * @param categoryId - ID kategorije
9972
- * @param subcategoryId - ID podkategorije
9973
10007
  * @param technologyId - ID tehnologije
9974
10008
  * @param type - Opcioni filter za tip zahteva (pre/post)
9975
10009
  * @returns Lista zahteva
9976
10010
  */
9977
- async getRequirements(categoryId, subcategoryId, technologyId, type) {
9978
- const technology = await this.getById(
9979
- categoryId,
9980
- subcategoryId,
9981
- technologyId
9982
- );
10011
+ async getRequirements(technologyId, type) {
10012
+ const technology = await this.getById(technologyId);
9983
10013
  if (!technology || !technology.requirements) return [];
9984
10014
  if (type) {
9985
10015
  return technology.requirements[type];
@@ -9988,224 +10018,240 @@ var TechnologyService = class extends BaseService {
9988
10018
  }
9989
10019
  /**
9990
10020
  * Ažurira postojeći zahtev
9991
- * @param categoryId - ID kategorije
9992
- * @param subcategoryId - ID podkategorije
9993
10021
  * @param technologyId - ID tehnologije
9994
10022
  * @param oldRequirement - Stari zahtev koji se menja
9995
10023
  * @param newRequirement - Novi zahtev koji zamenjuje stari
9996
10024
  * @returns Ažurirana tehnologija
9997
10025
  */
9998
- async updateRequirement(categoryId, subcategoryId, technologyId, oldRequirement, newRequirement) {
9999
- await this.removeRequirement(
10000
- categoryId,
10001
- subcategoryId,
10002
- technologyId,
10003
- oldRequirement
10004
- );
10005
- return this.addRequirement(
10006
- categoryId,
10007
- subcategoryId,
10008
- technologyId,
10009
- newRequirement
10010
- );
10026
+ async updateRequirement(technologyId, oldRequirement, newRequirement) {
10027
+ await this.removeRequirement(technologyId, oldRequirement);
10028
+ return this.addRequirement(technologyId, newRequirement);
10011
10029
  }
10012
10030
  /**
10013
10031
  * Dodaje blokirajući uslov tehnologiji
10014
- * @param categoryId - ID kategorije
10015
- * @param subcategoryId - ID podkategorije
10016
10032
  * @param technologyId - ID tehnologije
10017
10033
  * @param condition - Blokirajući uslov koji se dodaje
10018
10034
  * @returns Ažurirana tehnologija
10019
10035
  */
10020
- async addBlockingCondition(categoryId, subcategoryId, technologyId, condition) {
10021
- const docRef = (0, import_firestore37.doc)(
10022
- this.getTechnologiesRef(categoryId, subcategoryId),
10023
- technologyId
10024
- );
10036
+ async addBlockingCondition(technologyId, condition) {
10037
+ const docRef = (0, import_firestore37.doc)(this.getTechnologiesRef(), technologyId);
10025
10038
  await (0, import_firestore37.updateDoc)(docRef, {
10026
10039
  blockingConditions: (0, import_firestore37.arrayUnion)(condition),
10027
10040
  updatedAt: /* @__PURE__ */ new Date()
10028
10041
  });
10029
- return this.getById(categoryId, subcategoryId, technologyId);
10042
+ return this.getById(technologyId);
10030
10043
  }
10031
10044
  /**
10032
10045
  * Uklanja blokirajući uslov iz tehnologije
10033
- * @param categoryId - ID kategorije
10034
- * @param subcategoryId - ID podkategorije
10035
10046
  * @param technologyId - ID tehnologije
10036
10047
  * @param condition - Blokirajući uslov koji se uklanja
10037
10048
  * @returns Ažurirana tehnologija
10038
10049
  */
10039
- async removeBlockingCondition(categoryId, subcategoryId, technologyId, condition) {
10040
- const docRef = (0, import_firestore37.doc)(
10041
- this.getTechnologiesRef(categoryId, subcategoryId),
10042
- technologyId
10043
- );
10050
+ async removeBlockingCondition(technologyId, condition) {
10051
+ const docRef = (0, import_firestore37.doc)(this.getTechnologiesRef(), technologyId);
10044
10052
  await (0, import_firestore37.updateDoc)(docRef, {
10045
10053
  blockingConditions: (0, import_firestore37.arrayRemove)(condition),
10046
10054
  updatedAt: /* @__PURE__ */ new Date()
10047
10055
  });
10048
- return this.getById(categoryId, subcategoryId, technologyId);
10056
+ return this.getById(technologyId);
10049
10057
  }
10050
10058
  /**
10051
10059
  * Dodaje kontraindikaciju tehnologiji
10052
- * @param categoryId - ID kategorije
10053
- * @param subcategoryId - ID podkategorije
10054
10060
  * @param technologyId - ID tehnologije
10055
10061
  * @param contraindication - Kontraindikacija koja se dodaje
10056
10062
  * @returns Ažurirana tehnologija
10057
10063
  */
10058
- async addContraindication(categoryId, subcategoryId, technologyId, contraindication) {
10059
- const docRef = (0, import_firestore37.doc)(
10060
- this.getTechnologiesRef(categoryId, subcategoryId),
10061
- technologyId
10062
- );
10064
+ async addContraindication(technologyId, contraindication) {
10065
+ const docRef = (0, import_firestore37.doc)(this.getTechnologiesRef(), technologyId);
10063
10066
  await (0, import_firestore37.updateDoc)(docRef, {
10064
10067
  contraindications: (0, import_firestore37.arrayUnion)(contraindication),
10065
10068
  updatedAt: /* @__PURE__ */ new Date()
10066
10069
  });
10067
- return this.getById(categoryId, subcategoryId, technologyId);
10070
+ return this.getById(technologyId);
10068
10071
  }
10069
10072
  /**
10070
10073
  * Uklanja kontraindikaciju iz tehnologije
10071
- * @param categoryId - ID kategorije
10072
- * @param subcategoryId - ID podkategorije
10073
10074
  * @param technologyId - ID tehnologije
10074
10075
  * @param contraindication - Kontraindikacija koja se uklanja
10075
10076
  * @returns Ažurirana tehnologija
10076
10077
  */
10077
- async removeContraindication(categoryId, subcategoryId, technologyId, contraindication) {
10078
- const docRef = (0, import_firestore37.doc)(
10079
- this.getTechnologiesRef(categoryId, subcategoryId),
10080
- technologyId
10081
- );
10078
+ async removeContraindication(technologyId, contraindication) {
10079
+ const docRef = (0, import_firestore37.doc)(this.getTechnologiesRef(), technologyId);
10082
10080
  await (0, import_firestore37.updateDoc)(docRef, {
10083
10081
  contraindications: (0, import_firestore37.arrayRemove)(contraindication),
10084
10082
  updatedAt: /* @__PURE__ */ new Date()
10085
10083
  });
10086
- return this.getById(categoryId, subcategoryId, technologyId);
10084
+ return this.getById(technologyId);
10087
10085
  }
10088
10086
  /**
10089
10087
  * Dodaje benefit tehnologiji
10090
- * @param categoryId - ID kategorije
10091
- * @param subcategoryId - ID podkategorije
10092
10088
  * @param technologyId - ID tehnologije
10093
10089
  * @param benefit - Benefit koji se dodaje
10094
10090
  * @returns Ažurirana tehnologija
10095
10091
  */
10096
- async addBenefit(categoryId, subcategoryId, technologyId, benefit) {
10097
- const docRef = (0, import_firestore37.doc)(
10098
- this.getTechnologiesRef(categoryId, subcategoryId),
10099
- technologyId
10100
- );
10092
+ async addBenefit(technologyId, benefit) {
10093
+ const docRef = (0, import_firestore37.doc)(this.getTechnologiesRef(), technologyId);
10101
10094
  await (0, import_firestore37.updateDoc)(docRef, {
10102
10095
  benefits: (0, import_firestore37.arrayUnion)(benefit),
10103
10096
  updatedAt: /* @__PURE__ */ new Date()
10104
10097
  });
10105
- return this.getById(categoryId, subcategoryId, technologyId);
10098
+ return this.getById(technologyId);
10106
10099
  }
10107
10100
  /**
10108
10101
  * Uklanja benefit iz tehnologije
10109
- * @param categoryId - ID kategorije
10110
- * @param subcategoryId - ID podkategorije
10111
10102
  * @param technologyId - ID tehnologije
10112
10103
  * @param benefit - Benefit koji se uklanja
10113
10104
  * @returns Ažurirana tehnologija
10114
10105
  */
10115
- async removeBenefit(categoryId, subcategoryId, technologyId, benefit) {
10116
- const docRef = (0, import_firestore37.doc)(
10117
- this.getTechnologiesRef(categoryId, subcategoryId),
10118
- technologyId
10119
- );
10106
+ async removeBenefit(technologyId, benefit) {
10107
+ const docRef = (0, import_firestore37.doc)(this.getTechnologiesRef(), technologyId);
10120
10108
  await (0, import_firestore37.updateDoc)(docRef, {
10121
10109
  benefits: (0, import_firestore37.arrayRemove)(benefit),
10122
10110
  updatedAt: /* @__PURE__ */ new Date()
10123
10111
  });
10124
- return this.getById(categoryId, subcategoryId, technologyId);
10112
+ return this.getById(technologyId);
10125
10113
  }
10126
10114
  /**
10127
10115
  * Vraća sve blokirajuće uslove za tehnologiju
10128
- * @param categoryId - ID kategorije
10129
- * @param subcategoryId - ID podkategorije
10130
10116
  * @param technologyId - ID tehnologije
10131
10117
  * @returns Lista blokirajućih uslova
10132
10118
  */
10133
- async getBlockingConditions(categoryId, subcategoryId, technologyId) {
10134
- const technology = await this.getById(
10135
- categoryId,
10136
- subcategoryId,
10137
- technologyId
10138
- );
10119
+ async getBlockingConditions(technologyId) {
10120
+ const technology = await this.getById(technologyId);
10139
10121
  return (technology == null ? void 0 : technology.blockingConditions) || [];
10140
10122
  }
10141
10123
  /**
10142
10124
  * Vraća sve kontraindikacije za tehnologiju
10143
- * @param categoryId - ID kategorije
10144
- * @param subcategoryId - ID podkategorije
10145
10125
  * @param technologyId - ID tehnologije
10146
10126
  * @returns Lista kontraindikacija
10147
10127
  */
10148
- async getContraindications(categoryId, subcategoryId, technologyId) {
10149
- const technology = await this.getById(
10150
- categoryId,
10151
- subcategoryId,
10152
- technologyId
10153
- );
10128
+ async getContraindications(technologyId) {
10129
+ const technology = await this.getById(technologyId);
10154
10130
  return (technology == null ? void 0 : technology.contraindications) || [];
10155
10131
  }
10156
10132
  /**
10157
10133
  * Vraća sve benefite za tehnologiju
10158
- * @param categoryId - ID kategorije
10159
- * @param subcategoryId - ID podkategorije
10160
10134
  * @param technologyId - ID tehnologije
10161
10135
  * @returns Lista benefita
10162
10136
  */
10163
- async getBenefits(categoryId, subcategoryId, technologyId) {
10164
- const technology = await this.getById(
10165
- categoryId,
10166
- subcategoryId,
10167
- technologyId
10168
- );
10137
+ async getBenefits(technologyId) {
10138
+ const technology = await this.getById(technologyId);
10169
10139
  return (technology == null ? void 0 : technology.benefits) || [];
10170
10140
  }
10171
10141
  /**
10172
10142
  * Ažurira zahteve sertifikacije za tehnologiju
10173
- * @param categoryId - ID kategorije
10174
- * @param subcategoryId - ID podkategorije
10175
10143
  * @param technologyId - ID tehnologije
10176
10144
  * @param certificationRequirement - Novi zahtevi sertifikacije
10177
10145
  * @returns Ažurirana tehnologija
10178
10146
  */
10179
- async updateCertificationRequirement(categoryId, subcategoryId, technologyId, certificationRequirement) {
10180
- const docRef = (0, import_firestore37.doc)(
10181
- this.getTechnologiesRef(categoryId, subcategoryId),
10182
- technologyId
10183
- );
10147
+ async updateCertificationRequirement(technologyId, certificationRequirement) {
10148
+ const docRef = (0, import_firestore37.doc)(this.getTechnologiesRef(), technologyId);
10184
10149
  await (0, import_firestore37.updateDoc)(docRef, {
10185
10150
  certificationRequirement,
10186
10151
  updatedAt: /* @__PURE__ */ new Date()
10187
10152
  });
10188
- return this.getById(categoryId, subcategoryId, technologyId);
10153
+ return this.getById(technologyId);
10189
10154
  }
10190
10155
  /**
10191
10156
  * Vraća zahteve sertifikacije za tehnologiju
10192
- * @param categoryId - ID kategorije
10193
- * @param subcategoryId - ID podkategorije
10194
10157
  * @param technologyId - ID tehnologije
10195
10158
  * @returns Zahtevi sertifikacije ili null ako tehnologija ne postoji
10196
10159
  */
10197
- async getCertificationRequirement(categoryId, subcategoryId, technologyId) {
10198
- const technology = await this.getById(
10199
- categoryId,
10200
- subcategoryId,
10201
- technologyId
10202
- );
10160
+ async getCertificationRequirement(technologyId) {
10161
+ const technology = await this.getById(technologyId);
10203
10162
  return (technology == null ? void 0 : technology.certificationRequirement) || null;
10204
10163
  }
10164
+ /**
10165
+ * Proverava da li doktor ima odgovarajuću sertifikaciju za izvođenje tehnologije
10166
+ *
10167
+ * @param requiredCertification - Zahtevana sertifikacija za tehnologiju
10168
+ * @param practitionerCertification - Sertifikacija zdravstvenog radnika
10169
+ * @returns true ako zdravstveni radnik ima odgovarajuću sertifikaciju, false ako nema
10170
+ *
10171
+ * @example
10172
+ * const isValid = technologyService.validateCertification(
10173
+ * {
10174
+ * minimumLevel: CertificationLevel.DOCTOR,
10175
+ * requiredSpecialties: [CertificationSpecialty.INJECTABLES]
10176
+ * },
10177
+ * {
10178
+ * level: CertificationLevel.SPECIALIST,
10179
+ * specialties: [CertificationSpecialty.INJECTABLES, CertificationSpecialty.LASER]
10180
+ * }
10181
+ * );
10182
+ */
10183
+ validateCertification(requiredCertification, practitionerCertification) {
10184
+ const doctorLevel = Object.values(CertificationLevel).indexOf(
10185
+ practitionerCertification.level
10186
+ );
10187
+ const requiredLevel = Object.values(CertificationLevel).indexOf(
10188
+ requiredCertification.minimumLevel
10189
+ );
10190
+ if (doctorLevel < requiredLevel) return false;
10191
+ const requiredSpecialties = requiredCertification.requiredSpecialties || [];
10192
+ if (requiredSpecialties.length > 0) {
10193
+ const doctorSpecialties = practitionerCertification.specialties;
10194
+ const hasAllRequiredSpecialties = requiredSpecialties.every(
10195
+ (requiredSpecialty) => doctorSpecialties.includes(requiredSpecialty)
10196
+ );
10197
+ if (!hasAllRequiredSpecialties) return false;
10198
+ }
10199
+ return true;
10200
+ }
10201
+ /**
10202
+ * Vraća sve tehnologije koje je zdravstveni radnik sertifikovan da izvodi
10203
+ * zajedno sa listama dozvoljenih familija, kategorija i podkategorija
10204
+ *
10205
+ * @param practitioner - Profil zdravstvenog radnika
10206
+ * @returns Objekat koji sadrži:
10207
+ * - technologies: Lista tehnologija koje zdravstveni radnik može da izvodi
10208
+ * - families: Lista familija procedura koje zdravstveni radnik može da izvodi
10209
+ * - categories: Lista ID-eva kategorija koje zdravstveni radnik može da izvodi
10210
+ * - subcategories: Lista ID-eva podkategorija koje zdravstveni radnik može da izvodi
10211
+ *
10212
+ * @example
10213
+ * const practitioner = {
10214
+ * certification: {
10215
+ * level: CertificationLevel.DOCTOR,
10216
+ * specialties: [CertificationSpecialty.INJECTABLES]
10217
+ * }
10218
+ * };
10219
+ * const allowedTechnologies = await technologyService.getAllowedTechnologies(practitioner);
10220
+ * console.log(allowedTechnologies.families); // [ProcedureFamily.AESTHETICS]
10221
+ * console.log(allowedTechnologies.categories); // ["category1", "category2"]
10222
+ * console.log(allowedTechnologies.subcategories); // ["subcategory1", "subcategory2"]
10223
+ */
10224
+ async getAllowedTechnologies(practitioner) {
10225
+ const allTechnologies = await this.getAll();
10226
+ const allowedTechnologies = allTechnologies.filter(
10227
+ (technology) => this.validateCertification(
10228
+ technology.certificationRequirement,
10229
+ practitioner.certification
10230
+ )
10231
+ );
10232
+ const families = [...new Set(allowedTechnologies.map((t) => t.family))];
10233
+ const categories = [
10234
+ ...new Set(allowedTechnologies.map((t) => t.categoryId))
10235
+ ];
10236
+ const subcategories = [
10237
+ ...new Set(allowedTechnologies.map((t) => t.subcategoryId))
10238
+ ];
10239
+ return {
10240
+ technologies: allowedTechnologies,
10241
+ families,
10242
+ categories,
10243
+ subcategories
10244
+ };
10245
+ }
10205
10246
  };
10206
10247
 
10207
10248
  // src/backoffice/services/product.service.ts
10208
10249
  var import_firestore38 = require("firebase/firestore");
10250
+
10251
+ // src/backoffice/types/product.types.ts
10252
+ var PRODUCTS_COLLECTION = "products";
10253
+
10254
+ // src/backoffice/services/product.service.ts
10209
10255
  var ProductService = class extends BaseService {
10210
10256
  getProductsRefByTechnology(categoryId, subcategoryId, technologyId) {
10211
10257
  return (0, import_firestore38.collection)(