@blackcode_sa/metaestetics-api 1.5.31 → 1.5.32

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@blackcode_sa/metaestetics-api",
3
3
  "private": false,
4
- "version": "1.5.31",
4
+ "version": "1.5.32",
5
5
  "description": "Firebase authentication service with anonymous upgrade support",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.mjs",
package/src/index.ts CHANGED
@@ -26,6 +26,7 @@ export {
26
26
  } from "./services/documentation-templates";
27
27
  export { CalendarServiceV2 } from "./services/calendar/calendar-refactored.service";
28
28
  export { SyncedCalendarsService } from "./services/calendar/synced-calendars.service";
29
+ export { ReviewService } from "./services/reviews/reviews.service";
29
30
 
30
31
  // Backoffice services
31
32
  export { BrandService } from "./backoffice/services/brand.service";
@@ -259,6 +260,10 @@ export {
259
260
  export { Contraindication } from "./backoffice/types/static/contraindication.types";
260
261
  export { ProcedureFamily } from "./backoffice/types/static/procedure-family.types";
261
262
  export { TreatmentBenefit } from "./backoffice/types/static/treatment-benefit.types";
263
+ export {
264
+ RequirementType,
265
+ TimeUnit,
266
+ } from "./backoffice/types/requirement.types";
262
267
 
263
268
  // Documentation Templates types
264
269
  export type {
@@ -426,6 +426,12 @@ export class ClinicService extends BaseService {
426
426
  );
427
427
  }
428
428
 
429
+ /**
430
+ * Get clinics based on multiple filtering criteria
431
+ *
432
+ * @param filters - Various filters to apply
433
+ * @returns Filtered clinics and the last document for pagination
434
+ */
429
435
  async getClinicsByFilters(filters: {
430
436
  center?: { latitude: number; longitude: number };
431
437
  radiusInKm?: number;
@@ -95,7 +95,7 @@ export async function getClinicsByFilters(
95
95
  }
96
96
 
97
97
  // Add ordering to make pagination consistent
98
- constraints.push(orderBy(documentId()));
98
+ constraints.push(orderBy("location.geohash"));
99
99
 
100
100
  let clinicsResult: (Clinic & { distance?: number })[] = [];
101
101
  let lastVisibleDoc = null;
@@ -227,6 +227,32 @@ export async function getClinicsByFilters(
227
227
  // Apply filters that couldn't be applied in the query
228
228
  let filteredClinics = clinics;
229
229
 
230
+ // Calculate distance for each clinic if center coordinates are provided
231
+ if (filters.center) {
232
+ const center = filters.center;
233
+ const clinicsWithDistance: (Clinic & { distance: number })[] = [];
234
+
235
+ filteredClinics.forEach((clinic) => {
236
+ const distance = distanceBetween(
237
+ [center.latitude, center.longitude],
238
+ [clinic.location.latitude, clinic.location.longitude]
239
+ );
240
+
241
+ clinicsWithDistance.push({
242
+ ...clinic,
243
+ distance: distance / 1000, // Convert to kilometers
244
+ });
245
+ });
246
+
247
+ // Replace filtered clinics with the version that includes distances
248
+ filteredClinics = clinicsWithDistance;
249
+
250
+ // Sort by distance - use type assertion to fix type error
251
+ (filteredClinics as (Clinic & { distance: number })[]).sort(
252
+ (a, b) => a.distance - b.distance
253
+ );
254
+ }
255
+
230
256
  // Filter by multiple tags if more than one tag was specified
231
257
  if (filters.tags && filters.tags.length > 1) {
232
258
  filteredClinics = filteredClinics.filter((clinic) => {
@@ -612,7 +612,7 @@ export class ProcedureService extends BaseService {
612
612
  }
613
613
 
614
614
  // Add ordering to make pagination consistent
615
- constraints.push(orderBy(documentId()));
615
+ constraints.push(orderBy("clinicInfo.location.geohash"));
616
616
 
617
617
  // Add pagination if specified
618
618
  if (filters.pagination && filters.pagination > 0 && filters.lastDoc) {
@@ -743,16 +743,54 @@ export class ProcedureService extends BaseService {
743
743
  return { ...doc.data(), id: doc.id } as Procedure;
744
744
  });
745
745
 
746
- // Apply filters that couldn't be applied in the query
747
- let filteredProcedures = this.applyInMemoryFilters(procedures, filters);
746
+ // Calculate distance for each procedure if location is provided
747
+ if (filters.location) {
748
+ const center = filters.location;
749
+ const proceduresWithDistance: (Procedure & { distance: number })[] =
750
+ [];
751
+
752
+ procedures.forEach((procedure) => {
753
+ const distance = distanceBetween(
754
+ [center.latitude, center.longitude],
755
+ [
756
+ procedure.clinicInfo.location.latitude,
757
+ procedure.clinicInfo.location.longitude,
758
+ ]
759
+ );
760
+
761
+ proceduresWithDistance.push({
762
+ ...procedure,
763
+ distance: distance / 1000, // Convert to kilometers
764
+ });
765
+ });
766
+
767
+ // Replace procedures with version that includes distances
768
+ let filteredProcedures = proceduresWithDistance;
769
+
770
+ // Apply in-memory filters
771
+ filteredProcedures = this.applyInMemoryFilters(
772
+ filteredProcedures,
773
+ filters
774
+ );
775
+
776
+ // Sort by distance
777
+ filteredProcedures.sort((a, b) => a.distance - b.distance);
778
+
779
+ proceduresResult = filteredProcedures;
780
+ } else {
781
+ // Apply filters that couldn't be applied in the query
782
+ let filteredProcedures = this.applyInMemoryFilters(
783
+ procedures,
784
+ filters
785
+ );
786
+ proceduresResult = filteredProcedures;
787
+ }
748
788
 
749
789
  // Set last document for pagination
750
790
  lastVisibleDoc =
751
791
  querySnapshot.docs.length > 0
752
792
  ? querySnapshot.docs[querySnapshot.docs.length - 1]
753
793
  : null;
754
-
755
- proceduresResult = filteredProcedures;
756
794
  }
757
795
 
758
796
  return {