@blackcode_sa/metaestetics-api 1.13.15 → 1.13.17

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.d.mts CHANGED
@@ -7609,6 +7609,15 @@ declare class AppointmentService extends BaseService {
7609
7609
  * @returns The updated appointment
7610
7610
  */
7611
7611
  addAfterPhotoToEntry(appointmentId: string, zoneId: string, photoIndex: number, afterPhotoUrl: MediaResource, afterNote?: string): Promise<Appointment>;
7612
+ /**
7613
+ * Removes an after photo from an existing entry (keeps the before photo)
7614
+ *
7615
+ * @param appointmentId ID of the appointment
7616
+ * @param zoneId ID of the zone
7617
+ * @param photoIndex Index of the entry to remove after photo from
7618
+ * @returns The updated appointment
7619
+ */
7620
+ removeAfterPhotoFromEntry(appointmentId: string, zoneId: string, photoIndex: number): Promise<Appointment>;
7612
7621
  /**
7613
7622
  * Updates notes for a photo entry
7614
7623
  *
package/dist/index.d.ts CHANGED
@@ -7609,6 +7609,15 @@ declare class AppointmentService extends BaseService {
7609
7609
  * @returns The updated appointment
7610
7610
  */
7611
7611
  addAfterPhotoToEntry(appointmentId: string, zoneId: string, photoIndex: number, afterPhotoUrl: MediaResource, afterNote?: string): Promise<Appointment>;
7612
+ /**
7613
+ * Removes an after photo from an existing entry (keeps the before photo)
7614
+ *
7615
+ * @param appointmentId ID of the appointment
7616
+ * @param zoneId ID of the zone
7617
+ * @param photoIndex Index of the entry to remove after photo from
7618
+ * @returns The updated appointment
7619
+ */
7620
+ removeAfterPhotoFromEntry(appointmentId: string, zoneId: string, photoIndex: number): Promise<Appointment>;
7612
7621
  /**
7613
7622
  * Updates notes for a photo entry
7614
7623
  *
package/dist/index.js CHANGED
@@ -5328,6 +5328,12 @@ async function updateZonePhotoNotesUtil(db, appointmentId, zoneId, photoIndex, b
5328
5328
  }
5329
5329
  return updateZonePhotoEntryUtil(db, appointmentId, zoneId, photoIndex, updates);
5330
5330
  }
5331
+ async function removeAfterPhotoFromEntryUtil(db, appointmentId, zoneId, photoIndex) {
5332
+ return updateZonePhotoEntryUtil(db, appointmentId, zoneId, photoIndex, {
5333
+ after: null,
5334
+ afterNote: null
5335
+ });
5336
+ }
5331
5337
  async function getZonePhotoEntryUtil(db, appointmentId, zoneId, photoIndex) {
5332
5338
  var _a;
5333
5339
  const appointment = await getAppointmentOrThrow(db, appointmentId);
@@ -6767,6 +6773,30 @@ var AppointmentService = class extends BaseService {
6767
6773
  throw error;
6768
6774
  }
6769
6775
  }
6776
+ /**
6777
+ * Removes an after photo from an existing entry (keeps the before photo)
6778
+ *
6779
+ * @param appointmentId ID of the appointment
6780
+ * @param zoneId ID of the zone
6781
+ * @param photoIndex Index of the entry to remove after photo from
6782
+ * @returns The updated appointment
6783
+ */
6784
+ async removeAfterPhotoFromEntry(appointmentId, zoneId, photoIndex) {
6785
+ try {
6786
+ console.log(
6787
+ `[APPOINTMENT_SERVICE] Removing after photo from entry at index ${photoIndex} for zone ${zoneId}`
6788
+ );
6789
+ return await removeAfterPhotoFromEntryUtil(
6790
+ this.db,
6791
+ appointmentId,
6792
+ zoneId,
6793
+ photoIndex
6794
+ );
6795
+ } catch (error) {
6796
+ console.error(`[APPOINTMENT_SERVICE] Error removing after photo from entry:`, error);
6797
+ throw error;
6798
+ }
6799
+ }
6770
6800
  /**
6771
6801
  * Updates notes for a photo entry
6772
6802
  *
@@ -21125,7 +21155,6 @@ var ProcedureService = class extends BaseService {
21125
21155
  proceduresQuery = (0, import_firestore58.query)(proceduresCollection, (0, import_firestore58.orderBy)("name"));
21126
21156
  }
21127
21157
  const proceduresSnapshot = await (0, import_firestore58.getDocs)(proceduresQuery);
21128
- const lastVisible = proceduresSnapshot.docs[proceduresSnapshot.docs.length - 1];
21129
21158
  let procedures = proceduresSnapshot.docs.map((doc47) => {
21130
21159
  const data = doc47.data();
21131
21160
  return {
@@ -21137,9 +21166,10 @@ var ProcedureService = class extends BaseService {
21137
21166
  if (excludeDraftPractitioners) {
21138
21167
  procedures = await this.filterDraftPractitionerProcedures(procedures);
21139
21168
  }
21169
+ const lastDocForPagination = pagination && pagination > 0 && proceduresSnapshot.docs.length < pagination ? null : proceduresSnapshot.docs.length > 0 ? proceduresSnapshot.docs[proceduresSnapshot.docs.length - 1] : null;
21140
21170
  return {
21141
21171
  procedures,
21142
- lastDoc: lastVisible
21172
+ lastDoc: lastDocForPagination
21143
21173
  };
21144
21174
  } catch (error) {
21145
21175
  console.error("[PROCEDURE_SERVICE] Error getting all procedures:", error);
@@ -21265,11 +21295,11 @@ var ProcedureService = class extends BaseService {
21265
21295
  if (filters.excludeDraftPractitioners) {
21266
21296
  procedures = await this.filterDraftPractitionerProcedures(procedures);
21267
21297
  }
21268
- const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
21269
- console.log(`[PROCEDURE_SERVICE] Strategy 1 success: ${procedures.length} procedures`);
21298
+ console.log(`[PROCEDURE_SERVICE] Strategy 1 success: ${procedures.length} procedures (${querySnapshot.docs.length} from query)`);
21270
21299
  if (querySnapshot.docs.length < (filters.pagination || 10)) {
21271
21300
  return { procedures, lastDoc: null };
21272
21301
  }
21302
+ const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
21273
21303
  return { procedures, lastDoc };
21274
21304
  } catch (error) {
21275
21305
  console.log("[PROCEDURE_SERVICE] Strategy 1 failed:", error);
@@ -21308,11 +21338,11 @@ var ProcedureService = class extends BaseService {
21308
21338
  if (filters.excludeDraftPractitioners) {
21309
21339
  procedures = await this.filterDraftPractitionerProcedures(procedures);
21310
21340
  }
21311
- const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
21312
- console.log(`[PROCEDURE_SERVICE] Strategy 2 success: ${procedures.length} procedures`);
21313
- if (procedures.length < (filters.pagination || 10)) {
21341
+ console.log(`[PROCEDURE_SERVICE] Strategy 2 success: ${procedures.length} procedures (${querySnapshot.docs.length} from query)`);
21342
+ if (querySnapshot.docs.length < (filters.pagination || 10)) {
21314
21343
  return { procedures, lastDoc: null };
21315
21344
  }
21345
+ const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
21316
21346
  return { procedures, lastDoc };
21317
21347
  } catch (error) {
21318
21348
  console.log("[PROCEDURE_SERVICE] Strategy 2 failed:", error);
@@ -21392,13 +21422,14 @@ var ProcedureService = class extends BaseService {
21392
21422
  procedures = await this.filterDraftPractitionerProcedures(procedures);
21393
21423
  }
21394
21424
  console.log("[PROCEDURE_SERVICE] After applyInMemoryFilters (Strategy 3):", {
21395
- procedureCount: procedures.length
21425
+ procedureCount: procedures.length,
21426
+ queryDocCount: querySnapshot.docs.length
21396
21427
  });
21397
- const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
21398
- console.log(`[PROCEDURE_SERVICE] Strategy 3 success: ${procedures.length} procedures`);
21399
- if (procedures.length < (filters.pagination || 10)) {
21428
+ console.log(`[PROCEDURE_SERVICE] Strategy 3 success: ${procedures.length} procedures (${querySnapshot.docs.length} from query)`);
21429
+ if (querySnapshot.docs.length < (filters.pagination || 10)) {
21400
21430
  return { procedures, lastDoc: null };
21401
21431
  }
21432
+ const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
21402
21433
  return { procedures, lastDoc };
21403
21434
  } catch (error) {
21404
21435
  console.log("[PROCEDURE_SERVICE] Strategy 3 failed:", error);
@@ -21425,11 +21456,11 @@ var ProcedureService = class extends BaseService {
21425
21456
  if (filters.excludeDraftPractitioners) {
21426
21457
  procedures = await this.filterDraftPractitionerProcedures(procedures);
21427
21458
  }
21428
- const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
21429
- console.log(`[PROCEDURE_SERVICE] Strategy 4 success: ${procedures.length} procedures`);
21430
- if (procedures.length < (filters.pagination || 10)) {
21459
+ console.log(`[PROCEDURE_SERVICE] Strategy 4 success: ${procedures.length} procedures (${querySnapshot.docs.length} from query)`);
21460
+ if (querySnapshot.docs.length < (filters.pagination || 10)) {
21431
21461
  return { procedures, lastDoc: null };
21432
21462
  }
21463
+ const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
21433
21464
  return { procedures, lastDoc };
21434
21465
  } catch (error) {
21435
21466
  console.log("[PROCEDURE_SERVICE] Strategy 4 failed:", error);
package/dist/index.mjs CHANGED
@@ -5215,6 +5215,12 @@ async function updateZonePhotoNotesUtil(db, appointmentId, zoneId, photoIndex, b
5215
5215
  }
5216
5216
  return updateZonePhotoEntryUtil(db, appointmentId, zoneId, photoIndex, updates);
5217
5217
  }
5218
+ async function removeAfterPhotoFromEntryUtil(db, appointmentId, zoneId, photoIndex) {
5219
+ return updateZonePhotoEntryUtil(db, appointmentId, zoneId, photoIndex, {
5220
+ after: null,
5221
+ afterNote: null
5222
+ });
5223
+ }
5218
5224
  async function getZonePhotoEntryUtil(db, appointmentId, zoneId, photoIndex) {
5219
5225
  var _a;
5220
5226
  const appointment = await getAppointmentOrThrow(db, appointmentId);
@@ -6654,6 +6660,30 @@ var AppointmentService = class extends BaseService {
6654
6660
  throw error;
6655
6661
  }
6656
6662
  }
6663
+ /**
6664
+ * Removes an after photo from an existing entry (keeps the before photo)
6665
+ *
6666
+ * @param appointmentId ID of the appointment
6667
+ * @param zoneId ID of the zone
6668
+ * @param photoIndex Index of the entry to remove after photo from
6669
+ * @returns The updated appointment
6670
+ */
6671
+ async removeAfterPhotoFromEntry(appointmentId, zoneId, photoIndex) {
6672
+ try {
6673
+ console.log(
6674
+ `[APPOINTMENT_SERVICE] Removing after photo from entry at index ${photoIndex} for zone ${zoneId}`
6675
+ );
6676
+ return await removeAfterPhotoFromEntryUtil(
6677
+ this.db,
6678
+ appointmentId,
6679
+ zoneId,
6680
+ photoIndex
6681
+ );
6682
+ } catch (error) {
6683
+ console.error(`[APPOINTMENT_SERVICE] Error removing after photo from entry:`, error);
6684
+ throw error;
6685
+ }
6686
+ }
6657
6687
  /**
6658
6688
  * Updates notes for a photo entry
6659
6689
  *
@@ -21361,7 +21391,6 @@ var ProcedureService = class extends BaseService {
21361
21391
  proceduresQuery = query33(proceduresCollection, orderBy18("name"));
21362
21392
  }
21363
21393
  const proceduresSnapshot = await getDocs33(proceduresQuery);
21364
- const lastVisible = proceduresSnapshot.docs[proceduresSnapshot.docs.length - 1];
21365
21394
  let procedures = proceduresSnapshot.docs.map((doc47) => {
21366
21395
  const data = doc47.data();
21367
21396
  return {
@@ -21373,9 +21402,10 @@ var ProcedureService = class extends BaseService {
21373
21402
  if (excludeDraftPractitioners) {
21374
21403
  procedures = await this.filterDraftPractitionerProcedures(procedures);
21375
21404
  }
21405
+ const lastDocForPagination = pagination && pagination > 0 && proceduresSnapshot.docs.length < pagination ? null : proceduresSnapshot.docs.length > 0 ? proceduresSnapshot.docs[proceduresSnapshot.docs.length - 1] : null;
21376
21406
  return {
21377
21407
  procedures,
21378
- lastDoc: lastVisible
21408
+ lastDoc: lastDocForPagination
21379
21409
  };
21380
21410
  } catch (error) {
21381
21411
  console.error("[PROCEDURE_SERVICE] Error getting all procedures:", error);
@@ -21501,11 +21531,11 @@ var ProcedureService = class extends BaseService {
21501
21531
  if (filters.excludeDraftPractitioners) {
21502
21532
  procedures = await this.filterDraftPractitionerProcedures(procedures);
21503
21533
  }
21504
- const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
21505
- console.log(`[PROCEDURE_SERVICE] Strategy 1 success: ${procedures.length} procedures`);
21534
+ console.log(`[PROCEDURE_SERVICE] Strategy 1 success: ${procedures.length} procedures (${querySnapshot.docs.length} from query)`);
21506
21535
  if (querySnapshot.docs.length < (filters.pagination || 10)) {
21507
21536
  return { procedures, lastDoc: null };
21508
21537
  }
21538
+ const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
21509
21539
  return { procedures, lastDoc };
21510
21540
  } catch (error) {
21511
21541
  console.log("[PROCEDURE_SERVICE] Strategy 1 failed:", error);
@@ -21544,11 +21574,11 @@ var ProcedureService = class extends BaseService {
21544
21574
  if (filters.excludeDraftPractitioners) {
21545
21575
  procedures = await this.filterDraftPractitionerProcedures(procedures);
21546
21576
  }
21547
- const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
21548
- console.log(`[PROCEDURE_SERVICE] Strategy 2 success: ${procedures.length} procedures`);
21549
- if (procedures.length < (filters.pagination || 10)) {
21577
+ console.log(`[PROCEDURE_SERVICE] Strategy 2 success: ${procedures.length} procedures (${querySnapshot.docs.length} from query)`);
21578
+ if (querySnapshot.docs.length < (filters.pagination || 10)) {
21550
21579
  return { procedures, lastDoc: null };
21551
21580
  }
21581
+ const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
21552
21582
  return { procedures, lastDoc };
21553
21583
  } catch (error) {
21554
21584
  console.log("[PROCEDURE_SERVICE] Strategy 2 failed:", error);
@@ -21628,13 +21658,14 @@ var ProcedureService = class extends BaseService {
21628
21658
  procedures = await this.filterDraftPractitionerProcedures(procedures);
21629
21659
  }
21630
21660
  console.log("[PROCEDURE_SERVICE] After applyInMemoryFilters (Strategy 3):", {
21631
- procedureCount: procedures.length
21661
+ procedureCount: procedures.length,
21662
+ queryDocCount: querySnapshot.docs.length
21632
21663
  });
21633
- const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
21634
- console.log(`[PROCEDURE_SERVICE] Strategy 3 success: ${procedures.length} procedures`);
21635
- if (procedures.length < (filters.pagination || 10)) {
21664
+ console.log(`[PROCEDURE_SERVICE] Strategy 3 success: ${procedures.length} procedures (${querySnapshot.docs.length} from query)`);
21665
+ if (querySnapshot.docs.length < (filters.pagination || 10)) {
21636
21666
  return { procedures, lastDoc: null };
21637
21667
  }
21668
+ const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
21638
21669
  return { procedures, lastDoc };
21639
21670
  } catch (error) {
21640
21671
  console.log("[PROCEDURE_SERVICE] Strategy 3 failed:", error);
@@ -21661,11 +21692,11 @@ var ProcedureService = class extends BaseService {
21661
21692
  if (filters.excludeDraftPractitioners) {
21662
21693
  procedures = await this.filterDraftPractitionerProcedures(procedures);
21663
21694
  }
21664
- const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
21665
- console.log(`[PROCEDURE_SERVICE] Strategy 4 success: ${procedures.length} procedures`);
21666
- if (procedures.length < (filters.pagination || 10)) {
21695
+ console.log(`[PROCEDURE_SERVICE] Strategy 4 success: ${procedures.length} procedures (${querySnapshot.docs.length} from query)`);
21696
+ if (querySnapshot.docs.length < (filters.pagination || 10)) {
21667
21697
  return { procedures, lastDoc: null };
21668
21698
  }
21699
+ const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
21669
21700
  return { procedures, lastDoc };
21670
21701
  } catch (error) {
21671
21702
  console.log("[PROCEDURE_SERVICE] Strategy 4 failed:", error);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@blackcode_sa/metaestetics-api",
3
3
  "private": false,
4
- "version": "1.13.15",
4
+ "version": "1.13.17",
5
5
  "description": "Firebase authentication service with anonymous upgrade support",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",
@@ -89,6 +89,7 @@ import {
89
89
  import {
90
90
  updateZonePhotoEntryUtil,
91
91
  addAfterPhotoToEntryUtil,
92
+ removeAfterPhotoFromEntryUtil,
92
93
  updateZonePhotoNotesUtil,
93
94
  getZonePhotoEntryUtil,
94
95
  } from './utils/zone-photo.utils';
@@ -2034,6 +2035,35 @@ export class AppointmentService extends BaseService {
2034
2035
  }
2035
2036
  }
2036
2037
 
2038
+ /**
2039
+ * Removes an after photo from an existing entry (keeps the before photo)
2040
+ *
2041
+ * @param appointmentId ID of the appointment
2042
+ * @param zoneId ID of the zone
2043
+ * @param photoIndex Index of the entry to remove after photo from
2044
+ * @returns The updated appointment
2045
+ */
2046
+ async removeAfterPhotoFromEntry(
2047
+ appointmentId: string,
2048
+ zoneId: string,
2049
+ photoIndex: number,
2050
+ ): Promise<Appointment> {
2051
+ try {
2052
+ console.log(
2053
+ `[APPOINTMENT_SERVICE] Removing after photo from entry at index ${photoIndex} for zone ${zoneId}`,
2054
+ );
2055
+ return await removeAfterPhotoFromEntryUtil(
2056
+ this.db,
2057
+ appointmentId,
2058
+ zoneId,
2059
+ photoIndex,
2060
+ );
2061
+ } catch (error) {
2062
+ console.error(`[APPOINTMENT_SERVICE] Error removing after photo from entry:`, error);
2063
+ throw error;
2064
+ }
2065
+ }
2066
+
2037
2067
  /**
2038
2068
  * Updates notes for a photo entry
2039
2069
  *
@@ -116,6 +116,27 @@ export async function updateZonePhotoNotesUtil(
116
116
  return updateZonePhotoEntryUtil(db, appointmentId, zoneId, photoIndex, updates);
117
117
  }
118
118
 
119
+ /**
120
+ * Removes an after photo from an existing entry (keeps the before photo)
121
+ *
122
+ * @param db Firestore instance
123
+ * @param appointmentId Appointment ID
124
+ * @param zoneId Zone ID
125
+ * @param photoIndex Index of the entry to remove after photo from
126
+ * @returns Updated appointment
127
+ */
128
+ export async function removeAfterPhotoFromEntryUtil(
129
+ db: Firestore,
130
+ appointmentId: string,
131
+ zoneId: string,
132
+ photoIndex: number
133
+ ): Promise<Appointment> {
134
+ return updateZonePhotoEntryUtil(db, appointmentId, zoneId, photoIndex, {
135
+ after: null,
136
+ afterNote: null,
137
+ });
138
+ }
139
+
119
140
  /**
120
141
  * Gets a specific photo entry from a zone
121
142
  *
@@ -1465,7 +1465,6 @@ export class ProcedureService extends BaseService {
1465
1465
  }
1466
1466
 
1467
1467
  const proceduresSnapshot = await getDocs(proceduresQuery);
1468
- const lastVisible = proceduresSnapshot.docs[proceduresSnapshot.docs.length - 1];
1469
1468
 
1470
1469
  let procedures = proceduresSnapshot.docs.map(doc => {
1471
1470
  const data = doc.data() as Procedure;
@@ -1480,9 +1479,17 @@ export class ProcedureService extends BaseService {
1480
1479
  procedures = await this.filterDraftPractitionerProcedures(procedures);
1481
1480
  }
1482
1481
 
1482
+ // Fix lastDoc - if we got fewer documents from Firestore than requested, no more pages
1483
+ const lastDocForPagination =
1484
+ pagination && pagination > 0 && proceduresSnapshot.docs.length < pagination
1485
+ ? null
1486
+ : proceduresSnapshot.docs.length > 0
1487
+ ? proceduresSnapshot.docs[proceduresSnapshot.docs.length - 1]
1488
+ : null;
1489
+
1483
1490
  return {
1484
1491
  procedures,
1485
- lastDoc: lastVisible,
1492
+ lastDoc: lastDocForPagination,
1486
1493
  };
1487
1494
  } catch (error) {
1488
1495
  console.error('[PROCEDURE_SERVICE] Error getting all procedures:', error);
@@ -1657,17 +1664,20 @@ export class ProcedureService extends BaseService {
1657
1664
  procedures = await this.filterDraftPractitionerProcedures(procedures);
1658
1665
  }
1659
1666
 
1660
- const lastDoc =
1661
- querySnapshot.docs.length > 0
1662
- ? querySnapshot.docs[querySnapshot.docs.length - 1]
1663
- : null;
1667
+ console.log(`[PROCEDURE_SERVICE] Strategy 1 success: ${procedures.length} procedures (${querySnapshot.docs.length} from query)`);
1664
1668
 
1665
- console.log(`[PROCEDURE_SERVICE] Strategy 1 success: ${procedures.length} procedures`);
1666
-
1667
- // Fix Load More - ako je broj rezultata manji od pagination, nema više
1669
+ // Fix Load More - if we got fewer documents from Firestore than requested, no more pages
1668
1670
  if (querySnapshot.docs.length < (filters.pagination || 10)) {
1669
1671
  return { procedures, lastDoc: null };
1670
1672
  }
1673
+
1674
+ // If we filtered out some procedures but got full query results, use last doc for pagination
1675
+ // This allows fetching more pages to get enough filtered results
1676
+ const lastDoc =
1677
+ querySnapshot.docs.length > 0
1678
+ ? querySnapshot.docs[querySnapshot.docs.length - 1]
1679
+ : null;
1680
+
1671
1681
  return { procedures, lastDoc };
1672
1682
  } catch (error) {
1673
1683
  console.log('[PROCEDURE_SERVICE] Strategy 1 failed:', error);
@@ -1719,17 +1729,19 @@ export class ProcedureService extends BaseService {
1719
1729
  procedures = await this.filterDraftPractitionerProcedures(procedures);
1720
1730
  }
1721
1731
 
1732
+ console.log(`[PROCEDURE_SERVICE] Strategy 2 success: ${procedures.length} procedures (${querySnapshot.docs.length} from query)`);
1733
+
1734
+ // Fix Load More - if we got fewer documents from Firestore than requested, no more pages
1735
+ if (querySnapshot.docs.length < (filters.pagination || 10)) {
1736
+ return { procedures, lastDoc: null };
1737
+ }
1738
+
1739
+ // If we filtered out some procedures but got full query results, use last doc for pagination
1722
1740
  const lastDoc =
1723
1741
  querySnapshot.docs.length > 0
1724
1742
  ? querySnapshot.docs[querySnapshot.docs.length - 1]
1725
1743
  : null;
1726
-
1727
- console.log(`[PROCEDURE_SERVICE] Strategy 2 success: ${procedures.length} procedures`);
1728
-
1729
- // Fix Load More - ako je broj rezultata manji od pagination, nema više
1730
- if (procedures.length < (filters.pagination || 10)) {
1731
- return { procedures, lastDoc: null };
1732
- }
1744
+
1733
1745
  return { procedures, lastDoc };
1734
1746
  } catch (error) {
1735
1747
  console.log('[PROCEDURE_SERVICE] Strategy 2 failed:', error);
@@ -1836,16 +1848,20 @@ export class ProcedureService extends BaseService {
1836
1848
 
1837
1849
  console.log('[PROCEDURE_SERVICE] After applyInMemoryFilters (Strategy 3):', {
1838
1850
  procedureCount: procedures.length,
1851
+ queryDocCount: querySnapshot.docs.length,
1839
1852
  });
1840
1853
 
1841
- const lastDoc =
1842
- querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
1843
- console.log(`[PROCEDURE_SERVICE] Strategy 3 success: ${procedures.length} procedures`);
1854
+ console.log(`[PROCEDURE_SERVICE] Strategy 3 success: ${procedures.length} procedures (${querySnapshot.docs.length} from query)`);
1844
1855
 
1845
- // Fix Load More - ako je broj rezultata manji od pagination, nema više
1846
- if (procedures.length < (filters.pagination || 10)) {
1856
+ // Fix Load More - if we got fewer documents from Firestore than requested, no more pages
1857
+ if (querySnapshot.docs.length < (filters.pagination || 10)) {
1847
1858
  return { procedures, lastDoc: null };
1848
1859
  }
1860
+
1861
+ // If we filtered out some procedures but got full query results, use last doc for pagination
1862
+ const lastDoc =
1863
+ querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
1864
+
1849
1865
  return { procedures, lastDoc };
1850
1866
  } catch (error) {
1851
1867
  console.log('[PROCEDURE_SERVICE] Strategy 3 failed:', error);
@@ -1880,14 +1896,17 @@ export class ProcedureService extends BaseService {
1880
1896
  procedures = await this.filterDraftPractitionerProcedures(procedures);
1881
1897
  }
1882
1898
 
1883
- const lastDoc =
1884
- querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
1885
- console.log(`[PROCEDURE_SERVICE] Strategy 4 success: ${procedures.length} procedures`);
1899
+ console.log(`[PROCEDURE_SERVICE] Strategy 4 success: ${procedures.length} procedures (${querySnapshot.docs.length} from query)`);
1886
1900
 
1887
- // Fix Load More - ako je broj rezultata manji od pagination, nema više
1888
- if (procedures.length < (filters.pagination || 10)) {
1901
+ // Fix Load More - if we got fewer documents from Firestore than requested, no more pages
1902
+ if (querySnapshot.docs.length < (filters.pagination || 10)) {
1889
1903
  return { procedures, lastDoc: null };
1890
1904
  }
1905
+
1906
+ // If we filtered out some procedures but got full query results, use last doc for pagination
1907
+ const lastDoc =
1908
+ querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
1909
+
1891
1910
  return { procedures, lastDoc };
1892
1911
  } catch (error) {
1893
1912
  console.log('[PROCEDURE_SERVICE] Strategy 4 failed:', error);