@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.mjs CHANGED
@@ -6397,22 +6397,14 @@ var procedureSchema = createProcedureSchema.extend({
6397
6397
  updatedAt: z16.date()
6398
6398
  });
6399
6399
 
6400
- // src/backoffice/types/category.types.ts
6401
- var CATEGORIES_COLLECTION = "backoffice_categories";
6402
-
6403
- // src/backoffice/types/subcategory.types.ts
6404
- var SUBCATEGORIES_COLLECTION = "subcategories";
6405
-
6406
- // src/backoffice/types/technology.types.ts
6407
- var TECHNOLOGIES_COLLECTION = "technologies";
6408
-
6409
- // src/backoffice/types/product.types.ts
6410
- var PRODUCTS_COLLECTION = "products";
6411
-
6412
6400
  // src/services/procedure/procedure.service.ts
6413
6401
  var ProcedureService = class extends BaseService {
6414
- constructor(db, auth, app) {
6402
+ constructor(db, auth, app, categoryService, subcategoryService, technologyService, productService) {
6415
6403
  super(db, auth, app);
6404
+ this.categoryService = categoryService;
6405
+ this.subcategoryService = subcategoryService;
6406
+ this.technologyService = technologyService;
6407
+ this.productService = productService;
6416
6408
  }
6417
6409
  /**
6418
6410
  * Creates a new procedure
@@ -6422,10 +6414,18 @@ var ProcedureService = class extends BaseService {
6422
6414
  async createProcedure(data) {
6423
6415
  const validatedData = createProcedureSchema.parse(data);
6424
6416
  const [category, subcategory, technology, product] = await Promise.all([
6425
- this.getCategory(validatedData.categoryId),
6426
- this.getSubcategory(validatedData.subcategoryId),
6427
- this.getTechnology(validatedData.technologyId),
6428
- this.getProduct(validatedData.productId)
6417
+ this.categoryService.getById(validatedData.categoryId),
6418
+ this.subcategoryService.getById(
6419
+ validatedData.categoryId,
6420
+ validatedData.subcategoryId
6421
+ ),
6422
+ this.technologyService.getById(validatedData.technologyId),
6423
+ this.productService.getById(
6424
+ validatedData.categoryId,
6425
+ validatedData.subcategoryId,
6426
+ validatedData.technologyId,
6427
+ validatedData.productId
6428
+ )
6429
6429
  ]);
6430
6430
  if (!category || !subcategory || !technology || !product) {
6431
6431
  throw new Error("One or more required entities not found");
@@ -6532,40 +6532,46 @@ var ProcedureService = class extends BaseService {
6532
6532
  });
6533
6533
  }
6534
6534
  /**
6535
- * Gets a category by ID
6536
- * @private
6537
- */
6538
- async getCategory(id) {
6539
- const docRef = doc12(this.db, CATEGORIES_COLLECTION, id);
6540
- const docSnap = await getDoc16(docRef);
6541
- return docSnap.exists() ? docSnap.data() : null;
6542
- }
6543
- /**
6544
- * Gets a subcategory by ID
6545
- * @private
6546
- */
6547
- async getSubcategory(id) {
6548
- const docRef = doc12(this.db, SUBCATEGORIES_COLLECTION, id);
6549
- const docSnap = await getDoc16(docRef);
6550
- return docSnap.exists() ? docSnap.data() : null;
6551
- }
6552
- /**
6553
- * Gets a technology by ID
6554
- * @private
6555
- */
6556
- async getTechnology(id) {
6557
- const docRef = doc12(this.db, TECHNOLOGIES_COLLECTION, id);
6558
- const docSnap = await getDoc16(docRef);
6559
- return docSnap.exists() ? docSnap.data() : null;
6560
- }
6561
- /**
6562
- * Gets a product by ID
6563
- * @private
6564
- */
6565
- async getProduct(id) {
6566
- const docRef = doc12(this.db, PRODUCTS_COLLECTION, id);
6567
- const docSnap = await getDoc16(docRef);
6568
- return docSnap.exists() ? docSnap.data() : null;
6535
+ * Gets all procedures that a practitioner is certified to perform
6536
+ * @param practitioner - The practitioner's profile
6537
+ * @returns Object containing:
6538
+ * - procedures: List of procedures the practitioner can perform
6539
+ * - families: List of procedure families the practitioner can perform
6540
+ * - categories: List of category IDs the practitioner can perform
6541
+ * - subcategories: List of subcategory IDs the practitioner can perform
6542
+ *
6543
+ * @example
6544
+ * const practitioner = {
6545
+ * certification: {
6546
+ * level: CertificationLevel.DOCTOR,
6547
+ * specialties: [CertificationSpecialty.INJECTABLES]
6548
+ * }
6549
+ * };
6550
+ * const allowedProcedures = await procedureService.getAllowedProcedures(practitioner);
6551
+ * console.log(allowedProcedures.families); // [ProcedureFamily.AESTHETICS]
6552
+ * console.log(allowedProcedures.categories); // ["category1", "category2"]
6553
+ * console.log(allowedProcedures.subcategories); // ["subcategory1", "subcategory2"]
6554
+ */
6555
+ async getAllowedProcedures(practitioner) {
6556
+ const { technologies, families, categories, subcategories } = await this.technologyService.getAllowedTechnologies(practitioner);
6557
+ const procedures = await Promise.all(
6558
+ technologies.map(async (technology) => {
6559
+ const q = query10(
6560
+ collection11(this.db, PROCEDURES_COLLECTION),
6561
+ where10("technologyId", "==", technology.id),
6562
+ where10("isActive", "==", true)
6563
+ );
6564
+ const snapshot = await getDocs10(q);
6565
+ return snapshot.docs.map((doc26) => doc26.data());
6566
+ })
6567
+ );
6568
+ const flattenedProcedures = procedures.flat();
6569
+ return {
6570
+ procedures: flattenedProcedures,
6571
+ families,
6572
+ categories,
6573
+ subcategories
6574
+ };
6569
6575
  }
6570
6576
  };
6571
6577
 
@@ -9681,6 +9687,11 @@ import {
9681
9687
  updateDoc as updateDoc23,
9682
9688
  where as where19
9683
9689
  } from "firebase/firestore";
9690
+
9691
+ // src/backoffice/types/category.types.ts
9692
+ var CATEGORIES_COLLECTION = "backoffice_categories";
9693
+
9694
+ // src/backoffice/services/category.service.ts
9684
9695
  var CategoryService = class extends BaseService {
9685
9696
  /**
9686
9697
  * Referenca na Firestore kolekciju kategorija
@@ -9786,6 +9797,11 @@ import {
9786
9797
  updateDoc as updateDoc24,
9787
9798
  where as where20
9788
9799
  } from "firebase/firestore";
9800
+
9801
+ // src/backoffice/types/subcategory.types.ts
9802
+ var SUBCATEGORIES_COLLECTION = "subcategories";
9803
+
9804
+ // src/backoffice/services/subcategory.service.ts
9789
9805
  var SubcategoryService = class extends BaseService {
9790
9806
  /**
9791
9807
  * Vraća referencu na Firestore kolekciju podkategorija za određenu kategoriju
@@ -9892,66 +9908,108 @@ import {
9892
9908
  arrayUnion as arrayUnion5,
9893
9909
  arrayRemove as arrayRemove3
9894
9910
  } from "firebase/firestore";
9911
+
9912
+ // src/backoffice/types/technology.types.ts
9913
+ var TECHNOLOGIES_COLLECTION = "technologies";
9914
+
9915
+ // src/backoffice/services/technology.service.ts
9895
9916
  var DEFAULT_CERTIFICATION_REQUIREMENT = {
9896
9917
  minimumLevel: "aesthetician" /* AESTHETICIAN */,
9897
9918
  requiredSpecialties: []
9898
9919
  };
9899
9920
  var TechnologyService = class extends BaseService {
9900
9921
  /**
9901
- * Vraća referencu na Firestore kolekciju tehnologija za određenu podkategoriju
9902
- * @param categoryId - ID kategorije
9903
- * @param subcategoryId - ID podkategorije
9922
+ * Vraća referencu na Firestore kolekciju tehnologija
9904
9923
  */
9905
- getTechnologiesRef(categoryId, subcategoryId) {
9906
- return collection22(
9907
- this.db,
9908
- CATEGORIES_COLLECTION,
9909
- categoryId,
9910
- SUBCATEGORIES_COLLECTION,
9911
- subcategoryId,
9912
- TECHNOLOGIES_COLLECTION
9913
- );
9924
+ getTechnologiesRef() {
9925
+ return collection22(this.db, TECHNOLOGIES_COLLECTION);
9914
9926
  }
9915
9927
  /**
9916
- * Kreira novu tehnologiju u okviru podkategorije
9917
- * @param categoryId - ID kategorije
9918
- * @param subcategoryId - ID podkategorije
9928
+ * Kreira novu tehnologiju
9919
9929
  * @param technology - Podaci za novu tehnologiju
9920
9930
  * @returns Kreirana tehnologija sa generisanim ID-em
9921
9931
  */
9922
- async create(categoryId, subcategoryId, technology) {
9932
+ async create(technology) {
9923
9933
  const now = /* @__PURE__ */ new Date();
9924
9934
  const newTechnology = {
9925
9935
  ...technology,
9926
- subcategoryId,
9927
9936
  createdAt: now,
9928
9937
  updatedAt: now,
9929
9938
  isActive: true,
9930
- requirements: {
9939
+ requirements: technology.requirements || {
9931
9940
  pre: [],
9932
9941
  post: []
9933
9942
  },
9934
- blockingConditions: [],
9935
- contraindications: [],
9936
- benefits: [],
9943
+ blockingConditions: technology.blockingConditions || [],
9944
+ contraindications: technology.contraindications || [],
9945
+ benefits: technology.benefits || [],
9937
9946
  certificationRequirement: technology.certificationRequirement || DEFAULT_CERTIFICATION_REQUIREMENT
9938
9947
  };
9939
- const docRef = await addDoc7(
9940
- this.getTechnologiesRef(categoryId, subcategoryId),
9941
- newTechnology
9942
- );
9948
+ const docRef = await addDoc7(this.getTechnologiesRef(), newTechnology);
9943
9949
  return { id: docRef.id, ...newTechnology };
9944
9950
  }
9945
9951
  /**
9946
- * Vraća sve aktivne tehnologije za određenu podkategoriju
9952
+ * Vraća sve aktivne tehnologije
9953
+ * @returns Lista aktivnih tehnologija
9954
+ */
9955
+ async getAll() {
9956
+ const q = query21(this.getTechnologiesRef(), where21("isActive", "==", true));
9957
+ const snapshot = await getDocs21(q);
9958
+ return snapshot.docs.map(
9959
+ (doc26) => ({
9960
+ id: doc26.id,
9961
+ ...doc26.data()
9962
+ })
9963
+ );
9964
+ }
9965
+ /**
9966
+ * Vraća sve aktivne tehnologije za određenu familiju
9967
+ * @param family - Familija procedura
9968
+ * @returns Lista aktivnih tehnologija
9969
+ */
9970
+ async getAllByFamily(family) {
9971
+ const q = query21(
9972
+ this.getTechnologiesRef(),
9973
+ where21("isActive", "==", true),
9974
+ where21("family", "==", family)
9975
+ );
9976
+ const snapshot = await getDocs21(q);
9977
+ return snapshot.docs.map(
9978
+ (doc26) => ({
9979
+ id: doc26.id,
9980
+ ...doc26.data()
9981
+ })
9982
+ );
9983
+ }
9984
+ /**
9985
+ * Vraća sve aktivne tehnologije za određenu kategoriju
9947
9986
  * @param categoryId - ID kategorije
9987
+ * @returns Lista aktivnih tehnologija
9988
+ */
9989
+ async getAllByCategoryId(categoryId) {
9990
+ const q = query21(
9991
+ this.getTechnologiesRef(),
9992
+ where21("isActive", "==", true),
9993
+ where21("categoryId", "==", categoryId)
9994
+ );
9995
+ const snapshot = await getDocs21(q);
9996
+ return snapshot.docs.map(
9997
+ (doc26) => ({
9998
+ id: doc26.id,
9999
+ ...doc26.data()
10000
+ })
10001
+ );
10002
+ }
10003
+ /**
10004
+ * Vraća sve aktivne tehnologije za određenu podkategoriju
9948
10005
  * @param subcategoryId - ID podkategorije
9949
10006
  * @returns Lista aktivnih tehnologija
9950
10007
  */
9951
- async getAllBySubcategoryId(categoryId, subcategoryId) {
10008
+ async getAllBySubcategoryId(subcategoryId) {
9952
10009
  const q = query21(
9953
- this.getTechnologiesRef(categoryId, subcategoryId),
9954
- where21("isActive", "==", true)
10010
+ this.getTechnologiesRef(),
10011
+ where21("isActive", "==", true),
10012
+ where21("subcategoryId", "==", subcategoryId)
9955
10013
  );
9956
10014
  const snapshot = await getDocs21(q);
9957
10015
  return snapshot.docs.map(
@@ -9963,47 +10021,35 @@ var TechnologyService = class extends BaseService {
9963
10021
  }
9964
10022
  /**
9965
10023
  * Ažurira postojeću tehnologiju
9966
- * @param categoryId - ID kategorije
9967
- * @param subcategoryId - ID podkategorije
9968
10024
  * @param technologyId - ID tehnologije
9969
10025
  * @param technology - Novi podaci za tehnologiju
9970
10026
  * @returns Ažurirana tehnologija
9971
10027
  */
9972
- async update(categoryId, subcategoryId, technologyId, technology) {
10028
+ async update(technologyId, technology) {
9973
10029
  const updateData = {
9974
10030
  ...technology,
9975
10031
  updatedAt: /* @__PURE__ */ new Date()
9976
10032
  };
9977
- const docRef = doc24(
9978
- this.getTechnologiesRef(categoryId, subcategoryId),
9979
- technologyId
9980
- );
10033
+ const docRef = doc24(this.getTechnologiesRef(), technologyId);
9981
10034
  await updateDoc25(docRef, updateData);
9982
- return this.getById(categoryId, subcategoryId, technologyId);
10035
+ return this.getById(technologyId);
9983
10036
  }
9984
10037
  /**
9985
10038
  * Soft delete tehnologije (postavlja isActive na false)
9986
- * @param categoryId - ID kategorije
9987
- * @param subcategoryId - ID podkategorije
9988
10039
  * @param technologyId - ID tehnologije koja se briše
9989
10040
  */
9990
- async delete(categoryId, subcategoryId, technologyId) {
9991
- await this.update(categoryId, subcategoryId, technologyId, {
10041
+ async delete(technologyId) {
10042
+ await this.update(technologyId, {
9992
10043
  isActive: false
9993
10044
  });
9994
10045
  }
9995
10046
  /**
9996
10047
  * Vraća tehnologiju po ID-u
9997
- * @param categoryId - ID kategorije
9998
- * @param subcategoryId - ID podkategorije
9999
10048
  * @param technologyId - ID tražene tehnologije
10000
10049
  * @returns Tehnologija ili null ako ne postoji
10001
10050
  */
10002
- async getById(categoryId, subcategoryId, technologyId) {
10003
- const docRef = doc24(
10004
- this.getTechnologiesRef(categoryId, subcategoryId),
10005
- technologyId
10006
- );
10051
+ async getById(technologyId) {
10052
+ const docRef = doc24(this.getTechnologiesRef(), technologyId);
10007
10053
  const docSnap = await getDoc27(docRef);
10008
10054
  if (!docSnap.exists()) return null;
10009
10055
  return {
@@ -10013,58 +10059,42 @@ var TechnologyService = class extends BaseService {
10013
10059
  }
10014
10060
  /**
10015
10061
  * Dodaje novi zahtev tehnologiji
10016
- * @param categoryId - ID kategorije
10017
- * @param subcategoryId - ID podkategorije
10018
10062
  * @param technologyId - ID tehnologije
10019
10063
  * @param requirement - Zahtev koji se dodaje
10020
10064
  * @returns Ažurirana tehnologija sa novim zahtevom
10021
10065
  */
10022
- async addRequirement(categoryId, subcategoryId, technologyId, requirement) {
10023
- const docRef = doc24(
10024
- this.getTechnologiesRef(categoryId, subcategoryId),
10025
- technologyId
10026
- );
10066
+ async addRequirement(technologyId, requirement) {
10067
+ const docRef = doc24(this.getTechnologiesRef(), technologyId);
10027
10068
  const requirementType = requirement.type === "pre" ? "requirements.pre" : "requirements.post";
10028
10069
  await updateDoc25(docRef, {
10029
10070
  [requirementType]: arrayUnion5(requirement),
10030
10071
  updatedAt: /* @__PURE__ */ new Date()
10031
10072
  });
10032
- return this.getById(categoryId, subcategoryId, technologyId);
10073
+ return this.getById(technologyId);
10033
10074
  }
10034
10075
  /**
10035
10076
  * Uklanja zahtev iz tehnologije
10036
- * @param categoryId - ID kategorije
10037
- * @param subcategoryId - ID podkategorije
10038
10077
  * @param technologyId - ID tehnologije
10039
10078
  * @param requirement - Zahtev koji se uklanja
10040
10079
  * @returns Ažurirana tehnologija bez uklonjenog zahteva
10041
10080
  */
10042
- async removeRequirement(categoryId, subcategoryId, technologyId, requirement) {
10043
- const docRef = doc24(
10044
- this.getTechnologiesRef(categoryId, subcategoryId),
10045
- technologyId
10046
- );
10081
+ async removeRequirement(technologyId, requirement) {
10082
+ const docRef = doc24(this.getTechnologiesRef(), technologyId);
10047
10083
  const requirementType = requirement.type === "pre" ? "requirements.pre" : "requirements.post";
10048
10084
  await updateDoc25(docRef, {
10049
10085
  [requirementType]: arrayRemove3(requirement),
10050
10086
  updatedAt: /* @__PURE__ */ new Date()
10051
10087
  });
10052
- return this.getById(categoryId, subcategoryId, technologyId);
10088
+ return this.getById(technologyId);
10053
10089
  }
10054
10090
  /**
10055
10091
  * Vraća sve zahteve za tehnologiju
10056
- * @param categoryId - ID kategorije
10057
- * @param subcategoryId - ID podkategorije
10058
10092
  * @param technologyId - ID tehnologije
10059
10093
  * @param type - Opcioni filter za tip zahteva (pre/post)
10060
10094
  * @returns Lista zahteva
10061
10095
  */
10062
- async getRequirements(categoryId, subcategoryId, technologyId, type) {
10063
- const technology = await this.getById(
10064
- categoryId,
10065
- subcategoryId,
10066
- technologyId
10067
- );
10096
+ async getRequirements(technologyId, type) {
10097
+ const technology = await this.getById(technologyId);
10068
10098
  if (!technology || !technology.requirements) return [];
10069
10099
  if (type) {
10070
10100
  return technology.requirements[type];
@@ -10073,220 +10103,231 @@ var TechnologyService = class extends BaseService {
10073
10103
  }
10074
10104
  /**
10075
10105
  * Ažurira postojeći zahtev
10076
- * @param categoryId - ID kategorije
10077
- * @param subcategoryId - ID podkategorije
10078
10106
  * @param technologyId - ID tehnologije
10079
10107
  * @param oldRequirement - Stari zahtev koji se menja
10080
10108
  * @param newRequirement - Novi zahtev koji zamenjuje stari
10081
10109
  * @returns Ažurirana tehnologija
10082
10110
  */
10083
- async updateRequirement(categoryId, subcategoryId, technologyId, oldRequirement, newRequirement) {
10084
- await this.removeRequirement(
10085
- categoryId,
10086
- subcategoryId,
10087
- technologyId,
10088
- oldRequirement
10089
- );
10090
- return this.addRequirement(
10091
- categoryId,
10092
- subcategoryId,
10093
- technologyId,
10094
- newRequirement
10095
- );
10111
+ async updateRequirement(technologyId, oldRequirement, newRequirement) {
10112
+ await this.removeRequirement(technologyId, oldRequirement);
10113
+ return this.addRequirement(technologyId, newRequirement);
10096
10114
  }
10097
10115
  /**
10098
10116
  * Dodaje blokirajući uslov tehnologiji
10099
- * @param categoryId - ID kategorije
10100
- * @param subcategoryId - ID podkategorije
10101
10117
  * @param technologyId - ID tehnologije
10102
10118
  * @param condition - Blokirajući uslov koji se dodaje
10103
10119
  * @returns Ažurirana tehnologija
10104
10120
  */
10105
- async addBlockingCondition(categoryId, subcategoryId, technologyId, condition) {
10106
- const docRef = doc24(
10107
- this.getTechnologiesRef(categoryId, subcategoryId),
10108
- technologyId
10109
- );
10121
+ async addBlockingCondition(technologyId, condition) {
10122
+ const docRef = doc24(this.getTechnologiesRef(), technologyId);
10110
10123
  await updateDoc25(docRef, {
10111
10124
  blockingConditions: arrayUnion5(condition),
10112
10125
  updatedAt: /* @__PURE__ */ new Date()
10113
10126
  });
10114
- return this.getById(categoryId, subcategoryId, technologyId);
10127
+ return this.getById(technologyId);
10115
10128
  }
10116
10129
  /**
10117
10130
  * Uklanja blokirajući uslov iz tehnologije
10118
- * @param categoryId - ID kategorije
10119
- * @param subcategoryId - ID podkategorije
10120
10131
  * @param technologyId - ID tehnologije
10121
10132
  * @param condition - Blokirajući uslov koji se uklanja
10122
10133
  * @returns Ažurirana tehnologija
10123
10134
  */
10124
- async removeBlockingCondition(categoryId, subcategoryId, technologyId, condition) {
10125
- const docRef = doc24(
10126
- this.getTechnologiesRef(categoryId, subcategoryId),
10127
- technologyId
10128
- );
10135
+ async removeBlockingCondition(technologyId, condition) {
10136
+ const docRef = doc24(this.getTechnologiesRef(), technologyId);
10129
10137
  await updateDoc25(docRef, {
10130
10138
  blockingConditions: arrayRemove3(condition),
10131
10139
  updatedAt: /* @__PURE__ */ new Date()
10132
10140
  });
10133
- return this.getById(categoryId, subcategoryId, technologyId);
10141
+ return this.getById(technologyId);
10134
10142
  }
10135
10143
  /**
10136
10144
  * Dodaje kontraindikaciju tehnologiji
10137
- * @param categoryId - ID kategorije
10138
- * @param subcategoryId - ID podkategorije
10139
10145
  * @param technologyId - ID tehnologije
10140
10146
  * @param contraindication - Kontraindikacija koja se dodaje
10141
10147
  * @returns Ažurirana tehnologija
10142
10148
  */
10143
- async addContraindication(categoryId, subcategoryId, technologyId, contraindication) {
10144
- const docRef = doc24(
10145
- this.getTechnologiesRef(categoryId, subcategoryId),
10146
- technologyId
10147
- );
10149
+ async addContraindication(technologyId, contraindication) {
10150
+ const docRef = doc24(this.getTechnologiesRef(), technologyId);
10148
10151
  await updateDoc25(docRef, {
10149
10152
  contraindications: arrayUnion5(contraindication),
10150
10153
  updatedAt: /* @__PURE__ */ new Date()
10151
10154
  });
10152
- return this.getById(categoryId, subcategoryId, technologyId);
10155
+ return this.getById(technologyId);
10153
10156
  }
10154
10157
  /**
10155
10158
  * Uklanja kontraindikaciju iz tehnologije
10156
- * @param categoryId - ID kategorije
10157
- * @param subcategoryId - ID podkategorije
10158
10159
  * @param technologyId - ID tehnologije
10159
10160
  * @param contraindication - Kontraindikacija koja se uklanja
10160
10161
  * @returns Ažurirana tehnologija
10161
10162
  */
10162
- async removeContraindication(categoryId, subcategoryId, technologyId, contraindication) {
10163
- const docRef = doc24(
10164
- this.getTechnologiesRef(categoryId, subcategoryId),
10165
- technologyId
10166
- );
10163
+ async removeContraindication(technologyId, contraindication) {
10164
+ const docRef = doc24(this.getTechnologiesRef(), technologyId);
10167
10165
  await updateDoc25(docRef, {
10168
10166
  contraindications: arrayRemove3(contraindication),
10169
10167
  updatedAt: /* @__PURE__ */ new Date()
10170
10168
  });
10171
- return this.getById(categoryId, subcategoryId, technologyId);
10169
+ return this.getById(technologyId);
10172
10170
  }
10173
10171
  /**
10174
10172
  * Dodaje benefit tehnologiji
10175
- * @param categoryId - ID kategorije
10176
- * @param subcategoryId - ID podkategorije
10177
10173
  * @param technologyId - ID tehnologije
10178
10174
  * @param benefit - Benefit koji se dodaje
10179
10175
  * @returns Ažurirana tehnologija
10180
10176
  */
10181
- async addBenefit(categoryId, subcategoryId, technologyId, benefit) {
10182
- const docRef = doc24(
10183
- this.getTechnologiesRef(categoryId, subcategoryId),
10184
- technologyId
10185
- );
10177
+ async addBenefit(technologyId, benefit) {
10178
+ const docRef = doc24(this.getTechnologiesRef(), technologyId);
10186
10179
  await updateDoc25(docRef, {
10187
10180
  benefits: arrayUnion5(benefit),
10188
10181
  updatedAt: /* @__PURE__ */ new Date()
10189
10182
  });
10190
- return this.getById(categoryId, subcategoryId, technologyId);
10183
+ return this.getById(technologyId);
10191
10184
  }
10192
10185
  /**
10193
10186
  * Uklanja benefit iz tehnologije
10194
- * @param categoryId - ID kategorije
10195
- * @param subcategoryId - ID podkategorije
10196
10187
  * @param technologyId - ID tehnologije
10197
10188
  * @param benefit - Benefit koji se uklanja
10198
10189
  * @returns Ažurirana tehnologija
10199
10190
  */
10200
- async removeBenefit(categoryId, subcategoryId, technologyId, benefit) {
10201
- const docRef = doc24(
10202
- this.getTechnologiesRef(categoryId, subcategoryId),
10203
- technologyId
10204
- );
10191
+ async removeBenefit(technologyId, benefit) {
10192
+ const docRef = doc24(this.getTechnologiesRef(), technologyId);
10205
10193
  await updateDoc25(docRef, {
10206
10194
  benefits: arrayRemove3(benefit),
10207
10195
  updatedAt: /* @__PURE__ */ new Date()
10208
10196
  });
10209
- return this.getById(categoryId, subcategoryId, technologyId);
10197
+ return this.getById(technologyId);
10210
10198
  }
10211
10199
  /**
10212
10200
  * Vraća sve blokirajuće uslove za tehnologiju
10213
- * @param categoryId - ID kategorije
10214
- * @param subcategoryId - ID podkategorije
10215
10201
  * @param technologyId - ID tehnologije
10216
10202
  * @returns Lista blokirajućih uslova
10217
10203
  */
10218
- async getBlockingConditions(categoryId, subcategoryId, technologyId) {
10219
- const technology = await this.getById(
10220
- categoryId,
10221
- subcategoryId,
10222
- technologyId
10223
- );
10204
+ async getBlockingConditions(technologyId) {
10205
+ const technology = await this.getById(technologyId);
10224
10206
  return (technology == null ? void 0 : technology.blockingConditions) || [];
10225
10207
  }
10226
10208
  /**
10227
10209
  * Vraća sve kontraindikacije za tehnologiju
10228
- * @param categoryId - ID kategorije
10229
- * @param subcategoryId - ID podkategorije
10230
10210
  * @param technologyId - ID tehnologije
10231
10211
  * @returns Lista kontraindikacija
10232
10212
  */
10233
- async getContraindications(categoryId, subcategoryId, technologyId) {
10234
- const technology = await this.getById(
10235
- categoryId,
10236
- subcategoryId,
10237
- technologyId
10238
- );
10213
+ async getContraindications(technologyId) {
10214
+ const technology = await this.getById(technologyId);
10239
10215
  return (technology == null ? void 0 : technology.contraindications) || [];
10240
10216
  }
10241
10217
  /**
10242
10218
  * Vraća sve benefite za tehnologiju
10243
- * @param categoryId - ID kategorije
10244
- * @param subcategoryId - ID podkategorije
10245
10219
  * @param technologyId - ID tehnologije
10246
10220
  * @returns Lista benefita
10247
10221
  */
10248
- async getBenefits(categoryId, subcategoryId, technologyId) {
10249
- const technology = await this.getById(
10250
- categoryId,
10251
- subcategoryId,
10252
- technologyId
10253
- );
10222
+ async getBenefits(technologyId) {
10223
+ const technology = await this.getById(technologyId);
10254
10224
  return (technology == null ? void 0 : technology.benefits) || [];
10255
10225
  }
10256
10226
  /**
10257
10227
  * Ažurira zahteve sertifikacije za tehnologiju
10258
- * @param categoryId - ID kategorije
10259
- * @param subcategoryId - ID podkategorije
10260
10228
  * @param technologyId - ID tehnologije
10261
10229
  * @param certificationRequirement - Novi zahtevi sertifikacije
10262
10230
  * @returns Ažurirana tehnologija
10263
10231
  */
10264
- async updateCertificationRequirement(categoryId, subcategoryId, technologyId, certificationRequirement) {
10265
- const docRef = doc24(
10266
- this.getTechnologiesRef(categoryId, subcategoryId),
10267
- technologyId
10268
- );
10232
+ async updateCertificationRequirement(technologyId, certificationRequirement) {
10233
+ const docRef = doc24(this.getTechnologiesRef(), technologyId);
10269
10234
  await updateDoc25(docRef, {
10270
10235
  certificationRequirement,
10271
10236
  updatedAt: /* @__PURE__ */ new Date()
10272
10237
  });
10273
- return this.getById(categoryId, subcategoryId, technologyId);
10238
+ return this.getById(technologyId);
10274
10239
  }
10275
10240
  /**
10276
10241
  * Vraća zahteve sertifikacije za tehnologiju
10277
- * @param categoryId - ID kategorije
10278
- * @param subcategoryId - ID podkategorije
10279
10242
  * @param technologyId - ID tehnologije
10280
10243
  * @returns Zahtevi sertifikacije ili null ako tehnologija ne postoji
10281
10244
  */
10282
- async getCertificationRequirement(categoryId, subcategoryId, technologyId) {
10283
- const technology = await this.getById(
10284
- categoryId,
10285
- subcategoryId,
10286
- technologyId
10287
- );
10245
+ async getCertificationRequirement(technologyId) {
10246
+ const technology = await this.getById(technologyId);
10288
10247
  return (technology == null ? void 0 : technology.certificationRequirement) || null;
10289
10248
  }
10249
+ /**
10250
+ * Proverava da li doktor ima odgovarajuću sertifikaciju za izvođenje tehnologije
10251
+ *
10252
+ * @param requiredCertification - Zahtevana sertifikacija za tehnologiju
10253
+ * @param practitionerCertification - Sertifikacija zdravstvenog radnika
10254
+ * @returns true ako zdravstveni radnik ima odgovarajuću sertifikaciju, false ako nema
10255
+ *
10256
+ * @example
10257
+ * const isValid = technologyService.validateCertification(
10258
+ * {
10259
+ * minimumLevel: CertificationLevel.DOCTOR,
10260
+ * requiredSpecialties: [CertificationSpecialty.INJECTABLES]
10261
+ * },
10262
+ * {
10263
+ * level: CertificationLevel.SPECIALIST,
10264
+ * specialties: [CertificationSpecialty.INJECTABLES, CertificationSpecialty.LASER]
10265
+ * }
10266
+ * );
10267
+ */
10268
+ validateCertification(requiredCertification, practitionerCertification) {
10269
+ const doctorLevel = Object.values(CertificationLevel).indexOf(
10270
+ practitionerCertification.level
10271
+ );
10272
+ const requiredLevel = Object.values(CertificationLevel).indexOf(
10273
+ requiredCertification.minimumLevel
10274
+ );
10275
+ if (doctorLevel < requiredLevel) return false;
10276
+ const requiredSpecialties = requiredCertification.requiredSpecialties || [];
10277
+ if (requiredSpecialties.length > 0) {
10278
+ const doctorSpecialties = practitionerCertification.specialties;
10279
+ const hasAllRequiredSpecialties = requiredSpecialties.every(
10280
+ (requiredSpecialty) => doctorSpecialties.includes(requiredSpecialty)
10281
+ );
10282
+ if (!hasAllRequiredSpecialties) return false;
10283
+ }
10284
+ return true;
10285
+ }
10286
+ /**
10287
+ * Vraća sve tehnologije koje je zdravstveni radnik sertifikovan da izvodi
10288
+ * zajedno sa listama dozvoljenih familija, kategorija i podkategorija
10289
+ *
10290
+ * @param practitioner - Profil zdravstvenog radnika
10291
+ * @returns Objekat koji sadrži:
10292
+ * - technologies: Lista tehnologija koje zdravstveni radnik može da izvodi
10293
+ * - families: Lista familija procedura koje zdravstveni radnik može da izvodi
10294
+ * - categories: Lista ID-eva kategorija koje zdravstveni radnik može da izvodi
10295
+ * - subcategories: Lista ID-eva podkategorija koje zdravstveni radnik može da izvodi
10296
+ *
10297
+ * @example
10298
+ * const practitioner = {
10299
+ * certification: {
10300
+ * level: CertificationLevel.DOCTOR,
10301
+ * specialties: [CertificationSpecialty.INJECTABLES]
10302
+ * }
10303
+ * };
10304
+ * const allowedTechnologies = await technologyService.getAllowedTechnologies(practitioner);
10305
+ * console.log(allowedTechnologies.families); // [ProcedureFamily.AESTHETICS]
10306
+ * console.log(allowedTechnologies.categories); // ["category1", "category2"]
10307
+ * console.log(allowedTechnologies.subcategories); // ["subcategory1", "subcategory2"]
10308
+ */
10309
+ async getAllowedTechnologies(practitioner) {
10310
+ const allTechnologies = await this.getAll();
10311
+ const allowedTechnologies = allTechnologies.filter(
10312
+ (technology) => this.validateCertification(
10313
+ technology.certificationRequirement,
10314
+ practitioner.certification
10315
+ )
10316
+ );
10317
+ const families = [...new Set(allowedTechnologies.map((t) => t.family))];
10318
+ const categories = [
10319
+ ...new Set(allowedTechnologies.map((t) => t.categoryId))
10320
+ ];
10321
+ const subcategories = [
10322
+ ...new Set(allowedTechnologies.map((t) => t.subcategoryId))
10323
+ ];
10324
+ return {
10325
+ technologies: allowedTechnologies,
10326
+ families,
10327
+ categories,
10328
+ subcategories
10329
+ };
10330
+ }
10290
10331
  };
10291
10332
 
10292
10333
  // src/backoffice/services/product.service.ts
@@ -10301,6 +10342,11 @@ import {
10301
10342
  updateDoc as updateDoc26,
10302
10343
  where as where22
10303
10344
  } from "firebase/firestore";
10345
+
10346
+ // src/backoffice/types/product.types.ts
10347
+ var PRODUCTS_COLLECTION = "products";
10348
+
10349
+ // src/backoffice/services/product.service.ts
10304
10350
  var ProductService = class extends BaseService {
10305
10351
  getProductsRefByTechnology(categoryId, subcategoryId, technologyId) {
10306
10352
  return collection23(