@blackcode_sa/metaestetics-api 1.14.23 → 1.14.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -7696,58 +7696,17 @@ var import_firestore29 = require("firebase/firestore");
7696
7696
  var import_firestore30 = require("firebase/firestore");
7697
7697
 
7698
7698
  // src/services/patient/utils/clinic.utils.ts
7699
- var import_firestore15 = require("firebase/firestore");
7700
- var getPatientsByClinicUtil = async (db, clinicId, options) => {
7701
- try {
7702
- console.log(
7703
- `[getPatientsByClinicUtil] Fetching patients for clinic ID: ${clinicId} with options:`,
7704
- options
7705
- );
7706
- const patientsCollection = (0, import_firestore15.collection)(db, PATIENTS_COLLECTION);
7707
- const constraints = [
7708
- (0, import_firestore15.where)("clinicIds", "array-contains", clinicId)
7709
- ];
7710
- let q = (0, import_firestore15.query)(patientsCollection, ...constraints);
7711
- if (options == null ? void 0 : options.limit) {
7712
- q = (0, import_firestore15.query)(q, (0, import_firestore15.limit)(options.limit));
7713
- }
7714
- if (options == null ? void 0 : options.startAfter) {
7715
- const startAfterDoc = await (0, import_firestore15.getDoc)(
7716
- (0, import_firestore15.doc)(db, PATIENTS_COLLECTION, options.startAfter)
7717
- );
7718
- if (startAfterDoc.exists()) {
7719
- q = (0, import_firestore15.query)(q, (0, import_firestore15.startAfter)(startAfterDoc));
7720
- }
7721
- }
7722
- const patientsSnapshot = await (0, import_firestore15.getDocs)(q);
7723
- const patients = [];
7724
- patientsSnapshot.forEach((doc47) => {
7725
- patients.push(doc47.data());
7726
- });
7727
- console.log(
7728
- `[getPatientsByClinicUtil] Found ${patients.length} patients for clinic ID: ${clinicId}`
7729
- );
7730
- return patients;
7731
- } catch (error) {
7732
- console.error(
7733
- `[getPatientsByClinicUtil] Error fetching patients for clinic:`,
7734
- error
7735
- );
7736
- throw new Error(
7737
- `Failed to retrieve patients for clinic: ${error instanceof Error ? error.message : String(error)}`
7738
- );
7739
- }
7740
- };
7699
+ var import_firestore22 = require("firebase/firestore");
7741
7700
 
7742
7701
  // src/services/patient/utils/docs.utils.ts
7743
- var import_firestore22 = require("firebase/firestore");
7702
+ var import_firestore21 = require("firebase/firestore");
7744
7703
 
7745
7704
  // src/services/patient/utils/sensitive.utils.ts
7746
- var import_firestore21 = require("firebase/firestore");
7705
+ var import_firestore20 = require("firebase/firestore");
7747
7706
 
7748
7707
  // src/validations/patient.schema.ts
7749
7708
  var import_zod7 = require("zod");
7750
- var import_firestore17 = require("firebase/firestore");
7709
+ var import_firestore16 = require("firebase/firestore");
7751
7710
 
7752
7711
  // src/validations/patient/medical-info.schema.ts
7753
7712
  var import_zod6 = require("zod");
@@ -7774,23 +7733,23 @@ var BlockingCondition = /* @__PURE__ */ ((BlockingCondition2) => {
7774
7733
 
7775
7734
  // src/validations/common.schema.ts
7776
7735
  var import_zod5 = require("zod");
7777
- var import_firestore16 = require("firebase/firestore");
7736
+ var import_firestore15 = require("firebase/firestore");
7778
7737
  var timestampSchema = import_zod5.z.union([
7779
7738
  import_zod5.z.object({
7780
7739
  seconds: import_zod5.z.number(),
7781
7740
  nanoseconds: import_zod5.z.number()
7782
7741
  }),
7783
- import_zod5.z.instanceof(import_firestore16.Timestamp),
7742
+ import_zod5.z.instanceof(import_firestore15.Timestamp),
7784
7743
  import_zod5.z.instanceof(Date)
7785
7744
  // Add support for Date objects that Firestore returns on client
7786
7745
  ]).transform((data) => {
7787
- if (data instanceof import_firestore16.Timestamp) {
7746
+ if (data instanceof import_firestore15.Timestamp) {
7788
7747
  return data;
7789
7748
  }
7790
7749
  if (data instanceof Date) {
7791
- return import_firestore16.Timestamp.fromDate(data);
7750
+ return import_firestore15.Timestamp.fromDate(data);
7792
7751
  }
7793
- return new import_firestore16.Timestamp(data.seconds, data.nanoseconds);
7752
+ return new import_firestore15.Timestamp(data.seconds, data.nanoseconds);
7794
7753
  });
7795
7754
 
7796
7755
  // src/validations/patient/medical-info.schema.ts
@@ -7946,8 +7905,8 @@ var patientLocationInfoSchema = import_zod7.z.object({
7946
7905
  patientId: import_zod7.z.string(),
7947
7906
  userRef: import_zod7.z.string().optional(),
7948
7907
  locationData: locationDataSchema,
7949
- createdAt: import_zod7.z.instanceof(import_firestore17.Timestamp),
7950
- updatedAt: import_zod7.z.instanceof(import_firestore17.Timestamp)
7908
+ createdAt: import_zod7.z.instanceof(import_firestore16.Timestamp),
7909
+ updatedAt: import_zod7.z.instanceof(import_firestore16.Timestamp)
7951
7910
  });
7952
7911
  var createPatientLocationInfoSchema = import_zod7.z.object({
7953
7912
  patientId: import_zod7.z.string(),
@@ -7960,26 +7919,26 @@ var patientSensitiveInfoSchema = import_zod7.z.object({
7960
7919
  photoUrl: import_zod7.z.string().nullable().optional(),
7961
7920
  firstName: import_zod7.z.string().min(2),
7962
7921
  lastName: import_zod7.z.string().min(2),
7963
- dateOfBirth: import_zod7.z.instanceof(import_firestore17.Timestamp).nullable(),
7922
+ dateOfBirth: import_zod7.z.instanceof(import_firestore16.Timestamp).nullable(),
7964
7923
  gender: import_zod7.z.nativeEnum(Gender),
7965
7924
  email: import_zod7.z.string().email().optional(),
7966
7925
  phoneNumber: import_zod7.z.string().optional(),
7967
7926
  alternativePhoneNumber: import_zod7.z.string().optional(),
7968
7927
  addressData: addressDataSchema.optional(),
7969
7928
  emergencyContacts: import_zod7.z.array(emergencyContactSchema).optional(),
7970
- createdAt: import_zod7.z.instanceof(import_firestore17.Timestamp),
7971
- updatedAt: import_zod7.z.instanceof(import_firestore17.Timestamp)
7929
+ createdAt: import_zod7.z.instanceof(import_firestore16.Timestamp),
7930
+ updatedAt: import_zod7.z.instanceof(import_firestore16.Timestamp)
7972
7931
  });
7973
7932
  var patientDoctorSchema = import_zod7.z.object({
7974
7933
  userRef: import_zod7.z.string(),
7975
- assignedAt: import_zod7.z.instanceof(import_firestore17.Timestamp),
7934
+ assignedAt: import_zod7.z.instanceof(import_firestore16.Timestamp),
7976
7935
  assignedBy: import_zod7.z.string().optional(),
7977
7936
  isActive: import_zod7.z.boolean(),
7978
7937
  notes: import_zod7.z.string().optional()
7979
7938
  });
7980
7939
  var patientClinicSchema = import_zod7.z.object({
7981
7940
  clinicId: import_zod7.z.string(),
7982
- assignedAt: import_zod7.z.instanceof(import_firestore17.Timestamp),
7941
+ assignedAt: import_zod7.z.instanceof(import_firestore16.Timestamp),
7983
7942
  assignedBy: import_zod7.z.string().optional(),
7984
7943
  isActive: import_zod7.z.boolean(),
7985
7944
  notes: import_zod7.z.string().optional()
@@ -7995,14 +7954,14 @@ var patientProfileSchema = import_zod7.z.object({
7995
7954
  isManual: import_zod7.z.boolean().default(false),
7996
7955
  // Default to false if missing
7997
7956
  phoneNumber: import_zod7.z.string().nullable().optional(),
7998
- dateOfBirth: import_zod7.z.instanceof(import_firestore17.Timestamp).nullable().optional(),
7957
+ dateOfBirth: import_zod7.z.instanceof(import_firestore16.Timestamp).nullable().optional(),
7999
7958
  doctors: import_zod7.z.array(patientDoctorSchema),
8000
7959
  clinics: import_zod7.z.array(patientClinicSchema),
8001
7960
  doctorIds: import_zod7.z.array(import_zod7.z.string()),
8002
7961
  clinicIds: import_zod7.z.array(import_zod7.z.string()),
8003
7962
  dismissedNextStepsRecommendations: import_zod7.z.array(import_zod7.z.string()).optional(),
8004
- createdAt: import_zod7.z.instanceof(import_firestore17.Timestamp),
8005
- updatedAt: import_zod7.z.instanceof(import_firestore17.Timestamp)
7963
+ createdAt: import_zod7.z.instanceof(import_firestore16.Timestamp),
7964
+ updatedAt: import_zod7.z.instanceof(import_firestore16.Timestamp)
8006
7965
  });
8007
7966
  var createPatientProfileSchema = import_zod7.z.object({
8008
7967
  userRef: import_zod7.z.string().optional(),
@@ -8023,7 +7982,7 @@ var createPatientSensitiveInfoSchema = import_zod7.z.object({
8023
7982
  photoUrl: mediaResourceSchema.nullable().optional(),
8024
7983
  firstName: import_zod7.z.string().min(2),
8025
7984
  lastName: import_zod7.z.string().min(2),
8026
- dateOfBirth: import_zod7.z.instanceof(import_firestore17.Timestamp).nullable(),
7985
+ dateOfBirth: import_zod7.z.instanceof(import_firestore16.Timestamp).nullable(),
8027
7986
  gender: import_zod7.z.nativeEnum(Gender),
8028
7987
  email: import_zod7.z.string().email().optional(),
8029
7988
  phoneNumber: import_zod7.z.string().optional(),
@@ -8035,7 +7994,7 @@ var createManualPatientSchema = import_zod7.z.object({
8035
7994
  clinicId: import_zod7.z.string().min(1, "Clinic ID is required"),
8036
7995
  firstName: import_zod7.z.string().min(2, "First name is required"),
8037
7996
  lastName: import_zod7.z.string().min(2, "Last name is required"),
8038
- dateOfBirth: import_zod7.z.instanceof(import_firestore17.Timestamp).nullable(),
7997
+ dateOfBirth: import_zod7.z.instanceof(import_firestore16.Timestamp).nullable(),
8039
7998
  gender: import_zod7.z.nativeEnum(Gender),
8040
7999
  phoneNumber: import_zod7.z.string().optional(),
8041
8000
  email: import_zod7.z.string().email().optional(),
@@ -8074,30 +8033,30 @@ var requesterInfoSchema = import_zod7.z.object({
8074
8033
  var import_zod11 = require("zod");
8075
8034
 
8076
8035
  // src/services/patient/utils/practitioner.utils.ts
8077
- var import_firestore18 = require("firebase/firestore");
8036
+ var import_firestore17 = require("firebase/firestore");
8078
8037
  var getPatientsByPractitionerUtil = async (db, practitionerId, options) => {
8079
8038
  try {
8080
8039
  console.log(
8081
8040
  `[getPatientsByPractitionerUtil] Fetching patients for practitioner ID: ${practitionerId} with options:`,
8082
8041
  options
8083
8042
  );
8084
- const patientsCollection = (0, import_firestore18.collection)(db, PATIENTS_COLLECTION);
8043
+ const patientsCollection = (0, import_firestore17.collection)(db, PATIENTS_COLLECTION);
8085
8044
  const constraints = [
8086
- (0, import_firestore18.where)("doctorIds", "array-contains", practitionerId)
8045
+ (0, import_firestore17.where)("doctorIds", "array-contains", practitionerId)
8087
8046
  ];
8088
- let q = (0, import_firestore18.query)(patientsCollection, ...constraints);
8047
+ let q = (0, import_firestore17.query)(patientsCollection, ...constraints);
8089
8048
  if (options == null ? void 0 : options.limit) {
8090
- q = (0, import_firestore18.query)(q, (0, import_firestore18.limit)(options.limit));
8049
+ q = (0, import_firestore17.query)(q, (0, import_firestore17.limit)(options.limit));
8091
8050
  }
8092
8051
  if (options == null ? void 0 : options.startAfter) {
8093
- const startAfterDoc = await (0, import_firestore18.getDoc)(
8094
- (0, import_firestore18.doc)(db, PATIENTS_COLLECTION, options.startAfter)
8052
+ const startAfterDoc = await (0, import_firestore17.getDoc)(
8053
+ (0, import_firestore17.doc)(db, PATIENTS_COLLECTION, options.startAfter)
8095
8054
  );
8096
8055
  if (startAfterDoc.exists()) {
8097
- q = (0, import_firestore18.query)(q, (0, import_firestore18.startAfter)(startAfterDoc));
8056
+ q = (0, import_firestore17.query)(q, (0, import_firestore17.startAfter)(startAfterDoc));
8098
8057
  }
8099
8058
  }
8100
- const patientsSnapshot = await (0, import_firestore18.getDocs)(q);
8059
+ const patientsSnapshot = await (0, import_firestore17.getDocs)(q);
8101
8060
  const patients = [];
8102
8061
  patientsSnapshot.forEach((doc47) => {
8103
8062
  patients.push(doc47.data());
@@ -8130,7 +8089,7 @@ var getPatientsByPractitionerWithDetailsUtil = async (db, practitionerId, option
8130
8089
  const patientProfilesWithDetails = await Promise.all(
8131
8090
  patientProfiles.map(async (profile) => {
8132
8091
  try {
8133
- const sensitiveInfoDoc = await (0, import_firestore18.getDoc)(
8092
+ const sensitiveInfoDoc = await (0, import_firestore17.getDoc)(
8134
8093
  getSensitiveInfoDocRef(db, profile.id)
8135
8094
  );
8136
8095
  const sensitiveInfo = sensitiveInfoDoc.exists() ? sensitiveInfoDoc.data() : void 0;
@@ -8166,13 +8125,13 @@ var getPractitionerProfileByUserRef = async (db, userRef) => {
8166
8125
  console.log(
8167
8126
  `[getPractitionerProfileByUserRef] Fetching practitioner with userRef: ${userRef}`
8168
8127
  );
8169
- const practitionersCollection = (0, import_firestore18.collection)(db, PRACTITIONERS_COLLECTION);
8170
- const q = (0, import_firestore18.query)(
8128
+ const practitionersCollection = (0, import_firestore17.collection)(db, PRACTITIONERS_COLLECTION);
8129
+ const q = (0, import_firestore17.query)(
8171
8130
  practitionersCollection,
8172
- (0, import_firestore18.where)("userRef", "==", userRef),
8173
- (0, import_firestore18.limit)(1)
8131
+ (0, import_firestore17.where)("userRef", "==", userRef),
8132
+ (0, import_firestore17.limit)(1)
8174
8133
  );
8175
- const querySnapshot = await (0, import_firestore18.getDocs)(q);
8134
+ const querySnapshot = await (0, import_firestore17.getDocs)(q);
8176
8135
  if (querySnapshot.empty) {
8177
8136
  console.log(
8178
8137
  `[getPractitionerProfileByUserRef] No practitioner found with userRef: ${userRef}`
@@ -8197,11 +8156,11 @@ var getPractitionerProfileByUserRef = async (db, userRef) => {
8197
8156
  };
8198
8157
 
8199
8158
  // src/services/clinic/utils/admin.utils.ts
8200
- var import_firestore20 = require("firebase/firestore");
8159
+ var import_firestore19 = require("firebase/firestore");
8201
8160
 
8202
8161
  // src/validations/clinic.schema.ts
8203
8162
  var import_zod10 = require("zod");
8204
- var import_firestore19 = require("firebase/firestore");
8163
+ var import_firestore18 = require("firebase/firestore");
8205
8164
 
8206
8165
  // src/validations/reviews.schema.ts
8207
8166
  var import_zod8 = require("zod");
@@ -8461,8 +8420,8 @@ var clinicAdminSchema = import_zod10.z.object({
8461
8420
  clinicsManagedInfo: import_zod10.z.array(clinicInfoSchema),
8462
8421
  contactInfo: contactPersonSchema,
8463
8422
  roleTitle: import_zod10.z.string(),
8464
- createdAt: import_zod10.z.instanceof(Date).or(import_zod10.z.instanceof(import_firestore19.Timestamp)),
8465
- updatedAt: import_zod10.z.instanceof(Date).or(import_zod10.z.instanceof(import_firestore19.Timestamp)),
8423
+ createdAt: import_zod10.z.instanceof(Date).or(import_zod10.z.instanceof(import_firestore18.Timestamp)),
8424
+ updatedAt: import_zod10.z.instanceof(Date).or(import_zod10.z.instanceof(import_firestore18.Timestamp)),
8466
8425
  isActive: import_zod10.z.boolean()
8467
8426
  });
8468
8427
  var adminTokenSchema = import_zod10.z.object({
@@ -8471,9 +8430,9 @@ var adminTokenSchema = import_zod10.z.object({
8471
8430
  email: import_zod10.z.string().email().optional().nullable(),
8472
8431
  status: import_zod10.z.nativeEnum(AdminTokenStatus),
8473
8432
  usedByUserRef: import_zod10.z.string().optional(),
8474
- createdAt: import_zod10.z.instanceof(Date).or(import_zod10.z.instanceof(import_firestore19.Timestamp)),
8433
+ createdAt: import_zod10.z.instanceof(Date).or(import_zod10.z.instanceof(import_firestore18.Timestamp)),
8475
8434
  // Timestamp
8476
- expiresAt: import_zod10.z.instanceof(Date).or(import_zod10.z.instanceof(import_firestore19.Timestamp))
8435
+ expiresAt: import_zod10.z.instanceof(Date).or(import_zod10.z.instanceof(import_firestore18.Timestamp))
8477
8436
  // Timestamp
8478
8437
  });
8479
8438
  var stripeTransactionDataSchema = import_zod10.z.object({
@@ -8494,9 +8453,9 @@ var billingInfoSchema = import_zod10.z.object({
8494
8453
  planType: import_zod10.z.string(),
8495
8454
  stripeSubscriptionId: import_zod10.z.string().nullable(),
8496
8455
  stripePriceId: import_zod10.z.string().nullable(),
8497
- currentPeriodStart: import_zod10.z.instanceof(Date).or(import_zod10.z.instanceof(import_firestore19.Timestamp)).nullable(),
8498
- currentPeriodEnd: import_zod10.z.instanceof(Date).or(import_zod10.z.instanceof(import_firestore19.Timestamp)).nullable(),
8499
- updatedAt: import_zod10.z.instanceof(Date).or(import_zod10.z.instanceof(import_firestore19.Timestamp))
8456
+ currentPeriodStart: import_zod10.z.instanceof(Date).or(import_zod10.z.instanceof(import_firestore18.Timestamp)).nullable(),
8457
+ currentPeriodEnd: import_zod10.z.instanceof(Date).or(import_zod10.z.instanceof(import_firestore18.Timestamp)).nullable(),
8458
+ updatedAt: import_zod10.z.instanceof(Date).or(import_zod10.z.instanceof(import_firestore18.Timestamp))
8500
8459
  });
8501
8460
  var billingTransactionSchema = import_zod10.z.object({
8502
8461
  id: import_zod10.z.string(),
@@ -8508,8 +8467,8 @@ var billingTransactionSchema = import_zod10.z.object({
8508
8467
  stripeData: stripeTransactionDataSchema,
8509
8468
  planDetails: planDetailsSchema,
8510
8469
  metadata: import_zod10.z.record(import_zod10.z.any()).optional(),
8511
- timestamp: import_zod10.z.instanceof(Date).or(import_zod10.z.instanceof(import_firestore19.Timestamp)),
8512
- createdAt: import_zod10.z.instanceof(Date).or(import_zod10.z.instanceof(import_firestore19.Timestamp))
8470
+ timestamp: import_zod10.z.instanceof(Date).or(import_zod10.z.instanceof(import_firestore18.Timestamp)),
8471
+ createdAt: import_zod10.z.instanceof(Date).or(import_zod10.z.instanceof(import_firestore18.Timestamp))
8513
8472
  });
8514
8473
  var createBillingTransactionSchema = import_zod10.z.object({
8515
8474
  type: import_zod10.z.nativeEnum(BillingTransactionType),
@@ -8537,9 +8496,9 @@ var clinicGroupSchema = import_zod10.z.object({
8537
8496
  adminsInfo: import_zod10.z.array(adminInfoSchema),
8538
8497
  adminTokens: import_zod10.z.array(adminTokenSchema),
8539
8498
  ownerId: import_zod10.z.string().nullable(),
8540
- createdAt: import_zod10.z.instanceof(Date).or(import_zod10.z.instanceof(import_firestore19.Timestamp)),
8499
+ createdAt: import_zod10.z.instanceof(Date).or(import_zod10.z.instanceof(import_firestore18.Timestamp)),
8541
8500
  // Timestamp
8542
- updatedAt: import_zod10.z.instanceof(Date).or(import_zod10.z.instanceof(import_firestore19.Timestamp)),
8501
+ updatedAt: import_zod10.z.instanceof(Date).or(import_zod10.z.instanceof(import_firestore18.Timestamp)),
8543
8502
  // Timestamp
8544
8503
  isActive: import_zod10.z.boolean(),
8545
8504
  logo: mediaResourceSchema.optional().nullable(),
@@ -8582,9 +8541,9 @@ var clinicSchema = import_zod10.z.object({
8582
8541
  // Use the correct schema for aggregated procedure info
8583
8542
  reviewInfo: clinicReviewInfoSchema,
8584
8543
  admins: import_zod10.z.array(import_zod10.z.string()),
8585
- createdAt: import_zod10.z.instanceof(Date).or(import_zod10.z.instanceof(import_firestore19.Timestamp)),
8544
+ createdAt: import_zod10.z.instanceof(Date).or(import_zod10.z.instanceof(import_firestore18.Timestamp)),
8586
8545
  // Timestamp
8587
- updatedAt: import_zod10.z.instanceof(Date).or(import_zod10.z.instanceof(import_firestore19.Timestamp)),
8546
+ updatedAt: import_zod10.z.instanceof(Date).or(import_zod10.z.instanceof(import_firestore18.Timestamp)),
8588
8547
  // Timestamp
8589
8548
  isActive: import_zod10.z.boolean(),
8590
8549
  isVerified: import_zod10.z.boolean(),
@@ -8808,7 +8767,7 @@ async function createClinicAdmin(db, data, clinicGroupService) {
8808
8767
  }
8809
8768
  console.log("[CLINIC_ADMIN] Preparing admin data object");
8810
8769
  const adminData = {
8811
- id: (0, import_firestore20.doc)((0, import_firestore20.collection)(db, CLINIC_ADMINS_COLLECTION)).id,
8770
+ id: (0, import_firestore19.doc)((0, import_firestore19.collection)(db, CLINIC_ADMINS_COLLECTION)).id,
8812
8771
  // Generate a new ID for the admin document
8813
8772
  userRef: validatedData.userRef,
8814
8773
  clinicGroupId: clinicGroupId || "",
@@ -8821,15 +8780,15 @@ async function createClinicAdmin(db, data, clinicGroupService) {
8821
8780
  contactInfo: validatedData.contactInfo,
8822
8781
  roleTitle: validatedData.roleTitle,
8823
8782
  isActive: validatedData.isActive,
8824
- createdAt: (0, import_firestore20.serverTimestamp)(),
8825
- updatedAt: (0, import_firestore20.serverTimestamp)()
8783
+ createdAt: (0, import_firestore19.serverTimestamp)(),
8784
+ updatedAt: (0, import_firestore19.serverTimestamp)()
8826
8785
  };
8827
8786
  console.log("[CLINIC_ADMIN] Validating complete admin object");
8828
8787
  try {
8829
8788
  clinicAdminSchema.parse({
8830
8789
  ...adminData,
8831
- createdAt: import_firestore20.Timestamp.now(),
8832
- updatedAt: import_firestore20.Timestamp.now()
8790
+ createdAt: import_firestore19.Timestamp.now(),
8791
+ updatedAt: import_firestore19.Timestamp.now()
8833
8792
  });
8834
8793
  console.log("[CLINIC_ADMIN] Admin object validation passed");
8835
8794
  } catch (schemaError) {
@@ -8843,7 +8802,7 @@ async function createClinicAdmin(db, data, clinicGroupService) {
8843
8802
  adminId: adminData.id
8844
8803
  });
8845
8804
  try {
8846
- await (0, import_firestore20.setDoc)((0, import_firestore20.doc)(db, CLINIC_ADMINS_COLLECTION, adminData.id), adminData);
8805
+ await (0, import_firestore19.setDoc)((0, import_firestore19.doc)(db, CLINIC_ADMINS_COLLECTION, adminData.id), adminData);
8847
8806
  console.log("[CLINIC_ADMIN] Admin saved successfully");
8848
8807
  } catch (firestoreError) {
8849
8808
  console.error(
@@ -8892,30 +8851,30 @@ async function checkClinicGroupExists(db, groupId, clinicGroupService) {
8892
8851
  return !!group;
8893
8852
  }
8894
8853
  async function getClinicAdmin(db, adminId) {
8895
- const docRef = (0, import_firestore20.doc)(db, CLINIC_ADMINS_COLLECTION, adminId);
8896
- const docSnap = await (0, import_firestore20.getDoc)(docRef);
8854
+ const docRef = (0, import_firestore19.doc)(db, CLINIC_ADMINS_COLLECTION, adminId);
8855
+ const docSnap = await (0, import_firestore19.getDoc)(docRef);
8897
8856
  if (docSnap.exists()) {
8898
8857
  return docSnap.data();
8899
8858
  }
8900
8859
  return null;
8901
8860
  }
8902
8861
  async function getClinicAdminByUserRef(db, userRef) {
8903
- const q = (0, import_firestore20.query)(
8904
- (0, import_firestore20.collection)(db, CLINIC_ADMINS_COLLECTION),
8905
- (0, import_firestore20.where)("userRef", "==", userRef)
8862
+ const q = (0, import_firestore19.query)(
8863
+ (0, import_firestore19.collection)(db, CLINIC_ADMINS_COLLECTION),
8864
+ (0, import_firestore19.where)("userRef", "==", userRef)
8906
8865
  );
8907
- const querySnapshot = await (0, import_firestore20.getDocs)(q);
8866
+ const querySnapshot = await (0, import_firestore19.getDocs)(q);
8908
8867
  if (querySnapshot.empty) {
8909
8868
  return null;
8910
8869
  }
8911
8870
  return querySnapshot.docs[0].data();
8912
8871
  }
8913
8872
  async function getClinicAdminsByGroup(db, clinicGroupId) {
8914
- const q = (0, import_firestore20.query)(
8915
- (0, import_firestore20.collection)(db, CLINIC_ADMINS_COLLECTION),
8916
- (0, import_firestore20.where)("clinicGroupId", "==", clinicGroupId)
8873
+ const q = (0, import_firestore19.query)(
8874
+ (0, import_firestore19.collection)(db, CLINIC_ADMINS_COLLECTION),
8875
+ (0, import_firestore19.where)("clinicGroupId", "==", clinicGroupId)
8917
8876
  );
8918
- const querySnapshot = await (0, import_firestore20.getDocs)(q);
8877
+ const querySnapshot = await (0, import_firestore19.getDocs)(q);
8919
8878
  return querySnapshot.docs.map((doc47) => doc47.data());
8920
8879
  }
8921
8880
  async function updateClinicAdmin(db, adminId, data) {
@@ -8925,9 +8884,9 @@ async function updateClinicAdmin(db, adminId, data) {
8925
8884
  }
8926
8885
  const updatedData = {
8927
8886
  ...data,
8928
- updatedAt: (0, import_firestore20.serverTimestamp)()
8887
+ updatedAt: (0, import_firestore19.serverTimestamp)()
8929
8888
  };
8930
- await (0, import_firestore20.updateDoc)((0, import_firestore20.doc)(db, CLINIC_ADMINS_COLLECTION, adminId), updatedData);
8889
+ await (0, import_firestore19.updateDoc)((0, import_firestore19.doc)(db, CLINIC_ADMINS_COLLECTION, adminId), updatedData);
8931
8890
  const updatedAdmin = await getClinicAdmin(db, adminId);
8932
8891
  if (!updatedAdmin) {
8933
8892
  throw new Error("Failed to retrieve updated admin");
@@ -8939,7 +8898,7 @@ async function deleteClinicAdmin(db, adminId) {
8939
8898
  if (!admin) {
8940
8899
  throw new Error("Clinic admin not found");
8941
8900
  }
8942
- await (0, import_firestore20.deleteDoc)((0, import_firestore20.doc)(db, CLINIC_ADMINS_COLLECTION, adminId));
8901
+ await (0, import_firestore19.deleteDoc)((0, import_firestore19.doc)(db, CLINIC_ADMINS_COLLECTION, adminId));
8943
8902
  }
8944
8903
  async function addClinicToManaged(db, adminId, clinicId, requesterId, clinicService) {
8945
8904
  const admin = await getClinicAdmin(db, adminId);
@@ -9053,7 +9012,7 @@ async function syncOwnerClinics(db, adminId, clinicService, clinicGroupService)
9053
9012
  // src/services/patient/utils/sensitive.utils.ts
9054
9013
  var checkSensitiveAccessUtil = async (db, patientId, requesterId, requesterRoles) => {
9055
9014
  var _a;
9056
- const patientDoc = await (0, import_firestore21.getDoc)(getPatientDocRef(db, patientId));
9015
+ const patientDoc = await (0, import_firestore20.getDoc)(getPatientDocRef(db, patientId));
9057
9016
  if (!patientDoc.exists()) {
9058
9017
  throw new Error("Patient profile not found");
9059
9018
  }
@@ -9112,7 +9071,7 @@ var createSensitiveInfoUtil = async (db, data, requesterId, requesterRoles, medi
9112
9071
  try {
9113
9072
  await checkSensitiveAccessUtil(db, data.patientId, requesterId, requesterRoles);
9114
9073
  const validatedData = createPatientSensitiveInfoSchema.parse(data);
9115
- const sensitiveDoc = await (0, import_firestore21.getDoc)(getSensitiveInfoDocRef(db, data.patientId));
9074
+ const sensitiveDoc = await (0, import_firestore20.getDoc)(getSensitiveInfoDocRef(db, data.patientId));
9116
9075
  if (sensitiveDoc.exists()) {
9117
9076
  throw new Error("Sensitive information already exists for this patient");
9118
9077
  }
@@ -9129,11 +9088,11 @@ var createSensitiveInfoUtil = async (db, data, requesterId, requesterRoles, medi
9129
9088
  const sensitiveInfoData = {
9130
9089
  ...validatedData,
9131
9090
  photoUrl: processedPhotoUrl,
9132
- createdAt: (0, import_firestore21.serverTimestamp)(),
9133
- updatedAt: (0, import_firestore21.serverTimestamp)()
9091
+ createdAt: (0, import_firestore20.serverTimestamp)(),
9092
+ updatedAt: (0, import_firestore20.serverTimestamp)()
9134
9093
  };
9135
- await (0, import_firestore21.setDoc)(getSensitiveInfoDocRef(db, data.patientId), sensitiveInfoData);
9136
- const createdDoc = await (0, import_firestore21.getDoc)(getSensitiveInfoDocRef(db, data.patientId));
9094
+ await (0, import_firestore20.setDoc)(getSensitiveInfoDocRef(db, data.patientId), sensitiveInfoData);
9095
+ const createdDoc = await (0, import_firestore20.getDoc)(getSensitiveInfoDocRef(db, data.patientId));
9137
9096
  if (!createdDoc.exists()) {
9138
9097
  throw new Error("Failed to create sensitive information");
9139
9098
  }
@@ -9148,7 +9107,7 @@ var createSensitiveInfoUtil = async (db, data, requesterId, requesterRoles, medi
9148
9107
  var getSensitiveInfoUtil = async (db, patientId, requesterId, requesterRoles) => {
9149
9108
  await checkSensitiveAccessUtil(db, patientId, requesterId, requesterRoles);
9150
9109
  await initSensitiveInfoDocIfNotExists(db, patientId, requesterId);
9151
- const sensitiveDoc = await (0, import_firestore21.getDoc)(getSensitiveInfoDocRef(db, patientId));
9110
+ const sensitiveDoc = await (0, import_firestore20.getDoc)(getSensitiveInfoDocRef(db, patientId));
9152
9111
  return sensitiveDoc.exists() ? sensitiveDoc.data() : null;
9153
9112
  };
9154
9113
  var updateSensitiveInfoUtil = async (db, patientId, data, requesterId, requesterRoles, mediaService) => {
@@ -9167,17 +9126,17 @@ var updateSensitiveInfoUtil = async (db, patientId, data, requesterId, requester
9167
9126
  const updateData = {
9168
9127
  ...data,
9169
9128
  photoUrl: processedPhotoUrl,
9170
- updatedAt: (0, import_firestore21.serverTimestamp)()
9129
+ updatedAt: (0, import_firestore20.serverTimestamp)()
9171
9130
  };
9172
- await (0, import_firestore21.updateDoc)(getSensitiveInfoDocRef(db, patientId), updateData);
9173
- const updatedDoc = await (0, import_firestore21.getDoc)(getSensitiveInfoDocRef(db, patientId));
9131
+ await (0, import_firestore20.updateDoc)(getSensitiveInfoDocRef(db, patientId), updateData);
9132
+ const updatedDoc = await (0, import_firestore20.getDoc)(getSensitiveInfoDocRef(db, patientId));
9174
9133
  if (!updatedDoc.exists()) {
9175
9134
  throw new Error("Failed to retrieve updated sensitive information");
9176
9135
  }
9177
9136
  return updatedDoc.data();
9178
9137
  };
9179
9138
  var claimPatientSensitiveInfoUtil = async (db, patientId, userId) => {
9180
- const patientDoc = await (0, import_firestore21.getDoc)(getPatientDocRef(db, patientId));
9139
+ const patientDoc = await (0, import_firestore20.getDoc)(getPatientDocRef(db, patientId));
9181
9140
  if (!patientDoc.exists()) {
9182
9141
  throw new Error("Patient profile not found");
9183
9142
  }
@@ -9188,7 +9147,7 @@ var claimPatientSensitiveInfoUtil = async (db, patientId, userId) => {
9188
9147
  if (patientData.userRef) {
9189
9148
  throw new Error("Patient profile has already been claimed");
9190
9149
  }
9191
- const sensitiveDoc = await (0, import_firestore21.getDoc)(getSensitiveInfoDocRef(db, patientId));
9150
+ const sensitiveDoc = await (0, import_firestore20.getDoc)(getSensitiveInfoDocRef(db, patientId));
9192
9151
  if (!sensitiveDoc.exists()) {
9193
9152
  throw new Error("Patient sensitive information not found");
9194
9153
  }
@@ -9196,11 +9155,11 @@ var claimPatientSensitiveInfoUtil = async (db, patientId, userId) => {
9196
9155
  if (sensitiveData.userRef) {
9197
9156
  throw new Error("Patient sensitive information has already been claimed");
9198
9157
  }
9199
- await (0, import_firestore21.updateDoc)(getSensitiveInfoDocRef(db, patientId), {
9158
+ await (0, import_firestore20.updateDoc)(getSensitiveInfoDocRef(db, patientId), {
9200
9159
  userRef: userId,
9201
- updatedAt: (0, import_firestore21.serverTimestamp)()
9160
+ updatedAt: (0, import_firestore20.serverTimestamp)()
9202
9161
  });
9203
- const updatedDoc = await (0, import_firestore21.getDoc)(getSensitiveInfoDocRef(db, patientId));
9162
+ const updatedDoc = await (0, import_firestore20.getDoc)(getSensitiveInfoDocRef(db, patientId));
9204
9163
  if (!updatedDoc.exists()) {
9205
9164
  throw new Error("Failed to retrieve updated sensitive information");
9206
9165
  }
@@ -9209,21 +9168,21 @@ var claimPatientSensitiveInfoUtil = async (db, patientId, userId) => {
9209
9168
 
9210
9169
  // src/services/patient/utils/docs.utils.ts
9211
9170
  var getPatientDocRef = (db, patientId) => {
9212
- return (0, import_firestore22.doc)(db, PATIENTS_COLLECTION, patientId);
9171
+ return (0, import_firestore21.doc)(db, PATIENTS_COLLECTION, patientId);
9213
9172
  };
9214
9173
  var getPatientDocRefByUserRef = async (db, userRef) => {
9215
- const patientsRef = (0, import_firestore22.collection)(db, PATIENTS_COLLECTION);
9216
- const q = (0, import_firestore22.query)(patientsRef, (0, import_firestore22.where)("userRef", "==", userRef));
9217
- const querySnapshot = await (0, import_firestore22.getDocs)(q);
9174
+ const patientsRef = (0, import_firestore21.collection)(db, PATIENTS_COLLECTION);
9175
+ const q = (0, import_firestore21.query)(patientsRef, (0, import_firestore21.where)("userRef", "==", userRef));
9176
+ const querySnapshot = await (0, import_firestore21.getDocs)(q);
9218
9177
  if (querySnapshot.empty) {
9219
9178
  throw new Error("Patient profile not found");
9220
9179
  }
9221
- return (0, import_firestore22.doc)(db, PATIENTS_COLLECTION, querySnapshot.docs[0].id);
9180
+ return (0, import_firestore21.doc)(db, PATIENTS_COLLECTION, querySnapshot.docs[0].id);
9222
9181
  };
9223
9182
  var getSensitiveInfoDocRef = (db, patientId) => {
9224
9183
  const path = `${PATIENTS_COLLECTION}/${patientId}/${PATIENT_SENSITIVE_INFO_COLLECTION}/${patientId}`;
9225
9184
  console.log(`[getSensitiveInfoDocRef] Creating reference with path: ${path}`);
9226
- return (0, import_firestore22.doc)(
9185
+ return (0, import_firestore21.doc)(
9227
9186
  db,
9228
9187
  PATIENTS_COLLECTION,
9229
9188
  patientId,
@@ -9234,7 +9193,7 @@ var getSensitiveInfoDocRef = (db, patientId) => {
9234
9193
  var getLocationInfoDocRef = (db, patientId) => {
9235
9194
  const path = `${PATIENTS_COLLECTION}/${patientId}/${PATIENT_LOCATION_INFO_COLLECTION}/${patientId}`;
9236
9195
  console.log(`[getLocationInfoDocRef] Creating reference with path: ${path}`);
9237
- return (0, import_firestore22.doc)(
9196
+ return (0, import_firestore21.doc)(
9238
9197
  db,
9239
9198
  PATIENTS_COLLECTION,
9240
9199
  patientId,
@@ -9245,7 +9204,7 @@ var getLocationInfoDocRef = (db, patientId) => {
9245
9204
  var getMedicalInfoDocRef = (db, patientId) => {
9246
9205
  const path = `${PATIENTS_COLLECTION}/${patientId}/${PATIENT_MEDICAL_INFO_COLLECTION}/${patientId}`;
9247
9206
  console.log(`[getMedicalInfoDocRef] Creating reference with path: ${path}`);
9248
- return (0, import_firestore22.doc)(
9207
+ return (0, import_firestore21.doc)(
9249
9208
  db,
9250
9209
  PATIENTS_COLLECTION,
9251
9210
  patientId,
@@ -9262,7 +9221,7 @@ var initSensitiveInfoDocIfNotExists = async (db, patientId, userRef) => {
9262
9221
  console.log(
9263
9222
  `[initSensitiveInfoDocIfNotExists] Got document reference: ${sensitiveInfoRef.path}`
9264
9223
  );
9265
- const sensitiveDoc = await (0, import_firestore22.getDoc)(sensitiveInfoRef);
9224
+ const sensitiveDoc = await (0, import_firestore21.getDoc)(sensitiveInfoRef);
9266
9225
  console.log(
9267
9226
  `[initSensitiveInfoDocIfNotExists] Document exists: ${sensitiveDoc.exists()}`
9268
9227
  );
@@ -9286,7 +9245,7 @@ var initSensitiveInfoDocIfNotExists = async (db, patientId, userRef) => {
9286
9245
  )
9287
9246
  );
9288
9247
  await createSensitiveInfoUtil(db, defaultSensitiveInfo, userRef);
9289
- const verifyDoc = await (0, import_firestore22.getDoc)(sensitiveInfoRef);
9248
+ const verifyDoc = await (0, import_firestore21.getDoc)(sensitiveInfoRef);
9290
9249
  console.log(
9291
9250
  `[initSensitiveInfoDocIfNotExists] Verification - document exists: ${verifyDoc.exists()}`
9292
9251
  );
@@ -9302,6 +9261,93 @@ var initSensitiveInfoDocIfNotExists = async (db, patientId, userRef) => {
9302
9261
  }
9303
9262
  };
9304
9263
 
9264
+ // src/services/patient/utils/clinic.utils.ts
9265
+ var getPatientsByClinicUtil = async (db, clinicId, options) => {
9266
+ try {
9267
+ console.log(
9268
+ `[getPatientsByClinicUtil] Fetching patients for clinic ID: ${clinicId} with options:`,
9269
+ options
9270
+ );
9271
+ const patientsCollection = (0, import_firestore22.collection)(db, PATIENTS_COLLECTION);
9272
+ const constraints = [
9273
+ (0, import_firestore22.where)("clinicIds", "array-contains", clinicId)
9274
+ ];
9275
+ let q = (0, import_firestore22.query)(patientsCollection, ...constraints);
9276
+ if (options == null ? void 0 : options.limit) {
9277
+ q = (0, import_firestore22.query)(q, (0, import_firestore22.limit)(options.limit));
9278
+ }
9279
+ if (options == null ? void 0 : options.startAfter) {
9280
+ const startAfterDoc = await (0, import_firestore22.getDoc)(
9281
+ (0, import_firestore22.doc)(db, PATIENTS_COLLECTION, options.startAfter)
9282
+ );
9283
+ if (startAfterDoc.exists()) {
9284
+ q = (0, import_firestore22.query)(q, (0, import_firestore22.startAfter)(startAfterDoc));
9285
+ }
9286
+ }
9287
+ const patientsSnapshot = await (0, import_firestore22.getDocs)(q);
9288
+ const patients = [];
9289
+ patientsSnapshot.forEach((doc47) => {
9290
+ patients.push(doc47.data());
9291
+ });
9292
+ console.log(
9293
+ `[getPatientsByClinicUtil] Found ${patients.length} patients for clinic ID: ${clinicId}`
9294
+ );
9295
+ return patients;
9296
+ } catch (error) {
9297
+ console.error(
9298
+ `[getPatientsByClinicUtil] Error fetching patients for clinic:`,
9299
+ error
9300
+ );
9301
+ throw new Error(
9302
+ `Failed to retrieve patients for clinic: ${error instanceof Error ? error.message : String(error)}`
9303
+ );
9304
+ }
9305
+ };
9306
+ var getPatientsByClinicWithDetailsUtil = async (db, clinicId, options) => {
9307
+ try {
9308
+ console.log(
9309
+ `[getPatientsByClinicWithDetailsUtil] Fetching patients with details for clinic ID: ${clinicId} with options:`,
9310
+ options
9311
+ );
9312
+ const patientProfiles = await getPatientsByClinicUtil(db, clinicId, options);
9313
+ const patientsWithDetails = await Promise.all(
9314
+ patientProfiles.map(async (profile) => {
9315
+ try {
9316
+ const sensitiveInfoDoc = await (0, import_firestore22.getDoc)(
9317
+ getSensitiveInfoDocRef(db, profile.id)
9318
+ );
9319
+ const sensitiveInfo = sensitiveInfoDoc.exists() ? sensitiveInfoDoc.data() : null;
9320
+ return {
9321
+ ...profile,
9322
+ // Merge phoneNumber from sensitive info if not in profile
9323
+ phoneNumber: profile.phoneNumber || (sensitiveInfo == null ? void 0 : sensitiveInfo.phoneNumber) || null,
9324
+ // Merge dateOfBirth from sensitive info if not in profile
9325
+ dateOfBirth: profile.dateOfBirth || (sensitiveInfo == null ? void 0 : sensitiveInfo.dateOfBirth) || null
9326
+ };
9327
+ } catch (error) {
9328
+ console.error(
9329
+ `[getPatientsByClinicWithDetailsUtil] Error fetching sensitive info for patient ${profile.id}:`,
9330
+ error
9331
+ );
9332
+ return profile;
9333
+ }
9334
+ })
9335
+ );
9336
+ console.log(
9337
+ `[getPatientsByClinicWithDetailsUtil] Found ${patientsWithDetails.length} patients with details for clinic ID: ${clinicId}`
9338
+ );
9339
+ return patientsWithDetails;
9340
+ } catch (error) {
9341
+ console.error(
9342
+ `[getPatientsByClinicWithDetailsUtil] Error fetching patients with details:`,
9343
+ error
9344
+ );
9345
+ throw new Error(
9346
+ `Failed to retrieve patients with details: ${error instanceof Error ? error.message : String(error)}`
9347
+ );
9348
+ }
9349
+ };
9350
+
9305
9351
  // src/services/patient/utils/location.utils.ts
9306
9352
  var import_firestore23 = require("firebase/firestore");
9307
9353
  var import_zod12 = require("zod");
@@ -10852,17 +10898,18 @@ var PatientService = class extends BaseService {
10852
10898
  return getPatientsByPractitionerWithDetailsUtil(this.db, practitionerId, options);
10853
10899
  }
10854
10900
  /**
10855
- * Gets all patients associated with a specific clinic.
10901
+ * Gets all patients associated with a specific clinic, including sensitive info.
10902
+ * This merges data from PatientProfile and PatientSensitiveInfo subcollection.
10856
10903
  *
10857
10904
  * @param {string} clinicId - ID of the clinic whose patients to retrieve
10858
10905
  * @param {Object} options - Optional parameters for pagination
10859
10906
  * @param {number} options.limit - Maximum number of profiles to return
10860
10907
  * @param {string} options.startAfter - The ID of the document to start after (for pagination)
10861
- * @returns {Promise<PatientProfile[]>} A promise resolving to an array of patient profiles
10908
+ * @returns {Promise<PatientProfile[]>} A promise resolving to an array of patient profiles with merged sensitive info
10862
10909
  */
10863
10910
  async getPatientsByClinic(clinicId, options) {
10864
- console.log(`[PatientService.getPatientsByClinic] Fetching patients for clinic: ${clinicId}`);
10865
- return getPatientsByClinicUtil(this.db, clinicId, options);
10911
+ console.log(`[PatientService.getPatientsByClinic] Fetching patients with details for clinic: ${clinicId}`);
10912
+ return getPatientsByClinicWithDetailsUtil(this.db, clinicId, options);
10866
10913
  }
10867
10914
  /**
10868
10915
  * Creates a token for inviting a patient to claim their profile.
@@ -15837,10 +15884,20 @@ var AuthService = class extends BaseService {
15837
15884
  throw AUTH_ERRORS.VALIDATION_ERROR;
15838
15885
  }
15839
15886
  const firebaseError = error;
15840
- if (firebaseError.code === "auth/user-not-found" /* USER_NOT_FOUND */) {
15841
- throw AUTH_ERRORS.USER_NOT_FOUND;
15887
+ switch (firebaseError.code) {
15888
+ case "auth/user-not-found" /* USER_NOT_FOUND */:
15889
+ throw AUTH_ERRORS.USER_NOT_FOUND;
15890
+ case "auth/invalid-email" /* INVALID_EMAIL */:
15891
+ throw AUTH_ERRORS.INVALID_EMAIL;
15892
+ case "auth/too-many-requests" /* TOO_MANY_REQUESTS */:
15893
+ throw AUTH_ERRORS.TOO_MANY_REQUESTS;
15894
+ case "auth/network-request-failed" /* NETWORK_ERROR */:
15895
+ throw AUTH_ERRORS.NETWORK_ERROR;
15896
+ case "auth/operation-not-allowed" /* OPERATION_NOT_ALLOWED */:
15897
+ throw AUTH_ERRORS.OPERATION_NOT_ALLOWED;
15898
+ default:
15899
+ throw error;
15842
15900
  }
15843
- throw error;
15844
15901
  }
15845
15902
  }
15846
15903
  /**
@@ -23276,12 +23333,13 @@ var BrandService = class extends BaseService {
23276
23333
  return { id: docRef.id, ...newBrand };
23277
23334
  }
23278
23335
  /**
23279
- * Gets a paginated list of active brands, optionally filtered by name.
23336
+ * Gets a paginated list of active brands, optionally filtered by name and category.
23280
23337
  * @param rowsPerPage - The number of brands to fetch.
23281
23338
  * @param searchTerm - An optional string to filter brand names by (starts-with search).
23282
23339
  * @param lastVisible - An optional document snapshot to use as a cursor for pagination.
23340
+ * @param category - An optional category to filter brands by.
23283
23341
  */
23284
- async getAll(rowsPerPage, searchTerm, lastVisible) {
23342
+ async getAll(rowsPerPage, searchTerm, lastVisible, category) {
23285
23343
  const constraints = [
23286
23344
  (0, import_firestore61.where)("isActive", "==", true),
23287
23345
  (0, import_firestore61.orderBy)("name_lowercase")
@@ -23293,6 +23351,9 @@ var BrandService = class extends BaseService {
23293
23351
  (0, import_firestore61.where)("name_lowercase", "<=", lowercasedSearchTerm + "\uF8FF")
23294
23352
  );
23295
23353
  }
23354
+ if (category) {
23355
+ constraints.push((0, import_firestore61.where)("category", "==", category));
23356
+ }
23296
23357
  if (lastVisible) {
23297
23358
  constraints.push((0, import_firestore61.startAfter)(lastVisible));
23298
23359
  }
@@ -23309,10 +23370,11 @@ var BrandService = class extends BaseService {
23309
23370
  return { brands, lastVisible: newLastVisible };
23310
23371
  }
23311
23372
  /**
23312
- * Gets the total count of active brands, optionally filtered by name.
23373
+ * Gets the total count of active brands, optionally filtered by name and category.
23313
23374
  * @param searchTerm - An optional string to filter brand names by (starts-with search).
23375
+ * @param category - An optional category to filter brands by.
23314
23376
  */
23315
- async getBrandsCount(searchTerm) {
23377
+ async getBrandsCount(searchTerm, category) {
23316
23378
  const constraints = [(0, import_firestore61.where)("isActive", "==", true)];
23317
23379
  if (searchTerm) {
23318
23380
  const lowercasedSearchTerm = searchTerm.toLowerCase();
@@ -23321,6 +23383,9 @@ var BrandService = class extends BaseService {
23321
23383
  (0, import_firestore61.where)("name_lowercase", "<=", lowercasedSearchTerm + "\uF8FF")
23322
23384
  );
23323
23385
  }
23386
+ if (category) {
23387
+ constraints.push((0, import_firestore61.where)("category", "==", category));
23388
+ }
23324
23389
  const q = (0, import_firestore61.query)(this.getBrandsRef(), ...constraints);
23325
23390
  const snapshot = await (0, import_firestore61.getCountFromServer)(q);
23326
23391
  return snapshot.data().count;
@@ -23390,6 +23455,7 @@ var BrandService = class extends BaseService {
23390
23455
  "id",
23391
23456
  "name",
23392
23457
  "manufacturer",
23458
+ "category",
23393
23459
  "website",
23394
23460
  "description",
23395
23461
  "isActive"
@@ -23420,14 +23486,15 @@ var BrandService = class extends BaseService {
23420
23486
  return includeBom ? "\uFEFF" + csvBody : csvBody;
23421
23487
  }
23422
23488
  brandToCsvRow(brand) {
23423
- var _a, _b, _c, _d, _e, _f;
23489
+ var _a, _b, _c, _d, _e, _f, _g;
23424
23490
  const values = [
23425
23491
  (_a = brand.id) != null ? _a : "",
23426
23492
  (_b = brand.name) != null ? _b : "",
23427
23493
  (_c = brand.manufacturer) != null ? _c : "",
23428
- (_d = brand.website) != null ? _d : "",
23429
- (_e = brand.description) != null ? _e : "",
23430
- String((_f = brand.isActive) != null ? _f : "")
23494
+ (_d = brand.category) != null ? _d : "",
23495
+ (_e = brand.website) != null ? _e : "",
23496
+ (_f = brand.description) != null ? _f : "",
23497
+ String((_g = brand.isActive) != null ? _g : "")
23431
23498
  ];
23432
23499
  return values.map((v) => this.formatCsvValue(v)).join(",");
23433
23500
  }