@blackcode_sa/metaestetics-api 1.12.1 → 1.12.3
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/backoffice/index.d.mts +64 -14
- package/dist/backoffice/index.d.ts +64 -14
- package/dist/backoffice/index.js +72 -53
- package/dist/backoffice/index.mjs +72 -53
- package/dist/index.d.mts +131 -19
- package/dist/index.d.ts +131 -19
- package/dist/index.js +141 -261
- package/dist/index.mjs +141 -261
- package/package.json +1 -1
- package/src/backoffice/services/FIXES_README.md +102 -0
- package/src/backoffice/services/category.service.ts +46 -27
- package/src/backoffice/services/product.service.ts +52 -74
- package/src/backoffice/services/technology.service.ts +99 -116
- package/src/backoffice/types/category.types.ts +28 -2
- package/src/backoffice/types/product.types.ts +10 -9
- package/src/backoffice/types/technology.types.ts +31 -59
- package/src/services/procedure/procedure.service.ts +275 -472
package/dist/index.js
CHANGED
|
@@ -15000,9 +15000,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15000
15000
|
return media;
|
|
15001
15001
|
}
|
|
15002
15002
|
if (media instanceof File || media instanceof Blob) {
|
|
15003
|
-
console.log(
|
|
15004
|
-
`[ProcedureService] Uploading ${collectionName} media for ${ownerId}`
|
|
15005
|
-
);
|
|
15003
|
+
console.log(`[ProcedureService] Uploading ${collectionName} media for ${ownerId}`);
|
|
15006
15004
|
const metadata = await this.mediaService.uploadMedia(
|
|
15007
15005
|
media,
|
|
15008
15006
|
ownerId,
|
|
@@ -15024,11 +15022,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15024
15022
|
if (!mediaArray || mediaArray.length === 0) return [];
|
|
15025
15023
|
const result = [];
|
|
15026
15024
|
for (const media of mediaArray) {
|
|
15027
|
-
const processedUrl = await this.processMedia(
|
|
15028
|
-
media,
|
|
15029
|
-
ownerId,
|
|
15030
|
-
collectionName
|
|
15031
|
-
);
|
|
15025
|
+
const processedUrl = await this.processMedia(media, ownerId, collectionName);
|
|
15032
15026
|
if (processedUrl) {
|
|
15033
15027
|
result.push(processedUrl);
|
|
15034
15028
|
}
|
|
@@ -15044,10 +15038,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15044
15038
|
async transformProductsMetadata(productsMetadata, technologyId) {
|
|
15045
15039
|
const transformedProducts = [];
|
|
15046
15040
|
for (const productData of productsMetadata) {
|
|
15047
|
-
const product = await this.productService.getById(
|
|
15048
|
-
technologyId,
|
|
15049
|
-
productData.productId
|
|
15050
|
-
);
|
|
15041
|
+
const product = await this.productService.getById(technologyId, productData.productId);
|
|
15051
15042
|
if (!product) {
|
|
15052
15043
|
throw new Error(
|
|
15053
15044
|
`Product with ID ${productData.productId} not found for technology ${technologyId}`
|
|
@@ -15074,41 +15065,23 @@ var ProcedureService = class extends BaseService {
|
|
|
15074
15065
|
const procedureId = this.generateId();
|
|
15075
15066
|
const [category, subcategory, technology, product] = await Promise.all([
|
|
15076
15067
|
this.categoryService.getById(validatedData.categoryId),
|
|
15077
|
-
this.subcategoryService.getById(
|
|
15078
|
-
validatedData.categoryId,
|
|
15079
|
-
validatedData.subcategoryId
|
|
15080
|
-
),
|
|
15068
|
+
this.subcategoryService.getById(validatedData.categoryId, validatedData.subcategoryId),
|
|
15081
15069
|
this.technologyService.getById(validatedData.technologyId),
|
|
15082
|
-
this.productService.getById(
|
|
15083
|
-
validatedData.technologyId,
|
|
15084
|
-
validatedData.productId
|
|
15085
|
-
)
|
|
15070
|
+
this.productService.getById(validatedData.technologyId, validatedData.productId)
|
|
15086
15071
|
]);
|
|
15087
15072
|
if (!category || !subcategory || !technology || !product) {
|
|
15088
15073
|
throw new Error("One or more required base entities not found");
|
|
15089
15074
|
}
|
|
15090
|
-
const clinicRef = (0, import_firestore46.doc)(
|
|
15091
|
-
this.db,
|
|
15092
|
-
CLINICS_COLLECTION,
|
|
15093
|
-
validatedData.clinicBranchId
|
|
15094
|
-
);
|
|
15075
|
+
const clinicRef = (0, import_firestore46.doc)(this.db, CLINICS_COLLECTION, validatedData.clinicBranchId);
|
|
15095
15076
|
const clinicSnapshot = await (0, import_firestore46.getDoc)(clinicRef);
|
|
15096
15077
|
if (!clinicSnapshot.exists()) {
|
|
15097
|
-
throw new Error(
|
|
15098
|
-
`Clinic with ID ${validatedData.clinicBranchId} not found`
|
|
15099
|
-
);
|
|
15078
|
+
throw new Error(`Clinic with ID ${validatedData.clinicBranchId} not found`);
|
|
15100
15079
|
}
|
|
15101
15080
|
const clinic = clinicSnapshot.data();
|
|
15102
|
-
const practitionerRef = (0, import_firestore46.doc)(
|
|
15103
|
-
this.db,
|
|
15104
|
-
PRACTITIONERS_COLLECTION,
|
|
15105
|
-
validatedData.practitionerId
|
|
15106
|
-
);
|
|
15081
|
+
const practitionerRef = (0, import_firestore46.doc)(this.db, PRACTITIONERS_COLLECTION, validatedData.practitionerId);
|
|
15107
15082
|
const practitionerSnapshot = await (0, import_firestore46.getDoc)(practitionerRef);
|
|
15108
15083
|
if (!practitionerSnapshot.exists()) {
|
|
15109
|
-
throw new Error(
|
|
15110
|
-
`Practitioner with ID ${validatedData.practitionerId} not found`
|
|
15111
|
-
);
|
|
15084
|
+
throw new Error(`Practitioner with ID ${validatedData.practitionerId} not found`);
|
|
15112
15085
|
}
|
|
15113
15086
|
const practitioner = practitionerSnapshot.data();
|
|
15114
15087
|
let processedPhotos = [];
|
|
@@ -15140,9 +15113,10 @@ var ProcedureService = class extends BaseService {
|
|
|
15140
15113
|
rating: ((_a = practitioner.reviewInfo) == null ? void 0 : _a.averageRating) || 0,
|
|
15141
15114
|
services: practitioner.procedures || []
|
|
15142
15115
|
};
|
|
15116
|
+
const { productsMetadata: _, ...validatedDataWithoutProductsMetadata } = validatedData;
|
|
15143
15117
|
const newProcedure = {
|
|
15144
15118
|
id: procedureId,
|
|
15145
|
-
...
|
|
15119
|
+
...validatedDataWithoutProductsMetadata,
|
|
15146
15120
|
// Ensure nameLower is always set even if omitted by client
|
|
15147
15121
|
nameLower: validatedData.nameLower || validatedData.name.toLowerCase(),
|
|
15148
15122
|
photos: processedPhotos,
|
|
@@ -15152,6 +15126,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15152
15126
|
technology,
|
|
15153
15127
|
product,
|
|
15154
15128
|
productsMetadata: transformedProductsMetadata,
|
|
15129
|
+
// Use transformed data, not original
|
|
15155
15130
|
blockingConditions: technology.blockingConditions,
|
|
15156
15131
|
contraindications: technology.contraindications || [],
|
|
15157
15132
|
contraindicationIds: ((_b = technology.contraindications) == null ? void 0 : _b.map((c) => c.id)) || [],
|
|
@@ -15205,24 +15180,16 @@ var ProcedureService = class extends BaseService {
|
|
|
15205
15180
|
const validatedData = createProcedureSchema.parse(validationData);
|
|
15206
15181
|
const [category, subcategory, technology, product, clinicSnapshot] = await Promise.all([
|
|
15207
15182
|
this.categoryService.getById(validatedData.categoryId),
|
|
15208
|
-
this.subcategoryService.getById(
|
|
15209
|
-
validatedData.categoryId,
|
|
15210
|
-
validatedData.subcategoryId
|
|
15211
|
-
),
|
|
15183
|
+
this.subcategoryService.getById(validatedData.categoryId, validatedData.subcategoryId),
|
|
15212
15184
|
this.technologyService.getById(validatedData.technologyId),
|
|
15213
|
-
this.productService.getById(
|
|
15214
|
-
validatedData.technologyId,
|
|
15215
|
-
validatedData.productId
|
|
15216
|
-
),
|
|
15185
|
+
this.productService.getById(validatedData.technologyId, validatedData.productId),
|
|
15217
15186
|
(0, import_firestore46.getDoc)((0, import_firestore46.doc)(this.db, CLINICS_COLLECTION, validatedData.clinicBranchId))
|
|
15218
15187
|
]);
|
|
15219
15188
|
if (!category || !subcategory || !technology || !product) {
|
|
15220
15189
|
throw new Error("One or more required base entities not found");
|
|
15221
15190
|
}
|
|
15222
15191
|
if (!clinicSnapshot.exists()) {
|
|
15223
|
-
throw new Error(
|
|
15224
|
-
`Clinic with ID ${validatedData.clinicBranchId} not found`
|
|
15225
|
-
);
|
|
15192
|
+
throw new Error(`Clinic with ID ${validatedData.clinicBranchId} not found`);
|
|
15226
15193
|
}
|
|
15227
15194
|
const clinic = clinicSnapshot.data();
|
|
15228
15195
|
let processedPhotos = [];
|
|
@@ -15252,12 +15219,8 @@ var ProcedureService = class extends BaseService {
|
|
|
15252
15219
|
}
|
|
15253
15220
|
if (practitionersMap.size !== practitionerIds.length) {
|
|
15254
15221
|
const foundIds = Array.from(practitionersMap.keys());
|
|
15255
|
-
const notFoundIds = practitionerIds.filter(
|
|
15256
|
-
|
|
15257
|
-
);
|
|
15258
|
-
throw new Error(
|
|
15259
|
-
`The following practitioners were not found: ${notFoundIds.join(", ")}`
|
|
15260
|
-
);
|
|
15222
|
+
const notFoundIds = practitionerIds.filter((id) => !foundIds.includes(id));
|
|
15223
|
+
throw new Error(`The following practitioners were not found: ${notFoundIds.join(", ")}`);
|
|
15261
15224
|
}
|
|
15262
15225
|
const batch = (0, import_firestore46.writeBatch)(this.db);
|
|
15263
15226
|
const createdProcedureIds = [];
|
|
@@ -15282,9 +15245,10 @@ var ProcedureService = class extends BaseService {
|
|
|
15282
15245
|
const procedureId = this.generateId();
|
|
15283
15246
|
createdProcedureIds.push(procedureId);
|
|
15284
15247
|
const procedureRef = (0, import_firestore46.doc)(this.db, PROCEDURES_COLLECTION, procedureId);
|
|
15248
|
+
const { productsMetadata: _, ...validatedDataWithoutProductsMetadata } = validatedData;
|
|
15285
15249
|
const newProcedure = {
|
|
15286
15250
|
id: procedureId,
|
|
15287
|
-
...
|
|
15251
|
+
...validatedDataWithoutProductsMetadata,
|
|
15288
15252
|
nameLower: validatedData.nameLower || validatedData.name.toLowerCase(),
|
|
15289
15253
|
practitionerId,
|
|
15290
15254
|
// Override practitionerId with the correct one
|
|
@@ -15294,6 +15258,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15294
15258
|
technology,
|
|
15295
15259
|
product,
|
|
15296
15260
|
productsMetadata: transformedProductsMetadata,
|
|
15261
|
+
// Use transformed data, not original
|
|
15297
15262
|
blockingConditions: technology.blockingConditions,
|
|
15298
15263
|
contraindications: technology.contraindications || [],
|
|
15299
15264
|
contraindicationIds: ((_b = technology.contraindications) == null ? void 0 : _b.map((c) => c.id)) || [],
|
|
@@ -15328,10 +15293,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15328
15293
|
const fetchedProcedures = [];
|
|
15329
15294
|
for (let i = 0; i < createdProcedureIds.length; i += 30) {
|
|
15330
15295
|
const chunk = createdProcedureIds.slice(i, i + 30);
|
|
15331
|
-
const q = (0, import_firestore46.query)(
|
|
15332
|
-
(0, import_firestore46.collection)(this.db, PROCEDURES_COLLECTION),
|
|
15333
|
-
(0, import_firestore46.where)((0, import_firestore46.documentId)(), "in", chunk)
|
|
15334
|
-
);
|
|
15296
|
+
const q = (0, import_firestore46.query)((0, import_firestore46.collection)(this.db, PROCEDURES_COLLECTION), (0, import_firestore46.where)((0, import_firestore46.documentId)(), "in", chunk));
|
|
15335
15297
|
const snapshot = await (0, import_firestore46.getDocs)(q);
|
|
15336
15298
|
snapshot.forEach((doc38) => {
|
|
15337
15299
|
fetchedProcedures.push(doc38.data());
|
|
@@ -15410,12 +15372,10 @@ var ProcedureService = class extends BaseService {
|
|
|
15410
15372
|
}
|
|
15411
15373
|
const existingProcedure = procedureSnapshot.data();
|
|
15412
15374
|
let updatedProcedureData = {};
|
|
15413
|
-
if (validatedData.name !== void 0)
|
|
15414
|
-
updatedProcedureData.name = validatedData.name;
|
|
15375
|
+
if (validatedData.name !== void 0) updatedProcedureData.name = validatedData.name;
|
|
15415
15376
|
if (validatedData.description !== void 0)
|
|
15416
15377
|
updatedProcedureData.description = validatedData.description;
|
|
15417
|
-
if (validatedData.price !== void 0)
|
|
15418
|
-
updatedProcedureData.price = validatedData.price;
|
|
15378
|
+
if (validatedData.price !== void 0) updatedProcedureData.price = validatedData.price;
|
|
15419
15379
|
if (validatedData.currency !== void 0)
|
|
15420
15380
|
updatedProcedureData.currency = validatedData.currency;
|
|
15421
15381
|
if (validatedData.pricingMeasure !== void 0)
|
|
@@ -15440,9 +15400,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15440
15400
|
if (validatedData.productsMetadata !== void 0) {
|
|
15441
15401
|
const technologyId = (_a = validatedData.technologyId) != null ? _a : existingProcedure.technology.id;
|
|
15442
15402
|
if (!technologyId) {
|
|
15443
|
-
throw new Error(
|
|
15444
|
-
"Technology ID is required for updating products metadata"
|
|
15445
|
-
);
|
|
15403
|
+
throw new Error("Technology ID is required for updating products metadata");
|
|
15446
15404
|
}
|
|
15447
15405
|
updatedProcedureData.productsMetadata = await this.transformProductsMetadata(
|
|
15448
15406
|
validatedData.productsMetadata,
|
|
@@ -15458,9 +15416,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15458
15416
|
);
|
|
15459
15417
|
const newPractitionerSnap = await (0, import_firestore46.getDoc)(newPractitionerRef);
|
|
15460
15418
|
if (!newPractitionerSnap.exists())
|
|
15461
|
-
throw new Error(
|
|
15462
|
-
`New Practitioner ${validatedData.practitionerId} not found`
|
|
15463
|
-
);
|
|
15419
|
+
throw new Error(`New Practitioner ${validatedData.practitionerId} not found`);
|
|
15464
15420
|
newPractitioner = newPractitionerSnap.data();
|
|
15465
15421
|
updatedProcedureData.doctorInfo = {
|
|
15466
15422
|
id: newPractitioner.id,
|
|
@@ -15474,11 +15430,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15474
15430
|
}
|
|
15475
15431
|
if (validatedData.clinicBranchId && validatedData.clinicBranchId !== oldClinicId) {
|
|
15476
15432
|
clinicChanged = true;
|
|
15477
|
-
const newClinicRef = (0, import_firestore46.doc)(
|
|
15478
|
-
this.db,
|
|
15479
|
-
CLINICS_COLLECTION,
|
|
15480
|
-
validatedData.clinicBranchId
|
|
15481
|
-
);
|
|
15433
|
+
const newClinicRef = (0, import_firestore46.doc)(this.db, CLINICS_COLLECTION, validatedData.clinicBranchId);
|
|
15482
15434
|
const newClinicSnap = await (0, import_firestore46.getDoc)(newClinicRef);
|
|
15483
15435
|
if (!newClinicSnap.exists())
|
|
15484
15436
|
throw new Error(`New Clinic ${validatedData.clinicBranchId} not found`);
|
|
@@ -15497,11 +15449,8 @@ var ProcedureService = class extends BaseService {
|
|
|
15497
15449
|
updatedProcedureData.nameLower = validatedData.name.toLowerCase();
|
|
15498
15450
|
}
|
|
15499
15451
|
if (validatedData.categoryId) {
|
|
15500
|
-
const category = await this.categoryService.getById(
|
|
15501
|
-
|
|
15502
|
-
);
|
|
15503
|
-
if (!category)
|
|
15504
|
-
throw new Error(`Category ${validatedData.categoryId} not found`);
|
|
15452
|
+
const category = await this.categoryService.getById(validatedData.categoryId);
|
|
15453
|
+
if (!category) throw new Error(`Category ${validatedData.categoryId} not found`);
|
|
15505
15454
|
updatedProcedureData.category = category;
|
|
15506
15455
|
finalCategoryId = category.id;
|
|
15507
15456
|
}
|
|
@@ -15516,17 +15465,12 @@ var ProcedureService = class extends BaseService {
|
|
|
15516
15465
|
);
|
|
15517
15466
|
updatedProcedureData.subcategory = subcategory;
|
|
15518
15467
|
} else if (validatedData.subcategoryId) {
|
|
15519
|
-
console.warn(
|
|
15520
|
-
"Attempted to update subcategory without a valid categoryId"
|
|
15521
|
-
);
|
|
15468
|
+
console.warn("Attempted to update subcategory without a valid categoryId");
|
|
15522
15469
|
}
|
|
15523
15470
|
let finalTechnologyId = existingProcedure.technology.id;
|
|
15524
15471
|
if (validatedData.technologyId) {
|
|
15525
|
-
const technology = await this.technologyService.getById(
|
|
15526
|
-
|
|
15527
|
-
);
|
|
15528
|
-
if (!technology)
|
|
15529
|
-
throw new Error(`Technology ${validatedData.technologyId} not found`);
|
|
15472
|
+
const technology = await this.technologyService.getById(validatedData.technologyId);
|
|
15473
|
+
if (!technology) throw new Error(`Technology ${validatedData.technologyId} not found`);
|
|
15530
15474
|
updatedProcedureData.technology = technology;
|
|
15531
15475
|
finalTechnologyId = technology.id;
|
|
15532
15476
|
updatedProcedureData.blockingConditions = technology.blockingConditions;
|
|
@@ -15540,10 +15484,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15540
15484
|
updatedProcedureData.documentationTemplates = technology.documentationTemplates || [];
|
|
15541
15485
|
}
|
|
15542
15486
|
if (validatedData.productId && finalTechnologyId) {
|
|
15543
|
-
const product = await this.productService.getById(
|
|
15544
|
-
finalTechnologyId,
|
|
15545
|
-
validatedData.productId
|
|
15546
|
-
);
|
|
15487
|
+
const product = await this.productService.getById(finalTechnologyId, validatedData.productId);
|
|
15547
15488
|
if (!product)
|
|
15548
15489
|
throw new Error(
|
|
15549
15490
|
`Product ${validatedData.productId} not found for technology ${finalTechnologyId}`
|
|
@@ -15625,11 +15566,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15625
15566
|
limit21(pagination)
|
|
15626
15567
|
);
|
|
15627
15568
|
} else {
|
|
15628
|
-
proceduresQuery = (0, import_firestore46.query)(
|
|
15629
|
-
proceduresCollection,
|
|
15630
|
-
(0, import_firestore46.orderBy)("name"),
|
|
15631
|
-
limit21(pagination)
|
|
15632
|
-
);
|
|
15569
|
+
proceduresQuery = (0, import_firestore46.query)(proceduresCollection, (0, import_firestore46.orderBy)("name"), limit21(pagination));
|
|
15633
15570
|
}
|
|
15634
15571
|
} else {
|
|
15635
15572
|
proceduresQuery = (0, import_firestore46.query)(proceduresCollection, (0, import_firestore46.orderBy)("name"));
|
|
@@ -15678,9 +15615,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15678
15615
|
*/
|
|
15679
15616
|
async getProceduresByFilters(filters) {
|
|
15680
15617
|
try {
|
|
15681
|
-
console.log(
|
|
15682
|
-
"[PROCEDURE_SERVICE] Starting procedure filtering with multiple strategies"
|
|
15683
|
-
);
|
|
15618
|
+
console.log("[PROCEDURE_SERVICE] Starting procedure filtering with multiple strategies");
|
|
15684
15619
|
if (filters.location && filters.radiusInKm) {
|
|
15685
15620
|
console.log("[PROCEDURE_SERVICE] Executing geo query:", {
|
|
15686
15621
|
location: filters.location,
|
|
@@ -15688,10 +15623,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15688
15623
|
serviceName: "ProcedureService"
|
|
15689
15624
|
});
|
|
15690
15625
|
if (!filters.location.latitude || !filters.location.longitude) {
|
|
15691
|
-
console.warn(
|
|
15692
|
-
"[PROCEDURE_SERVICE] Invalid location data:",
|
|
15693
|
-
filters.location
|
|
15694
|
-
);
|
|
15626
|
+
console.warn("[PROCEDURE_SERVICE] Invalid location data:", filters.location);
|
|
15695
15627
|
filters.location = void 0;
|
|
15696
15628
|
filters.radiusInKm = void 0;
|
|
15697
15629
|
}
|
|
@@ -15711,19 +15643,13 @@ var ProcedureService = class extends BaseService {
|
|
|
15711
15643
|
constraints.push((0, import_firestore46.where)("family", "==", filters.procedureFamily));
|
|
15712
15644
|
}
|
|
15713
15645
|
if (filters.procedureCategory) {
|
|
15714
|
-
constraints.push(
|
|
15715
|
-
(0, import_firestore46.where)("category.id", "==", filters.procedureCategory)
|
|
15716
|
-
);
|
|
15646
|
+
constraints.push((0, import_firestore46.where)("category.id", "==", filters.procedureCategory));
|
|
15717
15647
|
}
|
|
15718
15648
|
if (filters.procedureSubcategory) {
|
|
15719
|
-
constraints.push(
|
|
15720
|
-
(0, import_firestore46.where)("subcategory.id", "==", filters.procedureSubcategory)
|
|
15721
|
-
);
|
|
15649
|
+
constraints.push((0, import_firestore46.where)("subcategory.id", "==", filters.procedureSubcategory));
|
|
15722
15650
|
}
|
|
15723
15651
|
if (filters.procedureTechnology) {
|
|
15724
|
-
constraints.push(
|
|
15725
|
-
(0, import_firestore46.where)("technology.id", "==", filters.procedureTechnology)
|
|
15726
|
-
);
|
|
15652
|
+
constraints.push((0, import_firestore46.where)("technology.id", "==", filters.procedureTechnology));
|
|
15727
15653
|
}
|
|
15728
15654
|
if (filters.minPrice !== void 0) {
|
|
15729
15655
|
constraints.push((0, import_firestore46.where)("price", ">=", filters.minPrice));
|
|
@@ -15732,32 +15658,20 @@ var ProcedureService = class extends BaseService {
|
|
|
15732
15658
|
constraints.push((0, import_firestore46.where)("price", "<=", filters.maxPrice));
|
|
15733
15659
|
}
|
|
15734
15660
|
if (filters.minRating !== void 0) {
|
|
15735
|
-
constraints.push(
|
|
15736
|
-
(0, import_firestore46.where)("reviewInfo.averageRating", ">=", filters.minRating)
|
|
15737
|
-
);
|
|
15661
|
+
constraints.push((0, import_firestore46.where)("reviewInfo.averageRating", ">=", filters.minRating));
|
|
15738
15662
|
}
|
|
15739
15663
|
if (filters.maxRating !== void 0) {
|
|
15740
|
-
constraints.push(
|
|
15741
|
-
(0, import_firestore46.where)("reviewInfo.averageRating", "<=", filters.maxRating)
|
|
15742
|
-
);
|
|
15664
|
+
constraints.push((0, import_firestore46.where)("reviewInfo.averageRating", "<=", filters.maxRating));
|
|
15743
15665
|
}
|
|
15744
15666
|
if (filters.treatmentBenefits && filters.treatmentBenefits.length > 0) {
|
|
15745
15667
|
const benefitIdsToMatch = filters.treatmentBenefits;
|
|
15746
|
-
constraints.push(
|
|
15747
|
-
(0, import_firestore46.where)(
|
|
15748
|
-
"treatmentBenefitIds",
|
|
15749
|
-
"array-contains-any",
|
|
15750
|
-
benefitIdsToMatch
|
|
15751
|
-
)
|
|
15752
|
-
);
|
|
15668
|
+
constraints.push((0, import_firestore46.where)("treatmentBenefitIds", "array-contains-any", benefitIdsToMatch));
|
|
15753
15669
|
}
|
|
15754
15670
|
return constraints;
|
|
15755
15671
|
};
|
|
15756
15672
|
if (filters.nameSearch && filters.nameSearch.trim()) {
|
|
15757
15673
|
try {
|
|
15758
|
-
console.log(
|
|
15759
|
-
"[PROCEDURE_SERVICE] Strategy 1: Trying nameLower search"
|
|
15760
|
-
);
|
|
15674
|
+
console.log("[PROCEDURE_SERVICE] Strategy 1: Trying nameLower search");
|
|
15761
15675
|
const searchTerm = filters.nameSearch.trim().toLowerCase();
|
|
15762
15676
|
const constraints = getBaseConstraints();
|
|
15763
15677
|
constraints.push((0, import_firestore46.where)("nameLower", ">=", searchTerm));
|
|
@@ -15773,18 +15687,13 @@ var ProcedureService = class extends BaseService {
|
|
|
15773
15687
|
}
|
|
15774
15688
|
}
|
|
15775
15689
|
constraints.push((0, import_firestore46.limit)(filters.pagination || 10));
|
|
15776
|
-
const q = (0, import_firestore46.query)(
|
|
15777
|
-
(0, import_firestore46.collection)(this.db, PROCEDURES_COLLECTION),
|
|
15778
|
-
...constraints
|
|
15779
|
-
);
|
|
15690
|
+
const q = (0, import_firestore46.query)((0, import_firestore46.collection)(this.db, PROCEDURES_COLLECTION), ...constraints);
|
|
15780
15691
|
const querySnapshot = await (0, import_firestore46.getDocs)(q);
|
|
15781
15692
|
const procedures = querySnapshot.docs.map(
|
|
15782
15693
|
(doc38) => ({ ...doc38.data(), id: doc38.id })
|
|
15783
15694
|
);
|
|
15784
15695
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
15785
|
-
console.log(
|
|
15786
|
-
`[PROCEDURE_SERVICE] Strategy 1 success: ${procedures.length} procedures`
|
|
15787
|
-
);
|
|
15696
|
+
console.log(`[PROCEDURE_SERVICE] Strategy 1 success: ${procedures.length} procedures`);
|
|
15788
15697
|
if (procedures.length < (filters.pagination || 10)) {
|
|
15789
15698
|
return { procedures, lastDoc: null };
|
|
15790
15699
|
}
|
|
@@ -15795,9 +15704,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15795
15704
|
}
|
|
15796
15705
|
if (filters.nameSearch && filters.nameSearch.trim()) {
|
|
15797
15706
|
try {
|
|
15798
|
-
console.log(
|
|
15799
|
-
"[PROCEDURE_SERVICE] Strategy 2: Trying name field search"
|
|
15800
|
-
);
|
|
15707
|
+
console.log("[PROCEDURE_SERVICE] Strategy 2: Trying name field search");
|
|
15801
15708
|
const searchTerm = filters.nameSearch.trim().toLowerCase();
|
|
15802
15709
|
const constraints = getBaseConstraints();
|
|
15803
15710
|
constraints.push((0, import_firestore46.where)("name", ">=", searchTerm));
|
|
@@ -15813,18 +15720,13 @@ var ProcedureService = class extends BaseService {
|
|
|
15813
15720
|
}
|
|
15814
15721
|
}
|
|
15815
15722
|
constraints.push((0, import_firestore46.limit)(filters.pagination || 10));
|
|
15816
|
-
const q = (0, import_firestore46.query)(
|
|
15817
|
-
(0, import_firestore46.collection)(this.db, PROCEDURES_COLLECTION),
|
|
15818
|
-
...constraints
|
|
15819
|
-
);
|
|
15723
|
+
const q = (0, import_firestore46.query)((0, import_firestore46.collection)(this.db, PROCEDURES_COLLECTION), ...constraints);
|
|
15820
15724
|
const querySnapshot = await (0, import_firestore46.getDocs)(q);
|
|
15821
15725
|
const procedures = querySnapshot.docs.map(
|
|
15822
15726
|
(doc38) => ({ ...doc38.data(), id: doc38.id })
|
|
15823
15727
|
);
|
|
15824
15728
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
15825
|
-
console.log(
|
|
15826
|
-
`[PROCEDURE_SERVICE] Strategy 2 success: ${procedures.length} procedures`
|
|
15827
|
-
);
|
|
15729
|
+
console.log(`[PROCEDURE_SERVICE] Strategy 2 success: ${procedures.length} procedures`);
|
|
15828
15730
|
if (procedures.length < (filters.pagination || 10)) {
|
|
15829
15731
|
return { procedures, lastDoc: null };
|
|
15830
15732
|
}
|
|
@@ -15849,19 +15751,14 @@ var ProcedureService = class extends BaseService {
|
|
|
15849
15751
|
}
|
|
15850
15752
|
}
|
|
15851
15753
|
constraints.push((0, import_firestore46.limit)(filters.pagination || 10));
|
|
15852
|
-
const q = (0, import_firestore46.query)(
|
|
15853
|
-
(0, import_firestore46.collection)(this.db, PROCEDURES_COLLECTION),
|
|
15854
|
-
...constraints
|
|
15855
|
-
);
|
|
15754
|
+
const q = (0, import_firestore46.query)((0, import_firestore46.collection)(this.db, PROCEDURES_COLLECTION), ...constraints);
|
|
15856
15755
|
const querySnapshot = await (0, import_firestore46.getDocs)(q);
|
|
15857
15756
|
let procedures = querySnapshot.docs.map(
|
|
15858
15757
|
(doc38) => ({ ...doc38.data(), id: doc38.id })
|
|
15859
15758
|
);
|
|
15860
15759
|
procedures = this.applyInMemoryFilters(procedures, filters);
|
|
15861
15760
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
15862
|
-
console.log(
|
|
15863
|
-
`[PROCEDURE_SERVICE] Strategy 3 success: ${procedures.length} procedures`
|
|
15864
|
-
);
|
|
15761
|
+
console.log(`[PROCEDURE_SERVICE] Strategy 3 success: ${procedures.length} procedures`);
|
|
15865
15762
|
if (procedures.length < (filters.pagination || 10)) {
|
|
15866
15763
|
return { procedures, lastDoc: null };
|
|
15867
15764
|
}
|
|
@@ -15876,19 +15773,14 @@ var ProcedureService = class extends BaseService {
|
|
|
15876
15773
|
(0, import_firestore46.orderBy)("createdAt", "desc"),
|
|
15877
15774
|
(0, import_firestore46.limit)(filters.pagination || 10)
|
|
15878
15775
|
];
|
|
15879
|
-
const q = (0, import_firestore46.query)(
|
|
15880
|
-
(0, import_firestore46.collection)(this.db, PROCEDURES_COLLECTION),
|
|
15881
|
-
...constraints
|
|
15882
|
-
);
|
|
15776
|
+
const q = (0, import_firestore46.query)((0, import_firestore46.collection)(this.db, PROCEDURES_COLLECTION), ...constraints);
|
|
15883
15777
|
const querySnapshot = await (0, import_firestore46.getDocs)(q);
|
|
15884
15778
|
let procedures = querySnapshot.docs.map(
|
|
15885
15779
|
(doc38) => ({ ...doc38.data(), id: doc38.id })
|
|
15886
15780
|
);
|
|
15887
15781
|
procedures = this.applyInMemoryFilters(procedures, filters);
|
|
15888
15782
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
15889
|
-
console.log(
|
|
15890
|
-
`[PROCEDURE_SERVICE] Strategy 4 success: ${procedures.length} procedures`
|
|
15891
|
-
);
|
|
15783
|
+
console.log(`[PROCEDURE_SERVICE] Strategy 4 success: ${procedures.length} procedures`);
|
|
15892
15784
|
if (procedures.length < (filters.pagination || 10)) {
|
|
15893
15785
|
return { procedures, lastDoc: null };
|
|
15894
15786
|
}
|
|
@@ -15896,9 +15788,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15896
15788
|
} catch (error) {
|
|
15897
15789
|
console.log("[PROCEDURE_SERVICE] Strategy 4 failed:", error);
|
|
15898
15790
|
}
|
|
15899
|
-
console.log(
|
|
15900
|
-
"[PROCEDURE_SERVICE] All strategies failed, returning empty result"
|
|
15901
|
-
);
|
|
15791
|
+
console.log("[PROCEDURE_SERVICE] All strategies failed, returning empty result");
|
|
15902
15792
|
return { procedures: [], lastDoc: null };
|
|
15903
15793
|
} catch (error) {
|
|
15904
15794
|
console.error("[PROCEDURE_SERVICE] Error filtering procedures:", error);
|
|
@@ -15918,17 +15808,13 @@ var ProcedureService = class extends BaseService {
|
|
|
15918
15808
|
const nameLower = procedure.nameLower || "";
|
|
15919
15809
|
return name.includes(searchTerm) || nameLower.includes(searchTerm);
|
|
15920
15810
|
});
|
|
15921
|
-
console.log(
|
|
15922
|
-
`[PROCEDURE_SERVICE] Applied name filter, results: ${filteredProcedures.length}`
|
|
15923
|
-
);
|
|
15811
|
+
console.log(`[PROCEDURE_SERVICE] Applied name filter, results: ${filteredProcedures.length}`);
|
|
15924
15812
|
}
|
|
15925
15813
|
if (filters.minPrice !== void 0 || filters.maxPrice !== void 0) {
|
|
15926
15814
|
filteredProcedures = filteredProcedures.filter((procedure) => {
|
|
15927
15815
|
const price = procedure.price || 0;
|
|
15928
|
-
if (filters.minPrice !== void 0 && price < filters.minPrice)
|
|
15929
|
-
|
|
15930
|
-
if (filters.maxPrice !== void 0 && price > filters.maxPrice)
|
|
15931
|
-
return false;
|
|
15816
|
+
if (filters.minPrice !== void 0 && price < filters.minPrice) return false;
|
|
15817
|
+
if (filters.maxPrice !== void 0 && price > filters.maxPrice) return false;
|
|
15932
15818
|
return true;
|
|
15933
15819
|
});
|
|
15934
15820
|
console.log(
|
|
@@ -15939,10 +15825,8 @@ var ProcedureService = class extends BaseService {
|
|
|
15939
15825
|
filteredProcedures = filteredProcedures.filter((procedure) => {
|
|
15940
15826
|
var _a;
|
|
15941
15827
|
const rating = ((_a = procedure.reviewInfo) == null ? void 0 : _a.averageRating) || 0;
|
|
15942
|
-
if (filters.minRating !== void 0 && rating < filters.minRating)
|
|
15943
|
-
|
|
15944
|
-
if (filters.maxRating !== void 0 && rating > filters.maxRating)
|
|
15945
|
-
return false;
|
|
15828
|
+
if (filters.minRating !== void 0 && rating < filters.minRating) return false;
|
|
15829
|
+
if (filters.maxRating !== void 0 && rating > filters.maxRating) return false;
|
|
15946
15830
|
return true;
|
|
15947
15831
|
});
|
|
15948
15832
|
console.log(
|
|
@@ -16018,12 +15902,8 @@ var ProcedureService = class extends BaseService {
|
|
|
16018
15902
|
procedure.distance = distance;
|
|
16019
15903
|
return distance <= radiusInKm;
|
|
16020
15904
|
});
|
|
16021
|
-
console.log(
|
|
16022
|
-
|
|
16023
|
-
);
|
|
16024
|
-
filteredProcedures.sort(
|
|
16025
|
-
(a, b) => (a.distance || 0) - (b.distance || 0)
|
|
16026
|
-
);
|
|
15905
|
+
console.log(`[PROCEDURE_SERVICE] Applied geo filter, results: ${filteredProcedures.length}`);
|
|
15906
|
+
filteredProcedures.sort((a, b) => (a.distance || 0) - (b.distance || 0));
|
|
16027
15907
|
}
|
|
16028
15908
|
return filteredProcedures;
|
|
16029
15909
|
}
|
|
@@ -16035,30 +15915,19 @@ var ProcedureService = class extends BaseService {
|
|
|
16035
15915
|
if (!location || !radiusInKm) {
|
|
16036
15916
|
return Promise.resolve({ procedures: [], lastDoc: null });
|
|
16037
15917
|
}
|
|
16038
|
-
const bounds = (0, import_geofire_common8.geohashQueryBounds)(
|
|
16039
|
-
[location.latitude, location.longitude],
|
|
16040
|
-
radiusInKm * 1e3
|
|
16041
|
-
);
|
|
15918
|
+
const bounds = (0, import_geofire_common8.geohashQueryBounds)([location.latitude, location.longitude], radiusInKm * 1e3);
|
|
16042
15919
|
const fetches = bounds.map((b) => {
|
|
16043
15920
|
const constraints = [
|
|
16044
15921
|
(0, import_firestore46.where)("clinicInfo.location.geohash", ">=", b[0]),
|
|
16045
15922
|
(0, import_firestore46.where)("clinicInfo.location.geohash", "<=", b[1]),
|
|
16046
|
-
(0, import_firestore46.where)(
|
|
16047
|
-
"isActive",
|
|
16048
|
-
"==",
|
|
16049
|
-
filters.isActive !== void 0 ? filters.isActive : true
|
|
16050
|
-
)
|
|
15923
|
+
(0, import_firestore46.where)("isActive", "==", filters.isActive !== void 0 ? filters.isActive : true)
|
|
16051
15924
|
];
|
|
16052
|
-
return (0, import_firestore46.getDocs)(
|
|
16053
|
-
(0, import_firestore46.query)((0, import_firestore46.collection)(this.db, PROCEDURES_COLLECTION), ...constraints)
|
|
16054
|
-
);
|
|
15925
|
+
return (0, import_firestore46.getDocs)((0, import_firestore46.query)((0, import_firestore46.collection)(this.db, PROCEDURES_COLLECTION), ...constraints));
|
|
16055
15926
|
});
|
|
16056
15927
|
return Promise.all(fetches).then((snaps) => {
|
|
16057
15928
|
const collected = [];
|
|
16058
15929
|
snaps.forEach((snap) => {
|
|
16059
|
-
snap.docs.forEach(
|
|
16060
|
-
(d) => collected.push({ ...d.data(), id: d.id })
|
|
16061
|
-
);
|
|
15930
|
+
snap.docs.forEach((d) => collected.push({ ...d.data(), id: d.id }));
|
|
16062
15931
|
});
|
|
16063
15932
|
const uniqueMap = /* @__PURE__ */ new Map();
|
|
16064
15933
|
for (const p of collected) {
|
|
@@ -16069,9 +15938,7 @@ var ProcedureService = class extends BaseService {
|
|
|
16069
15938
|
const pageSize = filters.pagination || 10;
|
|
16070
15939
|
let startIndex = 0;
|
|
16071
15940
|
if (filters.lastDoc && typeof filters.lastDoc === "object" && filters.lastDoc.id) {
|
|
16072
|
-
const idx = procedures.findIndex(
|
|
16073
|
-
(p) => p.id === filters.lastDoc.id
|
|
16074
|
-
);
|
|
15941
|
+
const idx = procedures.findIndex((p) => p.id === filters.lastDoc.id);
|
|
16075
15942
|
if (idx >= 0) startIndex = idx + 1;
|
|
16076
15943
|
}
|
|
16077
15944
|
const page = procedures.slice(startIndex, startIndex + pageSize);
|
|
@@ -16112,11 +15979,7 @@ var ProcedureService = class extends BaseService {
|
|
|
16112
15979
|
throw new Error(`Clinic with ID ${data.clinicBranchId} not found`);
|
|
16113
15980
|
}
|
|
16114
15981
|
const clinic = clinicSnapshot.data();
|
|
16115
|
-
const practitionerRef = (0, import_firestore46.doc)(
|
|
16116
|
-
this.db,
|
|
16117
|
-
PRACTITIONERS_COLLECTION,
|
|
16118
|
-
data.practitionerId
|
|
16119
|
-
);
|
|
15982
|
+
const practitionerRef = (0, import_firestore46.doc)(this.db, PRACTITIONERS_COLLECTION, data.practitionerId);
|
|
16120
15983
|
const practitionerSnapshot = await (0, import_firestore46.getDoc)(practitionerRef);
|
|
16121
15984
|
if (!practitionerSnapshot.exists()) {
|
|
16122
15985
|
throw new Error(`Practitioner with ID ${data.practitionerId} not found`);
|
|
@@ -16124,11 +15987,7 @@ var ProcedureService = class extends BaseService {
|
|
|
16124
15987
|
const practitioner = practitionerSnapshot.data();
|
|
16125
15988
|
let processedPhotos = [];
|
|
16126
15989
|
if (data.photos && data.photos.length > 0) {
|
|
16127
|
-
processedPhotos = await this.processMediaArray(
|
|
16128
|
-
data.photos,
|
|
16129
|
-
procedureId,
|
|
16130
|
-
"procedure-photos"
|
|
16131
|
-
);
|
|
15990
|
+
processedPhotos = await this.processMediaArray(data.photos, procedureId, "procedure-photos");
|
|
16132
15991
|
}
|
|
16133
15992
|
const transformedProductsMetadata = await this.transformProductsMetadata(
|
|
16134
15993
|
data.productsMetadata,
|
|
@@ -16164,9 +16023,10 @@ var ProcedureService = class extends BaseService {
|
|
|
16164
16023
|
createdAt: /* @__PURE__ */ new Date(),
|
|
16165
16024
|
updatedAt: /* @__PURE__ */ new Date()
|
|
16166
16025
|
};
|
|
16026
|
+
const { productsMetadata: _, ...dataWithoutProductsMetadata } = data;
|
|
16167
16027
|
const newProcedure = {
|
|
16168
16028
|
id: procedureId,
|
|
16169
|
-
...
|
|
16029
|
+
...dataWithoutProductsMetadata,
|
|
16170
16030
|
nameLower: data.nameLower || data.name.toLowerCase(),
|
|
16171
16031
|
photos: processedPhotos,
|
|
16172
16032
|
category,
|
|
@@ -16175,6 +16035,7 @@ var ProcedureService = class extends BaseService {
|
|
|
16175
16035
|
product: consultationProduct,
|
|
16176
16036
|
// Use placeholder product
|
|
16177
16037
|
productsMetadata: transformedProductsMetadata,
|
|
16038
|
+
// Use transformed data, not original
|
|
16178
16039
|
blockingConditions: technology.blockingConditions,
|
|
16179
16040
|
contraindications: technology.contraindications || [],
|
|
16180
16041
|
contraindicationIds: ((_b = technology.contraindications) == null ? void 0 : _b.map((c) => c.id)) || [],
|
|
@@ -16683,6 +16544,26 @@ var CategoryService = class extends BaseService {
|
|
|
16683
16544
|
})
|
|
16684
16545
|
);
|
|
16685
16546
|
}
|
|
16547
|
+
/**
|
|
16548
|
+
* Vraća sve kategorije za određenu familiju za potrebe filtera (bez paginacije)
|
|
16549
|
+
* @param family - Familija procedura (aesthetics/surgery)
|
|
16550
|
+
* @returns Lista aktivnih kategorija koje pripadaju traženoj familiji
|
|
16551
|
+
*/
|
|
16552
|
+
async getAllForFilterByFamily(family) {
|
|
16553
|
+
const q = (0, import_firestore50.query)(
|
|
16554
|
+
this.categoriesRef,
|
|
16555
|
+
(0, import_firestore50.where)("family", "==", family),
|
|
16556
|
+
(0, import_firestore50.where)("isActive", "==", true),
|
|
16557
|
+
(0, import_firestore50.orderBy)("name")
|
|
16558
|
+
);
|
|
16559
|
+
const snapshot = await (0, import_firestore50.getDocs)(q);
|
|
16560
|
+
return snapshot.docs.map(
|
|
16561
|
+
(doc38) => ({
|
|
16562
|
+
id: doc38.id,
|
|
16563
|
+
...doc38.data()
|
|
16564
|
+
})
|
|
16565
|
+
);
|
|
16566
|
+
}
|
|
16686
16567
|
/**
|
|
16687
16568
|
* Vraća sve kategorije sa paginacijom
|
|
16688
16569
|
* @param options - Pagination and filter options
|
|
@@ -17316,7 +17197,9 @@ var TechnologyService = class extends BaseService {
|
|
|
17316
17197
|
if (!technology) {
|
|
17317
17198
|
throw new Error(`Technology with id ${technologyId} not found`);
|
|
17318
17199
|
}
|
|
17319
|
-
const updatedContraindications = (technology.contraindications || []).filter(
|
|
17200
|
+
const updatedContraindications = (technology.contraindications || []).filter(
|
|
17201
|
+
(c) => c.id !== contraindication.id
|
|
17202
|
+
);
|
|
17320
17203
|
await (0, import_firestore52.updateDoc)(docRef, {
|
|
17321
17204
|
contraindications: updatedContraindications,
|
|
17322
17205
|
updatedAt: /* @__PURE__ */ new Date()
|
|
@@ -17337,9 +17220,7 @@ var TechnologyService = class extends BaseService {
|
|
|
17337
17220
|
throw new Error(`Technology with id ${technologyId} not found`);
|
|
17338
17221
|
}
|
|
17339
17222
|
const contraindications = technology.contraindications || [];
|
|
17340
|
-
const index = contraindications.findIndex(
|
|
17341
|
-
(c) => c.id === contraindication.id
|
|
17342
|
-
);
|
|
17223
|
+
const index = contraindications.findIndex((c) => c.id === contraindication.id);
|
|
17343
17224
|
if (index === -1) {
|
|
17344
17225
|
console.warn(
|
|
17345
17226
|
`Contraindication with id ${contraindication.id} not found for technology ${technologyId}. No update performed.`
|
|
@@ -17388,9 +17269,7 @@ var TechnologyService = class extends BaseService {
|
|
|
17388
17269
|
if (!technology) {
|
|
17389
17270
|
throw new Error(`Technology with id ${technologyId} not found`);
|
|
17390
17271
|
}
|
|
17391
|
-
const updatedBenefits = (technology.benefits || []).filter(
|
|
17392
|
-
(b) => b.id !== benefit.id
|
|
17393
|
-
);
|
|
17272
|
+
const updatedBenefits = (technology.benefits || []).filter((b) => b.id !== benefit.id);
|
|
17394
17273
|
await (0, import_firestore52.updateDoc)(docRef, {
|
|
17395
17274
|
benefits: updatedBenefits,
|
|
17396
17275
|
updatedAt: /* @__PURE__ */ new Date()
|
|
@@ -17496,9 +17375,7 @@ var TechnologyService = class extends BaseService {
|
|
|
17496
17375
|
* );
|
|
17497
17376
|
*/
|
|
17498
17377
|
validateCertification(requiredCertification, practitionerCertification) {
|
|
17499
|
-
const doctorLevel = Object.values(CertificationLevel).indexOf(
|
|
17500
|
-
practitionerCertification.level
|
|
17501
|
-
);
|
|
17378
|
+
const doctorLevel = Object.values(CertificationLevel).indexOf(practitionerCertification.level);
|
|
17502
17379
|
const requiredLevel = Object.values(CertificationLevel).indexOf(
|
|
17503
17380
|
requiredCertification.minimumLevel
|
|
17504
17381
|
);
|
|
@@ -17539,18 +17416,11 @@ var TechnologyService = class extends BaseService {
|
|
|
17539
17416
|
async getAllowedTechnologies(practitioner) {
|
|
17540
17417
|
const allTechnologies = await this.getAll();
|
|
17541
17418
|
const allowedTechnologies = allTechnologies.technologies.filter(
|
|
17542
|
-
(technology) => this.validateCertification(
|
|
17543
|
-
technology.certificationRequirement,
|
|
17544
|
-
practitioner.certification
|
|
17545
|
-
)
|
|
17419
|
+
(technology) => this.validateCertification(technology.certificationRequirement, practitioner.certification)
|
|
17546
17420
|
);
|
|
17547
17421
|
const families = [...new Set(allowedTechnologies.map((t) => t.family))];
|
|
17548
|
-
const categories = [
|
|
17549
|
-
|
|
17550
|
-
];
|
|
17551
|
-
const subcategories = [
|
|
17552
|
-
...new Set(allowedTechnologies.map((t) => t.subcategoryId))
|
|
17553
|
-
];
|
|
17422
|
+
const categories = [...new Set(allowedTechnologies.map((t) => t.categoryId))];
|
|
17423
|
+
const subcategories = [...new Set(allowedTechnologies.map((t) => t.subcategoryId))];
|
|
17554
17424
|
return {
|
|
17555
17425
|
technologies: allowedTechnologies,
|
|
17556
17426
|
families,
|
|
@@ -17558,6 +17428,25 @@ var TechnologyService = class extends BaseService {
|
|
|
17558
17428
|
subcategories
|
|
17559
17429
|
};
|
|
17560
17430
|
}
|
|
17431
|
+
/**
|
|
17432
|
+
* Gets all active technologies for a subcategory for filter dropdowns (by subcategory only).
|
|
17433
|
+
* @param subcategoryId - The ID of the subcategory.
|
|
17434
|
+
*/
|
|
17435
|
+
async getAllForFilterBySubcategory(subcategoryId) {
|
|
17436
|
+
const q = (0, import_firestore52.query)(
|
|
17437
|
+
(0, import_firestore52.collection)(this.db, TECHNOLOGIES_COLLECTION),
|
|
17438
|
+
(0, import_firestore52.where)("isActive", "==", true),
|
|
17439
|
+
(0, import_firestore52.where)("subcategoryId", "==", subcategoryId),
|
|
17440
|
+
(0, import_firestore52.orderBy)("name")
|
|
17441
|
+
);
|
|
17442
|
+
const snapshot = await (0, import_firestore52.getDocs)(q);
|
|
17443
|
+
return snapshot.docs.map(
|
|
17444
|
+
(doc38) => ({
|
|
17445
|
+
id: doc38.id,
|
|
17446
|
+
...doc38.data()
|
|
17447
|
+
})
|
|
17448
|
+
);
|
|
17449
|
+
}
|
|
17561
17450
|
/**
|
|
17562
17451
|
* Gets all active technologies for a subcategory for filter dropdowns.
|
|
17563
17452
|
* @param categoryId - The ID of the parent category.
|
|
@@ -17612,12 +17501,7 @@ var ProductService = class extends BaseService {
|
|
|
17612
17501
|
* @returns Firestore collection reference
|
|
17613
17502
|
*/
|
|
17614
17503
|
getProductsRef(technologyId) {
|
|
17615
|
-
return (0, import_firestore53.collection)(
|
|
17616
|
-
this.db,
|
|
17617
|
-
TECHNOLOGIES_COLLECTION,
|
|
17618
|
-
technologyId,
|
|
17619
|
-
PRODUCTS_COLLECTION
|
|
17620
|
-
);
|
|
17504
|
+
return (0, import_firestore53.collection)(this.db, TECHNOLOGIES_COLLECTION, technologyId, PRODUCTS_COLLECTION);
|
|
17621
17505
|
}
|
|
17622
17506
|
/**
|
|
17623
17507
|
* Creates a new product under technology
|
|
@@ -17632,10 +17516,7 @@ var ProductService = class extends BaseService {
|
|
|
17632
17516
|
updatedAt: now,
|
|
17633
17517
|
isActive: true
|
|
17634
17518
|
};
|
|
17635
|
-
const productRef = await (0, import_firestore53.addDoc)(
|
|
17636
|
-
this.getProductsRef(technologyId),
|
|
17637
|
-
newProduct
|
|
17638
|
-
);
|
|
17519
|
+
const productRef = await (0, import_firestore53.addDoc)(this.getProductsRef(technologyId), newProduct);
|
|
17639
17520
|
return { id: productRef.id, ...newProduct };
|
|
17640
17521
|
}
|
|
17641
17522
|
/**
|
|
@@ -17643,17 +17524,8 @@ var ProductService = class extends BaseService {
|
|
|
17643
17524
|
* This uses a collectionGroup query to search across all technologies.
|
|
17644
17525
|
*/
|
|
17645
17526
|
async getAll(options) {
|
|
17646
|
-
const {
|
|
17647
|
-
|
|
17648
|
-
lastVisible,
|
|
17649
|
-
categoryId,
|
|
17650
|
-
subcategoryId,
|
|
17651
|
-
technologyId
|
|
17652
|
-
} = options;
|
|
17653
|
-
const constraints = [
|
|
17654
|
-
(0, import_firestore53.where)("isActive", "==", true),
|
|
17655
|
-
(0, import_firestore53.orderBy)("name")
|
|
17656
|
-
];
|
|
17527
|
+
const { rowsPerPage, lastVisible, categoryId, subcategoryId, technologyId } = options;
|
|
17528
|
+
const constraints = [(0, import_firestore53.where)("isActive", "==", true), (0, import_firestore53.orderBy)("name")];
|
|
17657
17529
|
if (categoryId) {
|
|
17658
17530
|
constraints.push((0, import_firestore53.where)("categoryId", "==", categoryId));
|
|
17659
17531
|
}
|
|
@@ -17667,10 +17539,7 @@ var ProductService = class extends BaseService {
|
|
|
17667
17539
|
constraints.push((0, import_firestore53.startAfter)(lastVisible));
|
|
17668
17540
|
}
|
|
17669
17541
|
constraints.push((0, import_firestore53.limit)(rowsPerPage));
|
|
17670
|
-
const q = (0, import_firestore53.query)(
|
|
17671
|
-
(0, import_firestore53.collectionGroup)(this.db, PRODUCTS_COLLECTION),
|
|
17672
|
-
...constraints
|
|
17673
|
-
);
|
|
17542
|
+
const q = (0, import_firestore53.query)((0, import_firestore53.collectionGroup)(this.db, PRODUCTS_COLLECTION), ...constraints);
|
|
17674
17543
|
const snapshot = await (0, import_firestore53.getDocs)(q);
|
|
17675
17544
|
const products = snapshot.docs.map(
|
|
17676
17545
|
(doc38) => ({
|
|
@@ -17696,10 +17565,7 @@ var ProductService = class extends BaseService {
|
|
|
17696
17565
|
if (technologyId) {
|
|
17697
17566
|
constraints.push((0, import_firestore53.where)("technologyId", "==", technologyId));
|
|
17698
17567
|
}
|
|
17699
|
-
const q = (0, import_firestore53.query)(
|
|
17700
|
-
(0, import_firestore53.collectionGroup)(this.db, PRODUCTS_COLLECTION),
|
|
17701
|
-
...constraints
|
|
17702
|
-
);
|
|
17568
|
+
const q = (0, import_firestore53.query)((0, import_firestore53.collectionGroup)(this.db, PRODUCTS_COLLECTION), ...constraints);
|
|
17703
17569
|
const snapshot = await (0, import_firestore53.getCountFromServer)(q);
|
|
17704
17570
|
return snapshot.data().count;
|
|
17705
17571
|
}
|
|
@@ -17708,10 +17574,7 @@ var ProductService = class extends BaseService {
|
|
|
17708
17574
|
* This uses a single collectionGroup query for efficiency.
|
|
17709
17575
|
*/
|
|
17710
17576
|
async getProductCounts() {
|
|
17711
|
-
const q = (0, import_firestore53.query)(
|
|
17712
|
-
(0, import_firestore53.collectionGroup)(this.db, PRODUCTS_COLLECTION),
|
|
17713
|
-
(0, import_firestore53.where)("isActive", "==", true)
|
|
17714
|
-
);
|
|
17577
|
+
const q = (0, import_firestore53.query)((0, import_firestore53.collectionGroup)(this.db, PRODUCTS_COLLECTION), (0, import_firestore53.where)("isActive", "==", true));
|
|
17715
17578
|
const snapshot = await (0, import_firestore53.getDocs)(q);
|
|
17716
17579
|
const counts = {
|
|
17717
17580
|
byCategory: {},
|
|
@@ -17736,6 +17599,23 @@ var ProductService = class extends BaseService {
|
|
|
17736
17599
|
});
|
|
17737
17600
|
return counts;
|
|
17738
17601
|
}
|
|
17602
|
+
/**
|
|
17603
|
+
* Gets all products for a specific technology (non-paginated, for filters/dropdowns)
|
|
17604
|
+
*/
|
|
17605
|
+
async getAllByTechnology(technologyId) {
|
|
17606
|
+
const q = (0, import_firestore53.query)(
|
|
17607
|
+
this.getProductsRef(technologyId),
|
|
17608
|
+
(0, import_firestore53.where)("isActive", "==", true),
|
|
17609
|
+
(0, import_firestore53.orderBy)("name")
|
|
17610
|
+
);
|
|
17611
|
+
const snapshot = await (0, import_firestore53.getDocs)(q);
|
|
17612
|
+
return snapshot.docs.map(
|
|
17613
|
+
(doc38) => ({
|
|
17614
|
+
id: doc38.id,
|
|
17615
|
+
...doc38.data()
|
|
17616
|
+
})
|
|
17617
|
+
);
|
|
17618
|
+
}
|
|
17739
17619
|
/**
|
|
17740
17620
|
* Gets all products for a brand by filtering through all technologies
|
|
17741
17621
|
*/
|