@blackcode_sa/metaestetics-api 1.12.6 → 1.12.7
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 +98 -1
- package/dist/index.d.ts +98 -1
- package/dist/index.js +1019 -891
- package/dist/index.mjs +779 -644
- package/package.json +1 -2
- package/src/services/clinic/billing-transactions.service.ts +214 -0
- package/src/services/clinic/clinic-group.service.ts +99 -102
- package/src/services/clinic/index.ts +1 -0
package/dist/index.js
CHANGED
|
@@ -38,6 +38,7 @@ __export(index_exports, {
|
|
|
38
38
|
AuthService: () => AuthService,
|
|
39
39
|
BaseService: () => BaseService,
|
|
40
40
|
BillingTransactionType: () => BillingTransactionType,
|
|
41
|
+
BillingTransactionsService: () => BillingTransactionsService,
|
|
41
42
|
BlockingCondition: () => BlockingCondition,
|
|
42
43
|
BrandService: () => BrandService,
|
|
43
44
|
CALENDAR_COLLECTION: () => CALENDAR_COLLECTION,
|
|
@@ -2021,7 +2022,7 @@ var AppointmentService = class extends BaseService {
|
|
|
2021
2022
|
|
|
2022
2023
|
// src/services/auth/auth.service.ts
|
|
2023
2024
|
var import_auth7 = require("firebase/auth");
|
|
2024
|
-
var
|
|
2025
|
+
var import_firestore29 = require("firebase/firestore");
|
|
2025
2026
|
|
|
2026
2027
|
// src/types/user/index.ts
|
|
2027
2028
|
var UserRole = /* @__PURE__ */ ((UserRole2) => {
|
|
@@ -7784,8 +7785,140 @@ var UserService = class extends BaseService {
|
|
|
7784
7785
|
}
|
|
7785
7786
|
};
|
|
7786
7787
|
|
|
7787
|
-
// src/services/clinic/
|
|
7788
|
+
// src/services/clinic/billing-transactions.service.ts
|
|
7788
7789
|
var import_firestore23 = require("firebase/firestore");
|
|
7790
|
+
var BillingTransactionsService = class extends BaseService {
|
|
7791
|
+
constructor() {
|
|
7792
|
+
super(...arguments);
|
|
7793
|
+
this.BILLING_TRANSACTIONS_COLLECTION = "billingTransactions";
|
|
7794
|
+
}
|
|
7795
|
+
/**
|
|
7796
|
+
* Get billing transactions for a clinic group with pagination
|
|
7797
|
+
* @param clinicGroupId - The clinic group ID
|
|
7798
|
+
* @param options - Query options
|
|
7799
|
+
* @returns Promise with transactions and pagination info
|
|
7800
|
+
*/
|
|
7801
|
+
async getBillingTransactions(clinicGroupId, options = {}) {
|
|
7802
|
+
try {
|
|
7803
|
+
const { limit: queryLimit = 50, startAfter: startAfterDoc, transactionType } = options;
|
|
7804
|
+
const constraints = [];
|
|
7805
|
+
if (transactionType) {
|
|
7806
|
+
constraints.push((0, import_firestore23.where)("type", "==", transactionType));
|
|
7807
|
+
}
|
|
7808
|
+
constraints.push((0, import_firestore23.orderBy)("timestamp", "desc"));
|
|
7809
|
+
if (startAfterDoc) {
|
|
7810
|
+
constraints.push((0, import_firestore23.startAfter)(startAfterDoc));
|
|
7811
|
+
}
|
|
7812
|
+
constraints.push((0, import_firestore23.limit)(queryLimit + 1));
|
|
7813
|
+
const transactionsRef = (0, import_firestore23.collection)(
|
|
7814
|
+
this.db,
|
|
7815
|
+
CLINIC_GROUPS_COLLECTION,
|
|
7816
|
+
clinicGroupId,
|
|
7817
|
+
this.BILLING_TRANSACTIONS_COLLECTION
|
|
7818
|
+
);
|
|
7819
|
+
const q = (0, import_firestore23.query)(transactionsRef, ...constraints);
|
|
7820
|
+
const querySnapshot = await (0, import_firestore23.getDocs)(q);
|
|
7821
|
+
const docs = querySnapshot.docs;
|
|
7822
|
+
const hasMore = docs.length > queryLimit;
|
|
7823
|
+
const transactions = docs.slice(0, queryLimit).map((doc38) => ({
|
|
7824
|
+
id: doc38.id,
|
|
7825
|
+
...doc38.data()
|
|
7826
|
+
}));
|
|
7827
|
+
const lastDoc = transactions.length > 0 ? docs[transactions.length - 1] : null;
|
|
7828
|
+
return {
|
|
7829
|
+
transactions,
|
|
7830
|
+
lastDoc,
|
|
7831
|
+
hasMore
|
|
7832
|
+
};
|
|
7833
|
+
} catch (error) {
|
|
7834
|
+
console.error(
|
|
7835
|
+
`Error fetching billing transactions for clinic group ${clinicGroupId}:`,
|
|
7836
|
+
error
|
|
7837
|
+
);
|
|
7838
|
+
throw new Error(
|
|
7839
|
+
`Failed to fetch billing transactions: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
7840
|
+
);
|
|
7841
|
+
}
|
|
7842
|
+
}
|
|
7843
|
+
/**
|
|
7844
|
+
* Get recent billing transactions (last 10)
|
|
7845
|
+
* @param clinicGroupId - The clinic group ID
|
|
7846
|
+
* @returns Promise with recent transactions
|
|
7847
|
+
*/
|
|
7848
|
+
async getRecentBillingTransactions(clinicGroupId) {
|
|
7849
|
+
const result = await this.getBillingTransactions(clinicGroupId, { limit: 10 });
|
|
7850
|
+
return result.transactions;
|
|
7851
|
+
}
|
|
7852
|
+
/**
|
|
7853
|
+
* Get billing transactions by type
|
|
7854
|
+
* @param clinicGroupId - The clinic group ID
|
|
7855
|
+
* @param transactionType - The transaction type to filter by
|
|
7856
|
+
* @param options - Additional query options
|
|
7857
|
+
* @returns Promise with filtered transactions
|
|
7858
|
+
*/
|
|
7859
|
+
async getBillingTransactionsByType(clinicGroupId, transactionType, options = {}) {
|
|
7860
|
+
return this.getBillingTransactions(clinicGroupId, {
|
|
7861
|
+
...options,
|
|
7862
|
+
transactionType
|
|
7863
|
+
});
|
|
7864
|
+
}
|
|
7865
|
+
/**
|
|
7866
|
+
* Get subscription-related transactions only
|
|
7867
|
+
* @param clinicGroupId - The clinic group ID
|
|
7868
|
+
* @param options - Query options
|
|
7869
|
+
* @returns Promise with subscription transactions
|
|
7870
|
+
*/
|
|
7871
|
+
async getSubscriptionTransactions(clinicGroupId, options = {}) {
|
|
7872
|
+
try {
|
|
7873
|
+
const { limit: queryLimit = 50, startAfter: startAfterDoc } = options;
|
|
7874
|
+
const subscriptionTypes = [
|
|
7875
|
+
"subscription_created" /* SUBSCRIPTION_CREATED */,
|
|
7876
|
+
"subscription_activated" /* SUBSCRIPTION_ACTIVATED */,
|
|
7877
|
+
"subscription_renewed" /* SUBSCRIPTION_RENEWED */,
|
|
7878
|
+
"subscription_updated" /* SUBSCRIPTION_UPDATED */,
|
|
7879
|
+
"subscription_canceled" /* SUBSCRIPTION_CANCELED */,
|
|
7880
|
+
"subscription_reactivated" /* SUBSCRIPTION_REACTIVATED */,
|
|
7881
|
+
"subscription_deleted" /* SUBSCRIPTION_DELETED */
|
|
7882
|
+
];
|
|
7883
|
+
const constraints = [(0, import_firestore23.where)("type", "in", subscriptionTypes), (0, import_firestore23.orderBy)("timestamp", "desc")];
|
|
7884
|
+
if (startAfterDoc) {
|
|
7885
|
+
constraints.push((0, import_firestore23.startAfter)(startAfterDoc));
|
|
7886
|
+
}
|
|
7887
|
+
constraints.push((0, import_firestore23.limit)(queryLimit + 1));
|
|
7888
|
+
const transactionsRef = (0, import_firestore23.collection)(
|
|
7889
|
+
this.db,
|
|
7890
|
+
CLINIC_GROUPS_COLLECTION,
|
|
7891
|
+
clinicGroupId,
|
|
7892
|
+
this.BILLING_TRANSACTIONS_COLLECTION
|
|
7893
|
+
);
|
|
7894
|
+
const q = (0, import_firestore23.query)(transactionsRef, ...constraints);
|
|
7895
|
+
const querySnapshot = await (0, import_firestore23.getDocs)(q);
|
|
7896
|
+
const docs = querySnapshot.docs;
|
|
7897
|
+
const hasMore = docs.length > queryLimit;
|
|
7898
|
+
const transactions = docs.slice(0, queryLimit).map((doc38) => ({
|
|
7899
|
+
id: doc38.id,
|
|
7900
|
+
...doc38.data()
|
|
7901
|
+
}));
|
|
7902
|
+
const lastDoc = transactions.length > 0 ? docs[transactions.length - 1] : null;
|
|
7903
|
+
return {
|
|
7904
|
+
transactions,
|
|
7905
|
+
lastDoc,
|
|
7906
|
+
hasMore
|
|
7907
|
+
};
|
|
7908
|
+
} catch (error) {
|
|
7909
|
+
console.error(
|
|
7910
|
+
`Error fetching subscription transactions for clinic group ${clinicGroupId}:`,
|
|
7911
|
+
error
|
|
7912
|
+
);
|
|
7913
|
+
throw new Error(
|
|
7914
|
+
`Failed to fetch subscription transactions: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
7915
|
+
);
|
|
7916
|
+
}
|
|
7917
|
+
}
|
|
7918
|
+
};
|
|
7919
|
+
|
|
7920
|
+
// src/services/clinic/utils/clinic-group.utils.ts
|
|
7921
|
+
var import_firestore24 = require("firebase/firestore");
|
|
7789
7922
|
var import_geofire_common3 = require("geofire-common");
|
|
7790
7923
|
var import_zod18 = require("zod");
|
|
7791
7924
|
|
|
@@ -7902,9 +8035,9 @@ async function createClinicGroup(db, data, ownerId, isDefault = false, clinicAdm
|
|
|
7902
8035
|
throw geohashError;
|
|
7903
8036
|
}
|
|
7904
8037
|
}
|
|
7905
|
-
const now =
|
|
8038
|
+
const now = import_firestore24.Timestamp.now();
|
|
7906
8039
|
console.log("[CLINIC_GROUP] Preparing clinic group data object");
|
|
7907
|
-
const groupId = (0,
|
|
8040
|
+
const groupId = (0, import_firestore24.doc)((0, import_firestore24.collection)(db, CLINIC_GROUPS_COLLECTION)).id;
|
|
7908
8041
|
console.log("[CLINIC_GROUP] Logo value:", {
|
|
7909
8042
|
logoValue: validatedData.logo,
|
|
7910
8043
|
logoType: validatedData.logo === null ? "null" : typeof validatedData.logo
|
|
@@ -7954,7 +8087,7 @@ async function createClinicGroup(db, data, ownerId, isDefault = false, clinicAdm
|
|
|
7954
8087
|
groupId: groupData.id
|
|
7955
8088
|
});
|
|
7956
8089
|
try {
|
|
7957
|
-
await (0,
|
|
8090
|
+
await (0, import_firestore24.setDoc)((0, import_firestore24.doc)(db, CLINIC_GROUPS_COLLECTION, groupData.id), groupData);
|
|
7958
8091
|
console.log("[CLINIC_GROUP] Clinic group saved successfully");
|
|
7959
8092
|
} catch (firestoreError) {
|
|
7960
8093
|
console.error(
|
|
@@ -8000,19 +8133,19 @@ async function createClinicGroup(db, data, ownerId, isDefault = false, clinicAdm
|
|
|
8000
8133
|
}
|
|
8001
8134
|
}
|
|
8002
8135
|
async function getClinicGroup(db, groupId) {
|
|
8003
|
-
const docRef = (0,
|
|
8004
|
-
const docSnap = await (0,
|
|
8136
|
+
const docRef = (0, import_firestore24.doc)(db, CLINIC_GROUPS_COLLECTION, groupId);
|
|
8137
|
+
const docSnap = await (0, import_firestore24.getDoc)(docRef);
|
|
8005
8138
|
if (docSnap.exists()) {
|
|
8006
8139
|
return docSnap.data();
|
|
8007
8140
|
}
|
|
8008
8141
|
return null;
|
|
8009
8142
|
}
|
|
8010
8143
|
async function getAllActiveGroups(db) {
|
|
8011
|
-
const q = (0,
|
|
8012
|
-
(0,
|
|
8013
|
-
(0,
|
|
8144
|
+
const q = (0, import_firestore24.query)(
|
|
8145
|
+
(0, import_firestore24.collection)(db, CLINIC_GROUPS_COLLECTION),
|
|
8146
|
+
(0, import_firestore24.where)("isActive", "==", true)
|
|
8014
8147
|
);
|
|
8015
|
-
const querySnapshot = await (0,
|
|
8148
|
+
const querySnapshot = await (0, import_firestore24.getDocs)(q);
|
|
8016
8149
|
return querySnapshot.docs.map((doc38) => doc38.data());
|
|
8017
8150
|
}
|
|
8018
8151
|
async function updateClinicGroup(db, groupId, data, app) {
|
|
@@ -8041,10 +8174,10 @@ async function updateClinicGroup(db, groupId, data, app) {
|
|
|
8041
8174
|
}
|
|
8042
8175
|
updatedData = {
|
|
8043
8176
|
...updatedData,
|
|
8044
|
-
updatedAt:
|
|
8177
|
+
updatedAt: import_firestore24.Timestamp.now()
|
|
8045
8178
|
};
|
|
8046
8179
|
console.log("[CLINIC_GROUP] Updating clinic group in Firestore");
|
|
8047
|
-
await (0,
|
|
8180
|
+
await (0, import_firestore24.updateDoc)((0, import_firestore24.doc)(db, CLINIC_GROUPS_COLLECTION, groupId), updatedData);
|
|
8048
8181
|
console.log("[CLINIC_GROUP] Clinic group updated successfully");
|
|
8049
8182
|
const updatedGroup = await getClinicGroup(db, groupId);
|
|
8050
8183
|
if (!updatedGroup) {
|
|
@@ -8125,10 +8258,10 @@ async function createAdminToken(db, groupId, creatorAdminId, app, data) {
|
|
|
8125
8258
|
if (!group.admins.includes(creatorAdminId)) {
|
|
8126
8259
|
throw new Error("Admin does not belong to this clinic group");
|
|
8127
8260
|
}
|
|
8128
|
-
const now =
|
|
8261
|
+
const now = import_firestore24.Timestamp.now();
|
|
8129
8262
|
const expiresInDays = (data == null ? void 0 : data.expiresInDays) || 7;
|
|
8130
8263
|
const email = (data == null ? void 0 : data.email) || null;
|
|
8131
|
-
const expiresAt = new
|
|
8264
|
+
const expiresAt = new import_firestore24.Timestamp(
|
|
8132
8265
|
now.seconds + expiresInDays * 24 * 60 * 60,
|
|
8133
8266
|
now.nanoseconds
|
|
8134
8267
|
);
|
|
@@ -8162,7 +8295,7 @@ async function verifyAndUseAdminToken(db, groupId, token, userRef, app) {
|
|
|
8162
8295
|
if (adminToken.status !== "active" /* ACTIVE */) {
|
|
8163
8296
|
throw new Error("Admin token is not active");
|
|
8164
8297
|
}
|
|
8165
|
-
const now =
|
|
8298
|
+
const now = import_firestore24.Timestamp.now();
|
|
8166
8299
|
if (adminToken.expiresAt.seconds < now.seconds) {
|
|
8167
8300
|
const updatedTokens2 = group.adminTokens.map(
|
|
8168
8301
|
(t) => t.id === adminToken.id ? { ...t, status: "expired" /* EXPIRED */ } : t
|
|
@@ -8228,6 +8361,7 @@ var ClinicGroupService = class extends BaseService {
|
|
|
8228
8361
|
constructor(db, auth, app, clinicAdminService) {
|
|
8229
8362
|
super(db, auth, app);
|
|
8230
8363
|
this.clinicAdminService = clinicAdminService;
|
|
8364
|
+
this.billingTransactionsService = new BillingTransactionsService(db, auth, app);
|
|
8231
8365
|
}
|
|
8232
8366
|
/**
|
|
8233
8367
|
* Kreira novu grupaciju klinika
|
|
@@ -8264,23 +8398,13 @@ var ClinicGroupService = class extends BaseService {
|
|
|
8264
8398
|
* Dodaje admina u grupaciju
|
|
8265
8399
|
*/
|
|
8266
8400
|
async addAdminToGroup(groupId, adminId) {
|
|
8267
|
-
return addAdminToGroup(
|
|
8268
|
-
this.db,
|
|
8269
|
-
groupId,
|
|
8270
|
-
adminId,
|
|
8271
|
-
this.app
|
|
8272
|
-
);
|
|
8401
|
+
return addAdminToGroup(this.db, groupId, adminId, this.app);
|
|
8273
8402
|
}
|
|
8274
8403
|
/**
|
|
8275
8404
|
* Uklanja admina iz grupacije
|
|
8276
8405
|
*/
|
|
8277
8406
|
async removeAdminFromGroup(groupId, adminId) {
|
|
8278
|
-
return removeAdminFromGroup(
|
|
8279
|
-
this.db,
|
|
8280
|
-
groupId,
|
|
8281
|
-
adminId,
|
|
8282
|
-
this.app
|
|
8283
|
-
);
|
|
8407
|
+
return removeAdminFromGroup(this.db, groupId, adminId, this.app);
|
|
8284
8408
|
}
|
|
8285
8409
|
/**
|
|
8286
8410
|
* Deaktivira grupaciju klinika
|
|
@@ -8320,10 +8444,7 @@ var ClinicGroupService = class extends BaseService {
|
|
|
8320
8444
|
logoUrl = uploadedLogoUrl;
|
|
8321
8445
|
}
|
|
8322
8446
|
} catch (error) {
|
|
8323
|
-
console.error(
|
|
8324
|
-
"[CLINIC_GROUP] Error processing logo in setupClinicGroup:",
|
|
8325
|
-
error
|
|
8326
|
-
);
|
|
8447
|
+
console.error("[CLINIC_GROUP] Error processing logo in setupClinicGroup:", error);
|
|
8327
8448
|
}
|
|
8328
8449
|
}
|
|
8329
8450
|
const updateData = {
|
|
@@ -8342,48 +8463,25 @@ var ClinicGroupService = class extends BaseService {
|
|
|
8342
8463
|
* Kreira admin token za grupaciju
|
|
8343
8464
|
*/
|
|
8344
8465
|
async createAdminToken(groupId, creatorAdminId, data) {
|
|
8345
|
-
return createAdminToken(
|
|
8346
|
-
this.db,
|
|
8347
|
-
groupId,
|
|
8348
|
-
creatorAdminId,
|
|
8349
|
-
this.app,
|
|
8350
|
-
data
|
|
8351
|
-
);
|
|
8466
|
+
return createAdminToken(this.db, groupId, creatorAdminId, this.app, data);
|
|
8352
8467
|
}
|
|
8353
8468
|
/**
|
|
8354
8469
|
* Verifikuje i koristi admin token
|
|
8355
8470
|
*/
|
|
8356
8471
|
async verifyAndUseAdminToken(groupId, token, userRef) {
|
|
8357
|
-
return verifyAndUseAdminToken(
|
|
8358
|
-
this.db,
|
|
8359
|
-
groupId,
|
|
8360
|
-
token,
|
|
8361
|
-
userRef,
|
|
8362
|
-
this.app
|
|
8363
|
-
);
|
|
8472
|
+
return verifyAndUseAdminToken(this.db, groupId, token, userRef, this.app);
|
|
8364
8473
|
}
|
|
8365
8474
|
/**
|
|
8366
8475
|
* Briše admin token
|
|
8367
8476
|
*/
|
|
8368
8477
|
async deleteAdminToken(groupId, tokenId, adminId) {
|
|
8369
|
-
return deleteAdminToken(
|
|
8370
|
-
this.db,
|
|
8371
|
-
groupId,
|
|
8372
|
-
tokenId,
|
|
8373
|
-
adminId,
|
|
8374
|
-
this.app
|
|
8375
|
-
);
|
|
8478
|
+
return deleteAdminToken(this.db, groupId, tokenId, adminId, this.app);
|
|
8376
8479
|
}
|
|
8377
8480
|
/**
|
|
8378
8481
|
* Dohvata aktivne admin tokene
|
|
8379
8482
|
*/
|
|
8380
8483
|
async getActiveAdminTokens(groupId, adminId) {
|
|
8381
|
-
return getActiveAdminTokens(
|
|
8382
|
-
this.db,
|
|
8383
|
-
groupId,
|
|
8384
|
-
adminId,
|
|
8385
|
-
this.app
|
|
8386
|
-
);
|
|
8484
|
+
return getActiveAdminTokens(this.db, groupId, adminId, this.app);
|
|
8387
8485
|
}
|
|
8388
8486
|
// TODO: Add a method to get all admin tokens for a clinic group (not just active ones)
|
|
8389
8487
|
// TODO: Refactor admin token methods not to add tokens to the clinicGroup document,
|
|
@@ -8427,33 +8525,62 @@ var ClinicGroupService = class extends BaseService {
|
|
|
8427
8525
|
console.log("[CLINIC_GROUP] Completing onboarding", { groupId });
|
|
8428
8526
|
return this.setOnboarding(groupId, { completed: true });
|
|
8429
8527
|
}
|
|
8528
|
+
/**
|
|
8529
|
+
* Get billing transactions for a clinic group
|
|
8530
|
+
*
|
|
8531
|
+
* @param groupId - The clinic group ID
|
|
8532
|
+
* @param options - Query options for pagination and filtering
|
|
8533
|
+
* @returns Promise with billing transactions and pagination info
|
|
8534
|
+
*/
|
|
8535
|
+
async getBillingTransactions(groupId, options = {}) {
|
|
8536
|
+
return this.billingTransactionsService.getBillingTransactions(groupId, options);
|
|
8537
|
+
}
|
|
8538
|
+
/**
|
|
8539
|
+
* Get recent billing transactions for a clinic group (last 10)
|
|
8540
|
+
*
|
|
8541
|
+
* @param groupId - The clinic group ID
|
|
8542
|
+
* @returns Promise with recent billing transactions
|
|
8543
|
+
*/
|
|
8544
|
+
async getRecentBillingTransactions(groupId) {
|
|
8545
|
+
return this.billingTransactionsService.getRecentBillingTransactions(groupId);
|
|
8546
|
+
}
|
|
8547
|
+
/**
|
|
8548
|
+
* Get subscription-related billing transactions for a clinic group
|
|
8549
|
+
*
|
|
8550
|
+
* @param groupId - The clinic group ID
|
|
8551
|
+
* @param options - Query options for pagination
|
|
8552
|
+
* @returns Promise with subscription transactions and pagination info
|
|
8553
|
+
*/
|
|
8554
|
+
async getSubscriptionTransactions(groupId, options = {}) {
|
|
8555
|
+
return this.billingTransactionsService.getSubscriptionTransactions(groupId, options);
|
|
8556
|
+
}
|
|
8430
8557
|
};
|
|
8431
8558
|
|
|
8432
8559
|
// src/services/clinic/clinic.service.ts
|
|
8433
|
-
var
|
|
8560
|
+
var import_firestore28 = require("firebase/firestore");
|
|
8434
8561
|
var import_functions2 = require("firebase/functions");
|
|
8435
8562
|
var import_geofire_common7 = require("geofire-common");
|
|
8436
8563
|
var import_zod20 = require("zod");
|
|
8437
8564
|
|
|
8438
8565
|
// src/services/clinic/utils/clinic.utils.ts
|
|
8439
|
-
var
|
|
8566
|
+
var import_firestore25 = require("firebase/firestore");
|
|
8440
8567
|
var import_geofire_common4 = require("geofire-common");
|
|
8441
8568
|
var import_zod19 = require("zod");
|
|
8442
8569
|
async function getClinic(db, clinicId) {
|
|
8443
|
-
const docRef = (0,
|
|
8444
|
-
const docSnap = await (0,
|
|
8570
|
+
const docRef = (0, import_firestore25.doc)(db, CLINICS_COLLECTION, clinicId);
|
|
8571
|
+
const docSnap = await (0, import_firestore25.getDoc)(docRef);
|
|
8445
8572
|
if (docSnap.exists()) {
|
|
8446
8573
|
return docSnap.data();
|
|
8447
8574
|
}
|
|
8448
8575
|
return null;
|
|
8449
8576
|
}
|
|
8450
8577
|
async function getClinicsByGroup(db, groupId) {
|
|
8451
|
-
const q = (0,
|
|
8452
|
-
(0,
|
|
8453
|
-
(0,
|
|
8454
|
-
(0,
|
|
8578
|
+
const q = (0, import_firestore25.query)(
|
|
8579
|
+
(0, import_firestore25.collection)(db, CLINICS_COLLECTION),
|
|
8580
|
+
(0, import_firestore25.where)("clinicGroupId", "==", groupId),
|
|
8581
|
+
(0, import_firestore25.where)("isActive", "==", true)
|
|
8455
8582
|
);
|
|
8456
|
-
const querySnapshot = await (0,
|
|
8583
|
+
const querySnapshot = await (0, import_firestore25.getDocs)(q);
|
|
8457
8584
|
return querySnapshot.docs.map((doc38) => doc38.data());
|
|
8458
8585
|
}
|
|
8459
8586
|
async function updateClinic(db, clinicId, data, adminId, clinicAdminService, app) {
|
|
@@ -8609,11 +8736,11 @@ async function updateClinic(db, clinicId, data, adminId, clinicAdminService, app
|
|
|
8609
8736
|
}
|
|
8610
8737
|
updatedData = {
|
|
8611
8738
|
...updatedData,
|
|
8612
|
-
updatedAt:
|
|
8739
|
+
updatedAt: import_firestore25.Timestamp.now()
|
|
8613
8740
|
};
|
|
8614
8741
|
console.log("[CLINIC] Updating clinic in Firestore");
|
|
8615
8742
|
try {
|
|
8616
|
-
await (0,
|
|
8743
|
+
await (0, import_firestore25.updateDoc)((0, import_firestore25.doc)(db, CLINICS_COLLECTION, clinicId), updatedData);
|
|
8617
8744
|
console.log("[CLINIC] Clinic updated successfully");
|
|
8618
8745
|
} catch (updateError) {
|
|
8619
8746
|
console.error("[CLINIC] Error updating clinic in Firestore:", updateError);
|
|
@@ -8642,12 +8769,12 @@ async function getClinicsByAdmin(db, adminId, options = {}, clinicAdminService,
|
|
|
8642
8769
|
if (clinicIds.length === 0) {
|
|
8643
8770
|
return [];
|
|
8644
8771
|
}
|
|
8645
|
-
const constraints = [(0,
|
|
8772
|
+
const constraints = [(0, import_firestore25.where)("id", "in", clinicIds)];
|
|
8646
8773
|
if (options.isActive !== void 0) {
|
|
8647
|
-
constraints.push((0,
|
|
8774
|
+
constraints.push((0, import_firestore25.where)("isActive", "==", options.isActive));
|
|
8648
8775
|
}
|
|
8649
|
-
const q = (0,
|
|
8650
|
-
const querySnapshot = await (0,
|
|
8776
|
+
const q = (0, import_firestore25.query)((0, import_firestore25.collection)(db, CLINICS_COLLECTION), ...constraints);
|
|
8777
|
+
const querySnapshot = await (0, import_firestore25.getDocs)(q);
|
|
8651
8778
|
return querySnapshot.docs.map((doc38) => doc38.data());
|
|
8652
8779
|
}
|
|
8653
8780
|
async function getActiveClinicsByAdmin(db, adminId, clinicAdminService, clinicGroupService) {
|
|
@@ -8661,8 +8788,8 @@ async function getActiveClinicsByAdmin(db, adminId, clinicAdminService, clinicGr
|
|
|
8661
8788
|
}
|
|
8662
8789
|
async function getClinicById(db, clinicId) {
|
|
8663
8790
|
try {
|
|
8664
|
-
const clinicRef = (0,
|
|
8665
|
-
const clinicSnapshot = await (0,
|
|
8791
|
+
const clinicRef = (0, import_firestore25.doc)(db, CLINICS_COLLECTION, clinicId);
|
|
8792
|
+
const clinicSnapshot = await (0, import_firestore25.getDoc)(clinicRef);
|
|
8666
8793
|
if (!clinicSnapshot.exists()) {
|
|
8667
8794
|
return null;
|
|
8668
8795
|
}
|
|
@@ -8678,20 +8805,20 @@ async function getClinicById(db, clinicId) {
|
|
|
8678
8805
|
}
|
|
8679
8806
|
async function getAllClinics(db, pagination, lastDoc) {
|
|
8680
8807
|
try {
|
|
8681
|
-
const clinicsCollection = (0,
|
|
8682
|
-
let clinicsQuery = (0,
|
|
8808
|
+
const clinicsCollection = (0, import_firestore25.collection)(db, CLINICS_COLLECTION);
|
|
8809
|
+
let clinicsQuery = (0, import_firestore25.query)(clinicsCollection);
|
|
8683
8810
|
if (pagination && pagination > 0) {
|
|
8684
8811
|
if (lastDoc) {
|
|
8685
|
-
clinicsQuery = (0,
|
|
8812
|
+
clinicsQuery = (0, import_firestore25.query)(
|
|
8686
8813
|
clinicsCollection,
|
|
8687
|
-
(0,
|
|
8688
|
-
(0,
|
|
8814
|
+
(0, import_firestore25.startAfter)(lastDoc),
|
|
8815
|
+
(0, import_firestore25.limit)(pagination)
|
|
8689
8816
|
);
|
|
8690
8817
|
} else {
|
|
8691
|
-
clinicsQuery = (0,
|
|
8818
|
+
clinicsQuery = (0, import_firestore25.query)(clinicsCollection, (0, import_firestore25.limit)(pagination));
|
|
8692
8819
|
}
|
|
8693
8820
|
}
|
|
8694
|
-
const clinicsSnapshot = await (0,
|
|
8821
|
+
const clinicsSnapshot = await (0, import_firestore25.getDocs)(clinicsQuery);
|
|
8695
8822
|
const lastVisible = clinicsSnapshot.docs[clinicsSnapshot.docs.length - 1];
|
|
8696
8823
|
const clinics = clinicsSnapshot.docs.map((doc38) => {
|
|
8697
8824
|
const data = doc38.data();
|
|
@@ -8718,12 +8845,12 @@ async function getAllClinicsInRange(db, center, rangeInKm, pagination, lastDoc)
|
|
|
8718
8845
|
let lastDocSnapshot = null;
|
|
8719
8846
|
for (const b of bounds) {
|
|
8720
8847
|
const constraints = [
|
|
8721
|
-
(0,
|
|
8722
|
-
(0,
|
|
8723
|
-
(0,
|
|
8848
|
+
(0, import_firestore25.where)("location.geohash", ">=", b[0]),
|
|
8849
|
+
(0, import_firestore25.where)("location.geohash", "<=", b[1]),
|
|
8850
|
+
(0, import_firestore25.where)("isActive", "==", true)
|
|
8724
8851
|
];
|
|
8725
|
-
const q = (0,
|
|
8726
|
-
const querySnapshot = await (0,
|
|
8852
|
+
const q = (0, import_firestore25.query)((0, import_firestore25.collection)(db, CLINICS_COLLECTION), ...constraints);
|
|
8853
|
+
const querySnapshot = await (0, import_firestore25.getDocs)(q);
|
|
8727
8854
|
for (const doc38 of querySnapshot.docs) {
|
|
8728
8855
|
const clinic = doc38.data();
|
|
8729
8856
|
const distance = (0, import_geofire_common4.distanceBetween)(
|
|
@@ -8818,7 +8945,7 @@ async function removeTags(db, clinicId, adminId, tagsToRemove, clinicAdminServic
|
|
|
8818
8945
|
}
|
|
8819
8946
|
|
|
8820
8947
|
// src/services/clinic/utils/search.utils.ts
|
|
8821
|
-
var
|
|
8948
|
+
var import_firestore26 = require("firebase/firestore");
|
|
8822
8949
|
var import_geofire_common5 = require("geofire-common");
|
|
8823
8950
|
async function findClinicsInRadius(db, center, radiusInKm, filters) {
|
|
8824
8951
|
const bounds = (0, import_geofire_common5.geohashQueryBounds)(
|
|
@@ -8828,20 +8955,20 @@ async function findClinicsInRadius(db, center, radiusInKm, filters) {
|
|
|
8828
8955
|
const matchingDocs = [];
|
|
8829
8956
|
for (const b of bounds) {
|
|
8830
8957
|
const constraints = [
|
|
8831
|
-
(0,
|
|
8832
|
-
(0,
|
|
8833
|
-
(0,
|
|
8958
|
+
(0, import_firestore26.where)("location.geohash", ">=", b[0]),
|
|
8959
|
+
(0, import_firestore26.where)("location.geohash", "<=", b[1]),
|
|
8960
|
+
(0, import_firestore26.where)("isActive", "==", true)
|
|
8834
8961
|
];
|
|
8835
8962
|
if (filters == null ? void 0 : filters.services) {
|
|
8836
8963
|
constraints.push(
|
|
8837
|
-
(0,
|
|
8964
|
+
(0, import_firestore26.where)("services", "array-contains-any", filters.services)
|
|
8838
8965
|
);
|
|
8839
8966
|
}
|
|
8840
8967
|
if ((filters == null ? void 0 : filters.tags) && filters.tags.length > 0) {
|
|
8841
|
-
constraints.push((0,
|
|
8968
|
+
constraints.push((0, import_firestore26.where)("tags", "array-contains-any", filters.tags));
|
|
8842
8969
|
}
|
|
8843
|
-
const q = (0,
|
|
8844
|
-
const querySnapshot = await (0,
|
|
8970
|
+
const q = (0, import_firestore26.query)((0, import_firestore26.collection)(db, CLINICS_COLLECTION), ...constraints);
|
|
8971
|
+
const querySnapshot = await (0, import_firestore26.getDocs)(q);
|
|
8845
8972
|
for (const doc38 of querySnapshot.docs) {
|
|
8846
8973
|
const clinic = doc38.data();
|
|
8847
8974
|
const distance = (0, import_geofire_common5.distanceBetween)(
|
|
@@ -8868,7 +8995,7 @@ async function findClinicsInRadius(db, center, radiusInKm, filters) {
|
|
|
8868
8995
|
}
|
|
8869
8996
|
|
|
8870
8997
|
// src/services/clinic/utils/filter.utils.ts
|
|
8871
|
-
var
|
|
8998
|
+
var import_firestore27 = require("firebase/firestore");
|
|
8872
8999
|
var import_geofire_common6 = require("geofire-common");
|
|
8873
9000
|
async function getClinicsByFilters(db, filters) {
|
|
8874
9001
|
var _a;
|
|
@@ -8896,15 +9023,15 @@ async function getClinicsByFilters(db, filters) {
|
|
|
8896
9023
|
const collected = [];
|
|
8897
9024
|
for (const b of bounds) {
|
|
8898
9025
|
const constraints = [
|
|
8899
|
-
(0,
|
|
8900
|
-
(0,
|
|
8901
|
-
(0,
|
|
9026
|
+
(0, import_firestore27.where)("location.geohash", ">=", b[0]),
|
|
9027
|
+
(0, import_firestore27.where)("location.geohash", "<=", b[1]),
|
|
9028
|
+
(0, import_firestore27.where)("isActive", "==", (_a = filters.isActive) != null ? _a : true)
|
|
8902
9029
|
];
|
|
8903
9030
|
if (filters.tags && filters.tags.length > 0) {
|
|
8904
|
-
constraints.push((0,
|
|
9031
|
+
constraints.push((0, import_firestore27.where)("tags", "array-contains", filters.tags[0]));
|
|
8905
9032
|
}
|
|
8906
|
-
const q0 = (0,
|
|
8907
|
-
const snap = await (0,
|
|
9033
|
+
const q0 = (0, import_firestore27.query)((0, import_firestore27.collection)(db, CLINICS_COLLECTION), ...constraints);
|
|
9034
|
+
const snap = await (0, import_firestore27.getDocs)(q0);
|
|
8908
9035
|
snap.docs.forEach((d) => collected.push({ ...d.data(), id: d.id }));
|
|
8909
9036
|
}
|
|
8910
9037
|
const uniqueMap = /* @__PURE__ */ new Map();
|
|
@@ -8932,15 +9059,15 @@ async function getClinicsByFilters(db, filters) {
|
|
|
8932
9059
|
const getBaseConstraints = () => {
|
|
8933
9060
|
var _a2;
|
|
8934
9061
|
const constraints = [];
|
|
8935
|
-
constraints.push((0,
|
|
9062
|
+
constraints.push((0, import_firestore27.where)("isActive", "==", (_a2 = filters.isActive) != null ? _a2 : true));
|
|
8936
9063
|
if (filters.tags && filters.tags.length > 0) {
|
|
8937
|
-
constraints.push((0,
|
|
9064
|
+
constraints.push((0, import_firestore27.where)("tags", "array-contains", filters.tags[0]));
|
|
8938
9065
|
}
|
|
8939
9066
|
if (filters.minRating !== void 0) {
|
|
8940
|
-
constraints.push((0,
|
|
9067
|
+
constraints.push((0, import_firestore27.where)("reviewInfo.averageRating", ">=", filters.minRating));
|
|
8941
9068
|
}
|
|
8942
9069
|
if (filters.maxRating !== void 0) {
|
|
8943
|
-
constraints.push((0,
|
|
9070
|
+
constraints.push((0, import_firestore27.where)("reviewInfo.averageRating", "<=", filters.maxRating));
|
|
8944
9071
|
}
|
|
8945
9072
|
return constraints;
|
|
8946
9073
|
};
|
|
@@ -8949,21 +9076,21 @@ async function getClinicsByFilters(db, filters) {
|
|
|
8949
9076
|
console.log("[CLINIC_SERVICE] Strategy 1: Trying nameLower search");
|
|
8950
9077
|
const searchTerm = filters.nameSearch.trim().toLowerCase();
|
|
8951
9078
|
const constraints = getBaseConstraints();
|
|
8952
|
-
constraints.push((0,
|
|
8953
|
-
constraints.push((0,
|
|
8954
|
-
constraints.push((0,
|
|
9079
|
+
constraints.push((0, import_firestore27.where)("nameLower", ">=", searchTerm));
|
|
9080
|
+
constraints.push((0, import_firestore27.where)("nameLower", "<=", searchTerm + "\uF8FF"));
|
|
9081
|
+
constraints.push((0, import_firestore27.orderBy)("nameLower"));
|
|
8955
9082
|
if (filters.lastDoc) {
|
|
8956
9083
|
if (typeof filters.lastDoc.data === "function") {
|
|
8957
|
-
constraints.push((0,
|
|
9084
|
+
constraints.push((0, import_firestore27.startAfter)(filters.lastDoc));
|
|
8958
9085
|
} else if (Array.isArray(filters.lastDoc)) {
|
|
8959
|
-
constraints.push((0,
|
|
9086
|
+
constraints.push((0, import_firestore27.startAfter)(...filters.lastDoc));
|
|
8960
9087
|
} else {
|
|
8961
|
-
constraints.push((0,
|
|
9088
|
+
constraints.push((0, import_firestore27.startAfter)(filters.lastDoc));
|
|
8962
9089
|
}
|
|
8963
9090
|
}
|
|
8964
|
-
constraints.push((0,
|
|
8965
|
-
const q = (0,
|
|
8966
|
-
const querySnapshot = await (0,
|
|
9091
|
+
constraints.push((0, import_firestore27.limit)(filters.pagination || 5));
|
|
9092
|
+
const q = (0, import_firestore27.query)((0, import_firestore27.collection)(db, CLINICS_COLLECTION), ...constraints);
|
|
9093
|
+
const querySnapshot = await (0, import_firestore27.getDocs)(q);
|
|
8967
9094
|
let clinics = querySnapshot.docs.map((doc38) => ({ ...doc38.data(), id: doc38.id }));
|
|
8968
9095
|
clinics = applyInMemoryFilters(clinics, filters);
|
|
8969
9096
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
@@ -8981,21 +9108,21 @@ async function getClinicsByFilters(db, filters) {
|
|
|
8981
9108
|
console.log("[CLINIC_SERVICE] Strategy 2: Trying name field search");
|
|
8982
9109
|
const searchTerm = filters.nameSearch.trim().toLowerCase();
|
|
8983
9110
|
const constraints = getBaseConstraints();
|
|
8984
|
-
constraints.push((0,
|
|
8985
|
-
constraints.push((0,
|
|
8986
|
-
constraints.push((0,
|
|
9111
|
+
constraints.push((0, import_firestore27.where)("name", ">=", searchTerm));
|
|
9112
|
+
constraints.push((0, import_firestore27.where)("name", "<=", searchTerm + "\uF8FF"));
|
|
9113
|
+
constraints.push((0, import_firestore27.orderBy)("name"));
|
|
8987
9114
|
if (filters.lastDoc) {
|
|
8988
9115
|
if (typeof filters.lastDoc.data === "function") {
|
|
8989
|
-
constraints.push((0,
|
|
9116
|
+
constraints.push((0, import_firestore27.startAfter)(filters.lastDoc));
|
|
8990
9117
|
} else if (Array.isArray(filters.lastDoc)) {
|
|
8991
|
-
constraints.push((0,
|
|
9118
|
+
constraints.push((0, import_firestore27.startAfter)(...filters.lastDoc));
|
|
8992
9119
|
} else {
|
|
8993
|
-
constraints.push((0,
|
|
9120
|
+
constraints.push((0, import_firestore27.startAfter)(filters.lastDoc));
|
|
8994
9121
|
}
|
|
8995
9122
|
}
|
|
8996
|
-
constraints.push((0,
|
|
8997
|
-
const q = (0,
|
|
8998
|
-
const querySnapshot = await (0,
|
|
9123
|
+
constraints.push((0, import_firestore27.limit)(filters.pagination || 5));
|
|
9124
|
+
const q = (0, import_firestore27.query)((0, import_firestore27.collection)(db, CLINICS_COLLECTION), ...constraints);
|
|
9125
|
+
const querySnapshot = await (0, import_firestore27.getDocs)(q);
|
|
8999
9126
|
let clinics = querySnapshot.docs.map((doc38) => ({ ...doc38.data(), id: doc38.id }));
|
|
9000
9127
|
clinics = applyInMemoryFilters(clinics, filters);
|
|
9001
9128
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
@@ -9013,19 +9140,19 @@ async function getClinicsByFilters(db, filters) {
|
|
|
9013
9140
|
"[CLINIC_SERVICE] Strategy 3: Using createdAt ordering with client-side filtering"
|
|
9014
9141
|
);
|
|
9015
9142
|
const constraints = getBaseConstraints();
|
|
9016
|
-
constraints.push((0,
|
|
9143
|
+
constraints.push((0, import_firestore27.orderBy)("createdAt", "desc"));
|
|
9017
9144
|
if (filters.lastDoc) {
|
|
9018
9145
|
if (typeof filters.lastDoc.data === "function") {
|
|
9019
|
-
constraints.push((0,
|
|
9146
|
+
constraints.push((0, import_firestore27.startAfter)(filters.lastDoc));
|
|
9020
9147
|
} else if (Array.isArray(filters.lastDoc)) {
|
|
9021
|
-
constraints.push((0,
|
|
9148
|
+
constraints.push((0, import_firestore27.startAfter)(...filters.lastDoc));
|
|
9022
9149
|
} else {
|
|
9023
|
-
constraints.push((0,
|
|
9150
|
+
constraints.push((0, import_firestore27.startAfter)(filters.lastDoc));
|
|
9024
9151
|
}
|
|
9025
9152
|
}
|
|
9026
|
-
constraints.push((0,
|
|
9027
|
-
const q = (0,
|
|
9028
|
-
const querySnapshot = await (0,
|
|
9153
|
+
constraints.push((0, import_firestore27.limit)(filters.pagination || 5));
|
|
9154
|
+
const q = (0, import_firestore27.query)((0, import_firestore27.collection)(db, CLINICS_COLLECTION), ...constraints);
|
|
9155
|
+
const querySnapshot = await (0, import_firestore27.getDocs)(q);
|
|
9029
9156
|
let clinics = querySnapshot.docs.map((doc38) => ({ ...doc38.data(), id: doc38.id }));
|
|
9030
9157
|
clinics = applyInMemoryFilters(clinics, filters);
|
|
9031
9158
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
@@ -9040,12 +9167,12 @@ async function getClinicsByFilters(db, filters) {
|
|
|
9040
9167
|
try {
|
|
9041
9168
|
console.log("[CLINIC_SERVICE] Strategy 4: Minimal fallback");
|
|
9042
9169
|
const constraints = [
|
|
9043
|
-
(0,
|
|
9044
|
-
(0,
|
|
9045
|
-
(0,
|
|
9170
|
+
(0, import_firestore27.where)("isActive", "==", true),
|
|
9171
|
+
(0, import_firestore27.orderBy)("createdAt", "desc"),
|
|
9172
|
+
(0, import_firestore27.limit)(filters.pagination || 5)
|
|
9046
9173
|
];
|
|
9047
|
-
const q = (0,
|
|
9048
|
-
const querySnapshot = await (0,
|
|
9174
|
+
const q = (0, import_firestore27.query)((0, import_firestore27.collection)(db, CLINICS_COLLECTION), ...constraints);
|
|
9175
|
+
const querySnapshot = await (0, import_firestore27.getDocs)(q);
|
|
9049
9176
|
let clinics = querySnapshot.docs.map((doc38) => ({ ...doc38.data(), id: doc38.id }));
|
|
9050
9177
|
clinics = applyInMemoryFilters(clinics, filters);
|
|
9051
9178
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
@@ -9351,16 +9478,16 @@ var ClinicService = class extends BaseService {
|
|
|
9351
9478
|
isActive: validatedData.isActive !== void 0 ? validatedData.isActive : true,
|
|
9352
9479
|
isVerified: validatedData.isVerified !== void 0 ? validatedData.isVerified : false,
|
|
9353
9480
|
logo: logoUrl,
|
|
9354
|
-
createdAt: (0,
|
|
9355
|
-
updatedAt: (0,
|
|
9481
|
+
createdAt: (0, import_firestore28.serverTimestamp)(),
|
|
9482
|
+
updatedAt: (0, import_firestore28.serverTimestamp)()
|
|
9356
9483
|
};
|
|
9357
|
-
const batch = (0,
|
|
9358
|
-
const clinicRef = (0,
|
|
9484
|
+
const batch = (0, import_firestore28.writeBatch)(this.db);
|
|
9485
|
+
const clinicRef = (0, import_firestore28.doc)(this.db, CLINICS_COLLECTION, clinicId);
|
|
9359
9486
|
batch.set(clinicRef, clinicData);
|
|
9360
|
-
const adminRef = (0,
|
|
9487
|
+
const adminRef = (0, import_firestore28.doc)(this.db, CLINIC_ADMINS_COLLECTION, creatorAdminId);
|
|
9361
9488
|
batch.update(adminRef, {
|
|
9362
|
-
clinicsManaged: (0,
|
|
9363
|
-
updatedAt: (0,
|
|
9489
|
+
clinicsManaged: (0, import_firestore28.arrayUnion)(clinicId),
|
|
9490
|
+
updatedAt: (0, import_firestore28.serverTimestamp)()
|
|
9364
9491
|
});
|
|
9365
9492
|
await batch.commit();
|
|
9366
9493
|
console.log(`[ClinicService] Clinic created successfully: ${clinicId}`);
|
|
@@ -9381,8 +9508,8 @@ var ClinicService = class extends BaseService {
|
|
|
9381
9508
|
*/
|
|
9382
9509
|
async updateClinic(clinicId, data, adminId) {
|
|
9383
9510
|
try {
|
|
9384
|
-
const clinicRef = (0,
|
|
9385
|
-
const clinicDoc = await (0,
|
|
9511
|
+
const clinicRef = (0, import_firestore28.doc)(this.db, CLINICS_COLLECTION, clinicId);
|
|
9512
|
+
const clinicDoc = await (0, import_firestore28.getDoc)(clinicRef);
|
|
9386
9513
|
if (!clinicDoc.exists()) {
|
|
9387
9514
|
throw new Error(`Clinic ${clinicId} not found`);
|
|
9388
9515
|
}
|
|
@@ -9446,8 +9573,8 @@ var ClinicService = class extends BaseService {
|
|
|
9446
9573
|
tz
|
|
9447
9574
|
};
|
|
9448
9575
|
}
|
|
9449
|
-
updatePayload.updatedAt = (0,
|
|
9450
|
-
await (0,
|
|
9576
|
+
updatePayload.updatedAt = (0, import_firestore28.serverTimestamp)();
|
|
9577
|
+
await (0, import_firestore28.updateDoc)(clinicRef, updatePayload);
|
|
9451
9578
|
console.log(`[ClinicService] Clinic ${clinicId} updated successfully`);
|
|
9452
9579
|
const updatedClinic = await this.getClinic(clinicId);
|
|
9453
9580
|
if (!updatedClinic) throw new Error("Failed to retrieve updated clinic");
|
|
@@ -9464,20 +9591,20 @@ var ClinicService = class extends BaseService {
|
|
|
9464
9591
|
* Deactivates a clinic.
|
|
9465
9592
|
*/
|
|
9466
9593
|
async deactivateClinic(clinicId, adminId) {
|
|
9467
|
-
const clinicRef = (0,
|
|
9468
|
-
await (0,
|
|
9594
|
+
const clinicRef = (0, import_firestore28.doc)(this.db, CLINICS_COLLECTION, clinicId);
|
|
9595
|
+
await (0, import_firestore28.updateDoc)(clinicRef, {
|
|
9469
9596
|
isActive: false,
|
|
9470
|
-
updatedAt: (0,
|
|
9597
|
+
updatedAt: (0, import_firestore28.serverTimestamp)()
|
|
9471
9598
|
});
|
|
9472
9599
|
}
|
|
9473
9600
|
/**
|
|
9474
9601
|
* Activates a clinic.
|
|
9475
9602
|
*/
|
|
9476
9603
|
async activateClinic(clinicId, adminId) {
|
|
9477
|
-
const clinicRef = (0,
|
|
9478
|
-
await (0,
|
|
9604
|
+
const clinicRef = (0, import_firestore28.doc)(this.db, CLINICS_COLLECTION, clinicId);
|
|
9605
|
+
await (0, import_firestore28.updateDoc)(clinicRef, {
|
|
9479
9606
|
isActive: true,
|
|
9480
|
-
updatedAt: (0,
|
|
9607
|
+
updatedAt: (0, import_firestore28.serverTimestamp)()
|
|
9481
9608
|
});
|
|
9482
9609
|
}
|
|
9483
9610
|
/**
|
|
@@ -9620,8 +9747,8 @@ var ClinicService = class extends BaseService {
|
|
|
9620
9747
|
* @returns Array of minimal clinic info for map
|
|
9621
9748
|
*/
|
|
9622
9749
|
async getClinicsForMap() {
|
|
9623
|
-
const clinicsRef = (0,
|
|
9624
|
-
const snapshot = await (0,
|
|
9750
|
+
const clinicsRef = (0, import_firestore28.collection)(this.db, CLINICS_COLLECTION);
|
|
9751
|
+
const snapshot = await (0, import_firestore28.getDocs)(clinicsRef);
|
|
9625
9752
|
const clinicsForMap = snapshot.docs.map((doc38) => {
|
|
9626
9753
|
var _a, _b, _c;
|
|
9627
9754
|
const data = doc38.data();
|
|
@@ -9970,9 +10097,9 @@ var AuthService = class extends BaseService {
|
|
|
9970
10097
|
token: data.inviteToken
|
|
9971
10098
|
});
|
|
9972
10099
|
console.log("[AUTH] Searching for token in clinic groups");
|
|
9973
|
-
const groupsRef = (0,
|
|
9974
|
-
const q = (0,
|
|
9975
|
-
const querySnapshot = await (0,
|
|
10100
|
+
const groupsRef = (0, import_firestore29.collection)(this.db, CLINIC_GROUPS_COLLECTION);
|
|
10101
|
+
const q = (0, import_firestore29.query)(groupsRef);
|
|
10102
|
+
const querySnapshot = await (0, import_firestore29.getDocs)(q);
|
|
9976
10103
|
let foundGroup = null;
|
|
9977
10104
|
let foundToken = null;
|
|
9978
10105
|
console.log(
|
|
@@ -10455,7 +10582,7 @@ var AuthService = class extends BaseService {
|
|
|
10455
10582
|
throw handleFirebaseError(firebaseError);
|
|
10456
10583
|
}
|
|
10457
10584
|
console.log("[AUTH] Starting Firestore transaction");
|
|
10458
|
-
const transactionResult = await (0,
|
|
10585
|
+
const transactionResult = await (0, import_firestore29.runTransaction)(
|
|
10459
10586
|
this.db,
|
|
10460
10587
|
async (transaction) => {
|
|
10461
10588
|
console.log(
|
|
@@ -10619,46 +10746,46 @@ var AuthService = class extends BaseService {
|
|
|
10619
10746
|
};
|
|
10620
10747
|
|
|
10621
10748
|
// src/services/calendar/calendar.v2.service.ts
|
|
10622
|
-
var import_firestore36 = require("firebase/firestore");
|
|
10623
10749
|
var import_firestore37 = require("firebase/firestore");
|
|
10750
|
+
var import_firestore38 = require("firebase/firestore");
|
|
10624
10751
|
|
|
10625
10752
|
// src/services/calendar/utils/clinic.utils.ts
|
|
10626
|
-
var
|
|
10753
|
+
var import_firestore31 = require("firebase/firestore");
|
|
10627
10754
|
|
|
10628
10755
|
// src/services/calendar/utils/docs.utils.ts
|
|
10629
|
-
var
|
|
10756
|
+
var import_firestore30 = require("firebase/firestore");
|
|
10630
10757
|
function getPractitionerCalendarEventDocRef(db, practitionerId, eventId) {
|
|
10631
|
-
return (0,
|
|
10758
|
+
return (0, import_firestore30.doc)(
|
|
10632
10759
|
db,
|
|
10633
10760
|
`${PRACTITIONERS_COLLECTION}/${practitionerId}/${CALENDAR_COLLECTION}/${eventId}`
|
|
10634
10761
|
);
|
|
10635
10762
|
}
|
|
10636
10763
|
function getPatientCalendarEventDocRef(db, patientId, eventId) {
|
|
10637
|
-
return (0,
|
|
10764
|
+
return (0, import_firestore30.doc)(
|
|
10638
10765
|
db,
|
|
10639
10766
|
`${PATIENTS_COLLECTION}/${patientId}/${CALENDAR_COLLECTION}/${eventId}`
|
|
10640
10767
|
);
|
|
10641
10768
|
}
|
|
10642
10769
|
function getClinicCalendarEventDocRef(db, clinicId, eventId) {
|
|
10643
|
-
return (0,
|
|
10770
|
+
return (0, import_firestore30.doc)(
|
|
10644
10771
|
db,
|
|
10645
10772
|
`${CLINICS_COLLECTION}/${clinicId}/${CALENDAR_COLLECTION}/${eventId}`
|
|
10646
10773
|
);
|
|
10647
10774
|
}
|
|
10648
10775
|
function getPractitionerSyncedCalendarDocRef(db, practitionerId, syncedCalendarId) {
|
|
10649
|
-
return (0,
|
|
10776
|
+
return (0, import_firestore30.doc)(
|
|
10650
10777
|
db,
|
|
10651
10778
|
`${PRACTITIONERS_COLLECTION}/${practitionerId}/syncedCalendars/${syncedCalendarId}`
|
|
10652
10779
|
);
|
|
10653
10780
|
}
|
|
10654
10781
|
function getPatientSyncedCalendarDocRef(db, patientId, syncedCalendarId) {
|
|
10655
|
-
return (0,
|
|
10782
|
+
return (0, import_firestore30.doc)(
|
|
10656
10783
|
db,
|
|
10657
10784
|
`${PATIENTS_COLLECTION}/${patientId}/syncedCalendars/${syncedCalendarId}`
|
|
10658
10785
|
);
|
|
10659
10786
|
}
|
|
10660
10787
|
function getClinicSyncedCalendarDocRef(db, clinicId, syncedCalendarId) {
|
|
10661
|
-
return (0,
|
|
10788
|
+
return (0, import_firestore30.doc)(
|
|
10662
10789
|
db,
|
|
10663
10790
|
`${CLINICS_COLLECTION}/${clinicId}/syncedCalendars/${syncedCalendarId}`
|
|
10664
10791
|
);
|
|
@@ -10671,31 +10798,31 @@ async function createClinicCalendarEventUtil(db, clinicId, eventData, generateId
|
|
|
10671
10798
|
const newEvent = {
|
|
10672
10799
|
id: eventId,
|
|
10673
10800
|
...eventData,
|
|
10674
|
-
createdAt: (0,
|
|
10675
|
-
updatedAt: (0,
|
|
10801
|
+
createdAt: (0, import_firestore31.serverTimestamp)(),
|
|
10802
|
+
updatedAt: (0, import_firestore31.serverTimestamp)()
|
|
10676
10803
|
};
|
|
10677
|
-
await (0,
|
|
10804
|
+
await (0, import_firestore31.setDoc)(eventRef, newEvent);
|
|
10678
10805
|
return {
|
|
10679
10806
|
...newEvent,
|
|
10680
|
-
createdAt:
|
|
10681
|
-
updatedAt:
|
|
10807
|
+
createdAt: import_firestore31.Timestamp.now(),
|
|
10808
|
+
updatedAt: import_firestore31.Timestamp.now()
|
|
10682
10809
|
};
|
|
10683
10810
|
}
|
|
10684
10811
|
async function updateClinicCalendarEventUtil(db, clinicId, eventId, updateData) {
|
|
10685
10812
|
const eventRef = getClinicCalendarEventDocRef(db, clinicId, eventId);
|
|
10686
10813
|
const updates = {
|
|
10687
10814
|
...updateData,
|
|
10688
|
-
updatedAt: (0,
|
|
10815
|
+
updatedAt: (0, import_firestore31.serverTimestamp)()
|
|
10689
10816
|
};
|
|
10690
|
-
await (0,
|
|
10691
|
-
const updatedDoc = await (0,
|
|
10817
|
+
await (0, import_firestore31.updateDoc)(eventRef, updates);
|
|
10818
|
+
const updatedDoc = await (0, import_firestore31.getDoc)(eventRef);
|
|
10692
10819
|
if (!updatedDoc.exists()) {
|
|
10693
10820
|
throw new Error("Event not found after update");
|
|
10694
10821
|
}
|
|
10695
10822
|
return updatedDoc.data();
|
|
10696
10823
|
}
|
|
10697
10824
|
async function checkAutoConfirmAppointmentsUtil(db, clinicId) {
|
|
10698
|
-
const clinicDoc = await (0,
|
|
10825
|
+
const clinicDoc = await (0, import_firestore31.getDoc)((0, import_firestore31.doc)(db, `clinics/${clinicId}`));
|
|
10699
10826
|
if (!clinicDoc.exists()) {
|
|
10700
10827
|
throw new Error(`Clinic with ID ${clinicId} not found`);
|
|
10701
10828
|
}
|
|
@@ -10704,8 +10831,8 @@ async function checkAutoConfirmAppointmentsUtil(db, clinicId) {
|
|
|
10704
10831
|
if (!clinicGroupId) {
|
|
10705
10832
|
return false;
|
|
10706
10833
|
}
|
|
10707
|
-
const clinicGroupDoc = await (0,
|
|
10708
|
-
(0,
|
|
10834
|
+
const clinicGroupDoc = await (0, import_firestore31.getDoc)(
|
|
10835
|
+
(0, import_firestore31.doc)(db, `${CLINIC_GROUPS_COLLECTION}/${clinicGroupId}`)
|
|
10709
10836
|
);
|
|
10710
10837
|
if (!clinicGroupDoc.exists()) {
|
|
10711
10838
|
return false;
|
|
@@ -10715,31 +10842,31 @@ async function checkAutoConfirmAppointmentsUtil(db, clinicId) {
|
|
|
10715
10842
|
}
|
|
10716
10843
|
|
|
10717
10844
|
// src/services/calendar/utils/patient.utils.ts
|
|
10718
|
-
var
|
|
10845
|
+
var import_firestore32 = require("firebase/firestore");
|
|
10719
10846
|
async function createPatientCalendarEventUtil(db, patientId, eventData, generateId2) {
|
|
10720
10847
|
const eventId = generateId2();
|
|
10721
10848
|
const eventRef = getPatientCalendarEventDocRef(db, patientId, eventId);
|
|
10722
10849
|
const newEvent = {
|
|
10723
10850
|
id: eventId,
|
|
10724
10851
|
...eventData,
|
|
10725
|
-
createdAt: (0,
|
|
10726
|
-
updatedAt: (0,
|
|
10852
|
+
createdAt: (0, import_firestore32.serverTimestamp)(),
|
|
10853
|
+
updatedAt: (0, import_firestore32.serverTimestamp)()
|
|
10727
10854
|
};
|
|
10728
|
-
await (0,
|
|
10855
|
+
await (0, import_firestore32.setDoc)(eventRef, newEvent);
|
|
10729
10856
|
return {
|
|
10730
10857
|
...newEvent,
|
|
10731
|
-
createdAt:
|
|
10732
|
-
updatedAt:
|
|
10858
|
+
createdAt: import_firestore32.Timestamp.now(),
|
|
10859
|
+
updatedAt: import_firestore32.Timestamp.now()
|
|
10733
10860
|
};
|
|
10734
10861
|
}
|
|
10735
10862
|
async function updatePatientCalendarEventUtil(db, patientId, eventId, updateData) {
|
|
10736
10863
|
const eventRef = getPatientCalendarEventDocRef(db, patientId, eventId);
|
|
10737
10864
|
const updates = {
|
|
10738
10865
|
...updateData,
|
|
10739
|
-
updatedAt: (0,
|
|
10866
|
+
updatedAt: (0, import_firestore32.serverTimestamp)()
|
|
10740
10867
|
};
|
|
10741
|
-
await (0,
|
|
10742
|
-
const updatedDoc = await (0,
|
|
10868
|
+
await (0, import_firestore32.updateDoc)(eventRef, updates);
|
|
10869
|
+
const updatedDoc = await (0, import_firestore32.getDoc)(eventRef);
|
|
10743
10870
|
if (!updatedDoc.exists()) {
|
|
10744
10871
|
throw new Error("Event not found after update");
|
|
10745
10872
|
}
|
|
@@ -10747,7 +10874,7 @@ async function updatePatientCalendarEventUtil(db, patientId, eventId, updateData
|
|
|
10747
10874
|
}
|
|
10748
10875
|
|
|
10749
10876
|
// src/services/calendar/utils/practitioner.utils.ts
|
|
10750
|
-
var
|
|
10877
|
+
var import_firestore33 = require("firebase/firestore");
|
|
10751
10878
|
async function createPractitionerCalendarEventUtil(db, practitionerId, eventData, generateId2) {
|
|
10752
10879
|
const eventId = generateId2();
|
|
10753
10880
|
const eventRef = getPractitionerCalendarEventDocRef(
|
|
@@ -10758,14 +10885,14 @@ async function createPractitionerCalendarEventUtil(db, practitionerId, eventData
|
|
|
10758
10885
|
const newEvent = {
|
|
10759
10886
|
id: eventId,
|
|
10760
10887
|
...eventData,
|
|
10761
|
-
createdAt: (0,
|
|
10762
|
-
updatedAt: (0,
|
|
10888
|
+
createdAt: (0, import_firestore33.serverTimestamp)(),
|
|
10889
|
+
updatedAt: (0, import_firestore33.serverTimestamp)()
|
|
10763
10890
|
};
|
|
10764
|
-
await (0,
|
|
10891
|
+
await (0, import_firestore33.setDoc)(eventRef, newEvent);
|
|
10765
10892
|
return {
|
|
10766
10893
|
...newEvent,
|
|
10767
|
-
createdAt:
|
|
10768
|
-
updatedAt:
|
|
10894
|
+
createdAt: import_firestore33.Timestamp.now(),
|
|
10895
|
+
updatedAt: import_firestore33.Timestamp.now()
|
|
10769
10896
|
};
|
|
10770
10897
|
}
|
|
10771
10898
|
async function updatePractitionerCalendarEventUtil(db, practitionerId, eventId, updateData) {
|
|
@@ -10776,10 +10903,10 @@ async function updatePractitionerCalendarEventUtil(db, practitionerId, eventId,
|
|
|
10776
10903
|
);
|
|
10777
10904
|
const updates = {
|
|
10778
10905
|
...updateData,
|
|
10779
|
-
updatedAt: (0,
|
|
10906
|
+
updatedAt: (0, import_firestore33.serverTimestamp)()
|
|
10780
10907
|
};
|
|
10781
|
-
await (0,
|
|
10782
|
-
const updatedDoc = await (0,
|
|
10908
|
+
await (0, import_firestore33.updateDoc)(eventRef, updates);
|
|
10909
|
+
const updatedDoc = await (0, import_firestore33.getDoc)(eventRef);
|
|
10783
10910
|
if (!updatedDoc.exists()) {
|
|
10784
10911
|
throw new Error("Event not found after update");
|
|
10785
10912
|
}
|
|
@@ -10837,7 +10964,7 @@ async function updateAppointmentUtil2(db, clinicId, practitionerId, patientId, e
|
|
|
10837
10964
|
}
|
|
10838
10965
|
|
|
10839
10966
|
// src/services/calendar/utils/calendar-event.utils.ts
|
|
10840
|
-
var
|
|
10967
|
+
var import_firestore34 = require("firebase/firestore");
|
|
10841
10968
|
async function searchCalendarEventsUtil(db, params) {
|
|
10842
10969
|
const { searchLocation, entityId, ...filters } = params;
|
|
10843
10970
|
let baseCollectionPath;
|
|
@@ -10880,7 +11007,7 @@ async function searchCalendarEventsUtil(db, params) {
|
|
|
10880
11007
|
);
|
|
10881
11008
|
}
|
|
10882
11009
|
baseCollectionPath = `${CLINICS_COLLECTION}/${entityId}/${CALENDAR_COLLECTION}`;
|
|
10883
|
-
constraints.push((0,
|
|
11010
|
+
constraints.push((0, import_firestore34.where)("clinicBranchId", "==", entityId));
|
|
10884
11011
|
if (filters.clinicId && filters.clinicId !== entityId) {
|
|
10885
11012
|
console.warn(
|
|
10886
11013
|
`Provided clinicId filter (${filters.clinicId}) does not match search entityId (${entityId}). Returning empty results.`
|
|
@@ -10892,34 +11019,34 @@ async function searchCalendarEventsUtil(db, params) {
|
|
|
10892
11019
|
default:
|
|
10893
11020
|
throw new Error(`Invalid search location: ${searchLocation}`);
|
|
10894
11021
|
}
|
|
10895
|
-
const collectionRef = (0,
|
|
11022
|
+
const collectionRef = (0, import_firestore34.collection)(db, baseCollectionPath);
|
|
10896
11023
|
if (filters.clinicId) {
|
|
10897
|
-
constraints.push((0,
|
|
11024
|
+
constraints.push((0, import_firestore34.where)("clinicBranchId", "==", filters.clinicId));
|
|
10898
11025
|
}
|
|
10899
11026
|
if (filters.practitionerId) {
|
|
10900
11027
|
constraints.push(
|
|
10901
|
-
(0,
|
|
11028
|
+
(0, import_firestore34.where)("practitionerProfileId", "==", filters.practitionerId)
|
|
10902
11029
|
);
|
|
10903
11030
|
}
|
|
10904
11031
|
if (filters.patientId) {
|
|
10905
|
-
constraints.push((0,
|
|
11032
|
+
constraints.push((0, import_firestore34.where)("patientProfileId", "==", filters.patientId));
|
|
10906
11033
|
}
|
|
10907
11034
|
if (filters.procedureId) {
|
|
10908
|
-
constraints.push((0,
|
|
11035
|
+
constraints.push((0, import_firestore34.where)("procedureId", "==", filters.procedureId));
|
|
10909
11036
|
}
|
|
10910
11037
|
if (filters.eventStatus) {
|
|
10911
|
-
constraints.push((0,
|
|
11038
|
+
constraints.push((0, import_firestore34.where)("status", "==", filters.eventStatus));
|
|
10912
11039
|
}
|
|
10913
11040
|
if (filters.eventType) {
|
|
10914
|
-
constraints.push((0,
|
|
11041
|
+
constraints.push((0, import_firestore34.where)("eventType", "==", filters.eventType));
|
|
10915
11042
|
}
|
|
10916
11043
|
if (filters.dateRange) {
|
|
10917
|
-
constraints.push((0,
|
|
10918
|
-
constraints.push((0,
|
|
11044
|
+
constraints.push((0, import_firestore34.where)("eventTime.start", ">=", filters.dateRange.start));
|
|
11045
|
+
constraints.push((0, import_firestore34.where)("eventTime.start", "<=", filters.dateRange.end));
|
|
10919
11046
|
}
|
|
10920
11047
|
try {
|
|
10921
|
-
const finalQuery = (0,
|
|
10922
|
-
const querySnapshot = await (0,
|
|
11048
|
+
const finalQuery = (0, import_firestore34.query)(collectionRef, ...constraints);
|
|
11049
|
+
const querySnapshot = await (0, import_firestore34.getDocs)(finalQuery);
|
|
10923
11050
|
const events = querySnapshot.docs.map(
|
|
10924
11051
|
(doc38) => ({ id: doc38.id, ...doc38.data() })
|
|
10925
11052
|
);
|
|
@@ -10931,7 +11058,7 @@ async function searchCalendarEventsUtil(db, params) {
|
|
|
10931
11058
|
}
|
|
10932
11059
|
|
|
10933
11060
|
// src/services/calendar/utils/synced-calendar.utils.ts
|
|
10934
|
-
var
|
|
11061
|
+
var import_firestore35 = require("firebase/firestore");
|
|
10935
11062
|
async function createPractitionerSyncedCalendarUtil(db, practitionerId, calendarData, generateId2) {
|
|
10936
11063
|
const calendarId = generateId2();
|
|
10937
11064
|
const calendarRef = getPractitionerSyncedCalendarDocRef(
|
|
@@ -10942,14 +11069,14 @@ async function createPractitionerSyncedCalendarUtil(db, practitionerId, calendar
|
|
|
10942
11069
|
const newCalendar = {
|
|
10943
11070
|
id: calendarId,
|
|
10944
11071
|
...calendarData,
|
|
10945
|
-
createdAt: (0,
|
|
10946
|
-
updatedAt: (0,
|
|
11072
|
+
createdAt: (0, import_firestore35.serverTimestamp)(),
|
|
11073
|
+
updatedAt: (0, import_firestore35.serverTimestamp)()
|
|
10947
11074
|
};
|
|
10948
|
-
await (0,
|
|
11075
|
+
await (0, import_firestore35.setDoc)(calendarRef, newCalendar);
|
|
10949
11076
|
return {
|
|
10950
11077
|
...newCalendar,
|
|
10951
|
-
createdAt:
|
|
10952
|
-
updatedAt:
|
|
11078
|
+
createdAt: import_firestore35.Timestamp.now(),
|
|
11079
|
+
updatedAt: import_firestore35.Timestamp.now()
|
|
10953
11080
|
};
|
|
10954
11081
|
}
|
|
10955
11082
|
async function createPatientSyncedCalendarUtil(db, patientId, calendarData, generateId2) {
|
|
@@ -10958,14 +11085,14 @@ async function createPatientSyncedCalendarUtil(db, patientId, calendarData, gene
|
|
|
10958
11085
|
const newCalendar = {
|
|
10959
11086
|
id: calendarId,
|
|
10960
11087
|
...calendarData,
|
|
10961
|
-
createdAt: (0,
|
|
10962
|
-
updatedAt: (0,
|
|
11088
|
+
createdAt: (0, import_firestore35.serverTimestamp)(),
|
|
11089
|
+
updatedAt: (0, import_firestore35.serverTimestamp)()
|
|
10963
11090
|
};
|
|
10964
|
-
await (0,
|
|
11091
|
+
await (0, import_firestore35.setDoc)(calendarRef, newCalendar);
|
|
10965
11092
|
return {
|
|
10966
11093
|
...newCalendar,
|
|
10967
|
-
createdAt:
|
|
10968
|
-
updatedAt:
|
|
11094
|
+
createdAt: import_firestore35.Timestamp.now(),
|
|
11095
|
+
updatedAt: import_firestore35.Timestamp.now()
|
|
10969
11096
|
};
|
|
10970
11097
|
}
|
|
10971
11098
|
async function createClinicSyncedCalendarUtil(db, clinicId, calendarData, generateId2) {
|
|
@@ -10974,14 +11101,14 @@ async function createClinicSyncedCalendarUtil(db, clinicId, calendarData, genera
|
|
|
10974
11101
|
const newCalendar = {
|
|
10975
11102
|
id: calendarId,
|
|
10976
11103
|
...calendarData,
|
|
10977
|
-
createdAt: (0,
|
|
10978
|
-
updatedAt: (0,
|
|
11104
|
+
createdAt: (0, import_firestore35.serverTimestamp)(),
|
|
11105
|
+
updatedAt: (0, import_firestore35.serverTimestamp)()
|
|
10979
11106
|
};
|
|
10980
|
-
await (0,
|
|
11107
|
+
await (0, import_firestore35.setDoc)(calendarRef, newCalendar);
|
|
10981
11108
|
return {
|
|
10982
11109
|
...newCalendar,
|
|
10983
|
-
createdAt:
|
|
10984
|
-
updatedAt:
|
|
11110
|
+
createdAt: import_firestore35.Timestamp.now(),
|
|
11111
|
+
updatedAt: import_firestore35.Timestamp.now()
|
|
10985
11112
|
};
|
|
10986
11113
|
}
|
|
10987
11114
|
async function getPractitionerSyncedCalendarUtil(db, practitionerId, calendarId) {
|
|
@@ -10990,53 +11117,53 @@ async function getPractitionerSyncedCalendarUtil(db, practitionerId, calendarId)
|
|
|
10990
11117
|
practitionerId,
|
|
10991
11118
|
calendarId
|
|
10992
11119
|
);
|
|
10993
|
-
const calendarDoc = await (0,
|
|
11120
|
+
const calendarDoc = await (0, import_firestore35.getDoc)(calendarRef);
|
|
10994
11121
|
if (!calendarDoc.exists()) {
|
|
10995
11122
|
return null;
|
|
10996
11123
|
}
|
|
10997
11124
|
return calendarDoc.data();
|
|
10998
11125
|
}
|
|
10999
11126
|
async function getPractitionerSyncedCalendarsUtil(db, practitionerId) {
|
|
11000
|
-
const calendarsRef = (0,
|
|
11127
|
+
const calendarsRef = (0, import_firestore35.collection)(
|
|
11001
11128
|
db,
|
|
11002
11129
|
`practitioners/${practitionerId}/${SYNCED_CALENDARS_COLLECTION}`
|
|
11003
11130
|
);
|
|
11004
|
-
const q = (0,
|
|
11005
|
-
const querySnapshot = await (0,
|
|
11131
|
+
const q = (0, import_firestore35.query)(calendarsRef, (0, import_firestore35.orderBy)("createdAt", "desc"));
|
|
11132
|
+
const querySnapshot = await (0, import_firestore35.getDocs)(q);
|
|
11006
11133
|
return querySnapshot.docs.map((doc38) => doc38.data());
|
|
11007
11134
|
}
|
|
11008
11135
|
async function getPatientSyncedCalendarUtil(db, patientId, calendarId) {
|
|
11009
11136
|
const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
|
|
11010
|
-
const calendarDoc = await (0,
|
|
11137
|
+
const calendarDoc = await (0, import_firestore35.getDoc)(calendarRef);
|
|
11011
11138
|
if (!calendarDoc.exists()) {
|
|
11012
11139
|
return null;
|
|
11013
11140
|
}
|
|
11014
11141
|
return calendarDoc.data();
|
|
11015
11142
|
}
|
|
11016
11143
|
async function getPatientSyncedCalendarsUtil(db, patientId) {
|
|
11017
|
-
const calendarsRef = (0,
|
|
11144
|
+
const calendarsRef = (0, import_firestore35.collection)(
|
|
11018
11145
|
db,
|
|
11019
11146
|
`patients/${patientId}/${SYNCED_CALENDARS_COLLECTION}`
|
|
11020
11147
|
);
|
|
11021
|
-
const q = (0,
|
|
11022
|
-
const querySnapshot = await (0,
|
|
11148
|
+
const q = (0, import_firestore35.query)(calendarsRef, (0, import_firestore35.orderBy)("createdAt", "desc"));
|
|
11149
|
+
const querySnapshot = await (0, import_firestore35.getDocs)(q);
|
|
11023
11150
|
return querySnapshot.docs.map((doc38) => doc38.data());
|
|
11024
11151
|
}
|
|
11025
11152
|
async function getClinicSyncedCalendarUtil(db, clinicId, calendarId) {
|
|
11026
11153
|
const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
|
|
11027
|
-
const calendarDoc = await (0,
|
|
11154
|
+
const calendarDoc = await (0, import_firestore35.getDoc)(calendarRef);
|
|
11028
11155
|
if (!calendarDoc.exists()) {
|
|
11029
11156
|
return null;
|
|
11030
11157
|
}
|
|
11031
11158
|
return calendarDoc.data();
|
|
11032
11159
|
}
|
|
11033
11160
|
async function getClinicSyncedCalendarsUtil(db, clinicId) {
|
|
11034
|
-
const calendarsRef = (0,
|
|
11161
|
+
const calendarsRef = (0, import_firestore35.collection)(
|
|
11035
11162
|
db,
|
|
11036
11163
|
`clinics/${clinicId}/${SYNCED_CALENDARS_COLLECTION}`
|
|
11037
11164
|
);
|
|
11038
|
-
const q = (0,
|
|
11039
|
-
const querySnapshot = await (0,
|
|
11165
|
+
const q = (0, import_firestore35.query)(calendarsRef, (0, import_firestore35.orderBy)("createdAt", "desc"));
|
|
11166
|
+
const querySnapshot = await (0, import_firestore35.getDocs)(q);
|
|
11040
11167
|
return querySnapshot.docs.map((doc38) => doc38.data());
|
|
11041
11168
|
}
|
|
11042
11169
|
async function updatePractitionerSyncedCalendarUtil(db, practitionerId, calendarId, updateData) {
|
|
@@ -11047,10 +11174,10 @@ async function updatePractitionerSyncedCalendarUtil(db, practitionerId, calendar
|
|
|
11047
11174
|
);
|
|
11048
11175
|
const updates = {
|
|
11049
11176
|
...updateData,
|
|
11050
|
-
updatedAt: (0,
|
|
11177
|
+
updatedAt: (0, import_firestore35.serverTimestamp)()
|
|
11051
11178
|
};
|
|
11052
|
-
await (0,
|
|
11053
|
-
const updatedDoc = await (0,
|
|
11179
|
+
await (0, import_firestore35.updateDoc)(calendarRef, updates);
|
|
11180
|
+
const updatedDoc = await (0, import_firestore35.getDoc)(calendarRef);
|
|
11054
11181
|
if (!updatedDoc.exists()) {
|
|
11055
11182
|
throw new Error("Synced calendar not found after update");
|
|
11056
11183
|
}
|
|
@@ -11060,10 +11187,10 @@ async function updatePatientSyncedCalendarUtil(db, patientId, calendarId, update
|
|
|
11060
11187
|
const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
|
|
11061
11188
|
const updates = {
|
|
11062
11189
|
...updateData,
|
|
11063
|
-
updatedAt: (0,
|
|
11190
|
+
updatedAt: (0, import_firestore35.serverTimestamp)()
|
|
11064
11191
|
};
|
|
11065
|
-
await (0,
|
|
11066
|
-
const updatedDoc = await (0,
|
|
11192
|
+
await (0, import_firestore35.updateDoc)(calendarRef, updates);
|
|
11193
|
+
const updatedDoc = await (0, import_firestore35.getDoc)(calendarRef);
|
|
11067
11194
|
if (!updatedDoc.exists()) {
|
|
11068
11195
|
throw new Error("Synced calendar not found after update");
|
|
11069
11196
|
}
|
|
@@ -11073,10 +11200,10 @@ async function updateClinicSyncedCalendarUtil(db, clinicId, calendarId, updateDa
|
|
|
11073
11200
|
const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
|
|
11074
11201
|
const updates = {
|
|
11075
11202
|
...updateData,
|
|
11076
|
-
updatedAt: (0,
|
|
11203
|
+
updatedAt: (0, import_firestore35.serverTimestamp)()
|
|
11077
11204
|
};
|
|
11078
|
-
await (0,
|
|
11079
|
-
const updatedDoc = await (0,
|
|
11205
|
+
await (0, import_firestore35.updateDoc)(calendarRef, updates);
|
|
11206
|
+
const updatedDoc = await (0, import_firestore35.getDoc)(calendarRef);
|
|
11080
11207
|
if (!updatedDoc.exists()) {
|
|
11081
11208
|
throw new Error("Synced calendar not found after update");
|
|
11082
11209
|
}
|
|
@@ -11088,19 +11215,19 @@ async function deletePractitionerSyncedCalendarUtil(db, practitionerId, calendar
|
|
|
11088
11215
|
practitionerId,
|
|
11089
11216
|
calendarId
|
|
11090
11217
|
);
|
|
11091
|
-
await (0,
|
|
11218
|
+
await (0, import_firestore35.deleteDoc)(calendarRef);
|
|
11092
11219
|
}
|
|
11093
11220
|
async function deletePatientSyncedCalendarUtil(db, patientId, calendarId) {
|
|
11094
11221
|
const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
|
|
11095
|
-
await (0,
|
|
11222
|
+
await (0, import_firestore35.deleteDoc)(calendarRef);
|
|
11096
11223
|
}
|
|
11097
11224
|
async function deleteClinicSyncedCalendarUtil(db, clinicId, calendarId) {
|
|
11098
11225
|
const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
|
|
11099
|
-
await (0,
|
|
11226
|
+
await (0, import_firestore35.deleteDoc)(calendarRef);
|
|
11100
11227
|
}
|
|
11101
11228
|
async function updateLastSyncedTimestampUtil(db, entityType, entityId, calendarId) {
|
|
11102
11229
|
const updateData = {
|
|
11103
|
-
lastSyncedAt:
|
|
11230
|
+
lastSyncedAt: import_firestore35.Timestamp.now()
|
|
11104
11231
|
};
|
|
11105
11232
|
switch (entityType) {
|
|
11106
11233
|
case "practitioner":
|
|
@@ -11130,7 +11257,7 @@ async function updateLastSyncedTimestampUtil(db, entityType, entityId, calendarI
|
|
|
11130
11257
|
}
|
|
11131
11258
|
|
|
11132
11259
|
// src/services/calendar/utils/google-calendar.utils.ts
|
|
11133
|
-
var
|
|
11260
|
+
var import_firestore36 = require("firebase/firestore");
|
|
11134
11261
|
var GOOGLE_CALENDAR_API_URL = "https://www.googleapis.com/calendar/v3";
|
|
11135
11262
|
var GOOGLE_OAUTH_URL = "https://oauth2.googleapis.com/token";
|
|
11136
11263
|
var CLIENT_ID = "your-client-id";
|
|
@@ -11250,7 +11377,7 @@ async function ensureValidToken(db, entityType, entityId, syncedCalendar) {
|
|
|
11250
11377
|
tokenExpiry.setSeconds(tokenExpiry.getSeconds() + expiresIn);
|
|
11251
11378
|
const updateData = {
|
|
11252
11379
|
accessToken,
|
|
11253
|
-
tokenExpiry:
|
|
11380
|
+
tokenExpiry: import_firestore36.Timestamp.fromDate(tokenExpiry)
|
|
11254
11381
|
};
|
|
11255
11382
|
switch (entityType) {
|
|
11256
11383
|
case "practitioner":
|
|
@@ -11425,8 +11552,8 @@ function convertGoogleEventToCalendarEventUtil(googleEvent, entityId, entityType
|
|
|
11425
11552
|
eventName: googleEvent.summary || "External Event",
|
|
11426
11553
|
eventLocation: googleEvent.location,
|
|
11427
11554
|
eventTime: {
|
|
11428
|
-
start:
|
|
11429
|
-
end:
|
|
11555
|
+
start: import_firestore36.Timestamp.fromDate(start),
|
|
11556
|
+
end: import_firestore36.Timestamp.fromDate(end)
|
|
11430
11557
|
},
|
|
11431
11558
|
description: googleEvent.description || "",
|
|
11432
11559
|
// External events are always set as CONFIRMED - status updates will happen externally
|
|
@@ -11440,7 +11567,7 @@ function convertGoogleEventToCalendarEventUtil(googleEvent, entityId, entityType
|
|
|
11440
11567
|
{
|
|
11441
11568
|
eventId: googleEvent.id,
|
|
11442
11569
|
syncedCalendarProvider: "google" /* GOOGLE */,
|
|
11443
|
-
syncedAt:
|
|
11570
|
+
syncedAt: import_firestore36.Timestamp.now()
|
|
11444
11571
|
}
|
|
11445
11572
|
]
|
|
11446
11573
|
};
|
|
@@ -12218,7 +12345,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12218
12345
|
return 0;
|
|
12219
12346
|
}
|
|
12220
12347
|
let importedEventsCount = 0;
|
|
12221
|
-
const currentTime =
|
|
12348
|
+
const currentTime = import_firestore37.Timestamp.now();
|
|
12222
12349
|
for (const calendar of activeCalendars) {
|
|
12223
12350
|
try {
|
|
12224
12351
|
let externalEvents = [];
|
|
@@ -12285,7 +12412,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12285
12412
|
async createDoctorBlockingEvent(doctorId, eventData) {
|
|
12286
12413
|
try {
|
|
12287
12414
|
const eventId = this.generateId();
|
|
12288
|
-
const eventRef = (0,
|
|
12415
|
+
const eventRef = (0, import_firestore38.doc)(
|
|
12289
12416
|
this.db,
|
|
12290
12417
|
PRACTITIONERS_COLLECTION,
|
|
12291
12418
|
doctorId,
|
|
@@ -12295,14 +12422,14 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12295
12422
|
const newEvent = {
|
|
12296
12423
|
id: eventId,
|
|
12297
12424
|
...eventData,
|
|
12298
|
-
createdAt: (0,
|
|
12299
|
-
updatedAt: (0,
|
|
12425
|
+
createdAt: (0, import_firestore37.serverTimestamp)(),
|
|
12426
|
+
updatedAt: (0, import_firestore37.serverTimestamp)()
|
|
12300
12427
|
};
|
|
12301
|
-
await (0,
|
|
12428
|
+
await (0, import_firestore38.setDoc)(eventRef, newEvent);
|
|
12302
12429
|
return {
|
|
12303
12430
|
...newEvent,
|
|
12304
|
-
createdAt:
|
|
12305
|
-
updatedAt:
|
|
12431
|
+
createdAt: import_firestore37.Timestamp.now(),
|
|
12432
|
+
updatedAt: import_firestore37.Timestamp.now()
|
|
12306
12433
|
};
|
|
12307
12434
|
} catch (error) {
|
|
12308
12435
|
console.error(
|
|
@@ -12320,8 +12447,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12320
12447
|
*/
|
|
12321
12448
|
async synchronizeExternalCalendars(lookbackDays = 7, lookforwardDays = 30) {
|
|
12322
12449
|
try {
|
|
12323
|
-
const practitionersRef = (0,
|
|
12324
|
-
const practitionersSnapshot = await (0,
|
|
12450
|
+
const practitionersRef = (0, import_firestore38.collection)(this.db, PRACTITIONERS_COLLECTION);
|
|
12451
|
+
const practitionersSnapshot = await (0, import_firestore38.getDocs)(practitionersRef);
|
|
12325
12452
|
const startDate = /* @__PURE__ */ new Date();
|
|
12326
12453
|
startDate.setDate(startDate.getDate() - lookbackDays);
|
|
12327
12454
|
const endDate = /* @__PURE__ */ new Date();
|
|
@@ -12379,19 +12506,19 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12379
12506
|
async updateExistingEventsFromExternalCalendars(doctorId, startDate, endDate) {
|
|
12380
12507
|
var _a;
|
|
12381
12508
|
try {
|
|
12382
|
-
const eventsRef = (0,
|
|
12509
|
+
const eventsRef = (0, import_firestore38.collection)(
|
|
12383
12510
|
this.db,
|
|
12384
12511
|
PRACTITIONERS_COLLECTION,
|
|
12385
12512
|
doctorId,
|
|
12386
12513
|
CALENDAR_COLLECTION
|
|
12387
12514
|
);
|
|
12388
|
-
const q = (0,
|
|
12515
|
+
const q = (0, import_firestore38.query)(
|
|
12389
12516
|
eventsRef,
|
|
12390
|
-
(0,
|
|
12391
|
-
(0,
|
|
12392
|
-
(0,
|
|
12517
|
+
(0, import_firestore38.where)("syncStatus", "==", "external" /* EXTERNAL */),
|
|
12518
|
+
(0, import_firestore38.where)("eventTime.start", ">=", import_firestore37.Timestamp.fromDate(startDate)),
|
|
12519
|
+
(0, import_firestore38.where)("eventTime.start", "<=", import_firestore37.Timestamp.fromDate(endDate))
|
|
12393
12520
|
);
|
|
12394
|
-
const eventsSnapshot = await (0,
|
|
12521
|
+
const eventsSnapshot = await (0, import_firestore38.getDocs)(q);
|
|
12395
12522
|
const events = eventsSnapshot.docs.map((doc38) => ({
|
|
12396
12523
|
id: doc38.id,
|
|
12397
12524
|
...doc38.data()
|
|
@@ -12498,21 +12625,21 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12498
12625
|
const endTime = new Date(
|
|
12499
12626
|
externalEvent.end.dateTime || externalEvent.end.date
|
|
12500
12627
|
);
|
|
12501
|
-
const eventRef = (0,
|
|
12628
|
+
const eventRef = (0, import_firestore38.doc)(
|
|
12502
12629
|
this.db,
|
|
12503
12630
|
PRACTITIONERS_COLLECTION,
|
|
12504
12631
|
doctorId,
|
|
12505
12632
|
CALENDAR_COLLECTION,
|
|
12506
12633
|
eventId
|
|
12507
12634
|
);
|
|
12508
|
-
await (0,
|
|
12635
|
+
await (0, import_firestore38.updateDoc)(eventRef, {
|
|
12509
12636
|
eventName: externalEvent.summary || "External Event",
|
|
12510
12637
|
eventTime: {
|
|
12511
|
-
start:
|
|
12512
|
-
end:
|
|
12638
|
+
start: import_firestore37.Timestamp.fromDate(startTime),
|
|
12639
|
+
end: import_firestore37.Timestamp.fromDate(endTime)
|
|
12513
12640
|
},
|
|
12514
12641
|
description: externalEvent.description || "",
|
|
12515
|
-
updatedAt: (0,
|
|
12642
|
+
updatedAt: (0, import_firestore37.serverTimestamp)()
|
|
12516
12643
|
});
|
|
12517
12644
|
console.log(`Updated local event ${eventId} from external event`);
|
|
12518
12645
|
} catch (error) {
|
|
@@ -12530,16 +12657,16 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12530
12657
|
*/
|
|
12531
12658
|
async updateEventStatus(doctorId, eventId, status) {
|
|
12532
12659
|
try {
|
|
12533
|
-
const eventRef = (0,
|
|
12660
|
+
const eventRef = (0, import_firestore38.doc)(
|
|
12534
12661
|
this.db,
|
|
12535
12662
|
PRACTITIONERS_COLLECTION,
|
|
12536
12663
|
doctorId,
|
|
12537
12664
|
CALENDAR_COLLECTION,
|
|
12538
12665
|
eventId
|
|
12539
12666
|
);
|
|
12540
|
-
await (0,
|
|
12667
|
+
await (0, import_firestore38.updateDoc)(eventRef, {
|
|
12541
12668
|
status,
|
|
12542
|
-
updatedAt: (0,
|
|
12669
|
+
updatedAt: (0, import_firestore37.serverTimestamp)()
|
|
12543
12670
|
});
|
|
12544
12671
|
console.log(`Updated event ${eventId} status to ${status}`);
|
|
12545
12672
|
} catch (error) {
|
|
@@ -12587,8 +12714,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12587
12714
|
*/
|
|
12588
12715
|
async getPractitionerUpcomingAppointments(doctorId, startDate, endDate, status = "confirmed" /* CONFIRMED */) {
|
|
12589
12716
|
const dateRange = {
|
|
12590
|
-
start:
|
|
12591
|
-
end:
|
|
12717
|
+
start: import_firestore37.Timestamp.fromDate(startDate),
|
|
12718
|
+
end: import_firestore37.Timestamp.fromDate(endDate)
|
|
12592
12719
|
};
|
|
12593
12720
|
const searchParams = {
|
|
12594
12721
|
searchLocation: "practitioner" /* PRACTITIONER */,
|
|
@@ -12610,8 +12737,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12610
12737
|
*/
|
|
12611
12738
|
async getPatientAppointments(patientId, startDate, endDate, status) {
|
|
12612
12739
|
const dateRange = {
|
|
12613
|
-
start:
|
|
12614
|
-
end:
|
|
12740
|
+
start: import_firestore37.Timestamp.fromDate(startDate),
|
|
12741
|
+
end: import_firestore37.Timestamp.fromDate(endDate)
|
|
12615
12742
|
};
|
|
12616
12743
|
const searchParams = {
|
|
12617
12744
|
searchLocation: "patient" /* PATIENT */,
|
|
@@ -12636,8 +12763,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12636
12763
|
*/
|
|
12637
12764
|
async getClinicAppointments(clinicId, startDate, endDate, doctorId, status) {
|
|
12638
12765
|
const dateRange = {
|
|
12639
|
-
start:
|
|
12640
|
-
end:
|
|
12766
|
+
start: import_firestore37.Timestamp.fromDate(startDate),
|
|
12767
|
+
end: import_firestore37.Timestamp.fromDate(endDate)
|
|
12641
12768
|
};
|
|
12642
12769
|
const searchParams = {
|
|
12643
12770
|
searchLocation: "clinic" /* CLINIC */,
|
|
@@ -12696,8 +12823,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12696
12823
|
const startDate = eventTime.start.toDate();
|
|
12697
12824
|
const startTime = startDate;
|
|
12698
12825
|
const endTime = eventTime.end.toDate();
|
|
12699
|
-
const practitionerRef = (0,
|
|
12700
|
-
const practitionerDoc = await (0,
|
|
12826
|
+
const practitionerRef = (0, import_firestore38.doc)(this.db, PRACTITIONERS_COLLECTION, doctorId);
|
|
12827
|
+
const practitionerDoc = await (0, import_firestore38.getDoc)(practitionerRef);
|
|
12701
12828
|
if (!practitionerDoc.exists()) {
|
|
12702
12829
|
throw new Error(`Doctor with ID ${doctorId} not found`);
|
|
12703
12830
|
}
|
|
@@ -12755,8 +12882,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12755
12882
|
*/
|
|
12756
12883
|
async updateAppointmentStatus(appointmentId, clinicId, status) {
|
|
12757
12884
|
const baseCollectionPath = `${CLINICS_COLLECTION}/${clinicId}/${CALENDAR_COLLECTION}`;
|
|
12758
|
-
const appointmentRef = (0,
|
|
12759
|
-
const appointmentDoc = await (0,
|
|
12885
|
+
const appointmentRef = (0, import_firestore38.doc)(this.db, baseCollectionPath, appointmentId);
|
|
12886
|
+
const appointmentDoc = await (0, import_firestore38.getDoc)(appointmentRef);
|
|
12760
12887
|
if (!appointmentDoc.exists()) {
|
|
12761
12888
|
throw new Error(`Appointment with ID ${appointmentId} not found`);
|
|
12762
12889
|
}
|
|
@@ -12891,7 +13018,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12891
13018
|
const newSyncEvent = {
|
|
12892
13019
|
eventId: result.eventIds[0],
|
|
12893
13020
|
syncedCalendarProvider: calendar.provider,
|
|
12894
|
-
syncedAt:
|
|
13021
|
+
syncedAt: import_firestore37.Timestamp.now()
|
|
12895
13022
|
};
|
|
12896
13023
|
await this.updateEventWithSyncId(
|
|
12897
13024
|
entityType === "doctor" ? appointment.practitionerProfileId : appointment.patientProfileId,
|
|
@@ -12915,8 +13042,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12915
13042
|
async updateEventWithSyncId(entityId, entityType, eventId, syncEvent) {
|
|
12916
13043
|
try {
|
|
12917
13044
|
const collectionPath = entityType === "doctor" ? `${PRACTITIONERS_COLLECTION}/${entityId}/${CALENDAR_COLLECTION}` : `${PATIENTS_COLLECTION}/${entityId}/${CALENDAR_COLLECTION}`;
|
|
12918
|
-
const eventRef = (0,
|
|
12919
|
-
const eventDoc = await (0,
|
|
13045
|
+
const eventRef = (0, import_firestore38.doc)(this.db, collectionPath, eventId);
|
|
13046
|
+
const eventDoc = await (0, import_firestore38.getDoc)(eventRef);
|
|
12920
13047
|
if (eventDoc.exists()) {
|
|
12921
13048
|
const event = eventDoc.data();
|
|
12922
13049
|
const syncIds = [...event.syncedCalendarEventId || []];
|
|
@@ -12928,9 +13055,9 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12928
13055
|
} else {
|
|
12929
13056
|
syncIds.push(syncEvent);
|
|
12930
13057
|
}
|
|
12931
|
-
await (0,
|
|
13058
|
+
await (0, import_firestore38.updateDoc)(eventRef, {
|
|
12932
13059
|
syncedCalendarEventId: syncIds,
|
|
12933
|
-
updatedAt: (0,
|
|
13060
|
+
updatedAt: (0, import_firestore37.serverTimestamp)()
|
|
12934
13061
|
});
|
|
12935
13062
|
console.log(
|
|
12936
13063
|
`Updated event ${eventId} with sync ID ${syncEvent.eventId}`
|
|
@@ -12954,8 +13081,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12954
13081
|
* @returns Working hours for the clinic
|
|
12955
13082
|
*/
|
|
12956
13083
|
async getClinicWorkingHours(clinicId, date) {
|
|
12957
|
-
const clinicRef = (0,
|
|
12958
|
-
const clinicDoc = await (0,
|
|
13084
|
+
const clinicRef = (0, import_firestore38.doc)(this.db, CLINICS_COLLECTION, clinicId);
|
|
13085
|
+
const clinicDoc = await (0, import_firestore38.getDoc)(clinicRef);
|
|
12959
13086
|
if (!clinicDoc.exists()) {
|
|
12960
13087
|
throw new Error(`Clinic with ID ${clinicId} not found`);
|
|
12961
13088
|
}
|
|
@@ -12983,8 +13110,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
12983
13110
|
* @returns Doctor's schedule
|
|
12984
13111
|
*/
|
|
12985
13112
|
async getDoctorSchedule(doctorId, date) {
|
|
12986
|
-
const practitionerRef = (0,
|
|
12987
|
-
const practitionerDoc = await (0,
|
|
13113
|
+
const practitionerRef = (0, import_firestore38.doc)(this.db, PRACTITIONERS_COLLECTION, doctorId);
|
|
13114
|
+
const practitionerDoc = await (0, import_firestore38.getDoc)(practitionerRef);
|
|
12988
13115
|
if (!practitionerDoc.exists()) {
|
|
12989
13116
|
throw new Error(`Doctor with ID ${doctorId} not found`);
|
|
12990
13117
|
}
|
|
@@ -13016,18 +13143,18 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
13016
13143
|
startOfDay.setHours(0, 0, 0, 0);
|
|
13017
13144
|
const endOfDay = new Date(date);
|
|
13018
13145
|
endOfDay.setHours(23, 59, 59, 999);
|
|
13019
|
-
const appointmentsRef = (0,
|
|
13020
|
-
const q = (0,
|
|
13146
|
+
const appointmentsRef = (0, import_firestore38.collection)(this.db, CALENDAR_COLLECTION);
|
|
13147
|
+
const q = (0, import_firestore38.query)(
|
|
13021
13148
|
appointmentsRef,
|
|
13022
|
-
(0,
|
|
13023
|
-
(0,
|
|
13024
|
-
(0,
|
|
13025
|
-
(0,
|
|
13149
|
+
(0, import_firestore38.where)("practitionerProfileId", "==", doctorId),
|
|
13150
|
+
(0, import_firestore38.where)("eventTime.start", ">=", import_firestore37.Timestamp.fromDate(startOfDay)),
|
|
13151
|
+
(0, import_firestore38.where)("eventTime.start", "<=", import_firestore37.Timestamp.fromDate(endOfDay)),
|
|
13152
|
+
(0, import_firestore38.where)("status", "in", [
|
|
13026
13153
|
"confirmed" /* CONFIRMED */,
|
|
13027
13154
|
"pending" /* PENDING */
|
|
13028
13155
|
])
|
|
13029
13156
|
);
|
|
13030
|
-
const querySnapshot = await (0,
|
|
13157
|
+
const querySnapshot = await (0, import_firestore38.getDocs)(q);
|
|
13031
13158
|
return querySnapshot.docs.map((doc38) => doc38.data());
|
|
13032
13159
|
}
|
|
13033
13160
|
/**
|
|
@@ -13085,11 +13212,11 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
13085
13212
|
var _a;
|
|
13086
13213
|
try {
|
|
13087
13214
|
const [clinicDoc, practitionerDoc, patientDoc, patientSensitiveInfoDoc] = await Promise.all([
|
|
13088
|
-
(0,
|
|
13089
|
-
(0,
|
|
13090
|
-
(0,
|
|
13091
|
-
(0,
|
|
13092
|
-
(0,
|
|
13215
|
+
(0, import_firestore38.getDoc)((0, import_firestore38.doc)(this.db, CLINICS_COLLECTION, clinicId)),
|
|
13216
|
+
(0, import_firestore38.getDoc)((0, import_firestore38.doc)(this.db, PRACTITIONERS_COLLECTION, doctorId)),
|
|
13217
|
+
(0, import_firestore38.getDoc)((0, import_firestore38.doc)(this.db, PATIENTS_COLLECTION, patientId)),
|
|
13218
|
+
(0, import_firestore38.getDoc)(
|
|
13219
|
+
(0, import_firestore38.doc)(
|
|
13093
13220
|
this.db,
|
|
13094
13221
|
PATIENTS_COLLECTION,
|
|
13095
13222
|
patientId,
|
|
@@ -13122,7 +13249,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
13122
13249
|
fullName: `${sensitiveData.firstName} ${sensitiveData.lastName}`,
|
|
13123
13250
|
email: sensitiveData.email || "",
|
|
13124
13251
|
phone: sensitiveData.phoneNumber || null,
|
|
13125
|
-
dateOfBirth: sensitiveData.dateOfBirth ||
|
|
13252
|
+
dateOfBirth: sensitiveData.dateOfBirth || import_firestore37.Timestamp.now(),
|
|
13126
13253
|
gender: sensitiveData.gender || "other" /* OTHER */
|
|
13127
13254
|
};
|
|
13128
13255
|
} else if (patientDoc.exists()) {
|
|
@@ -13131,7 +13258,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
13131
13258
|
fullName: patientDoc.data().displayName,
|
|
13132
13259
|
email: ((_a = patientDoc.data().contactInfo) == null ? void 0 : _a.email) || "",
|
|
13133
13260
|
phone: patientDoc.data().phoneNumber || null,
|
|
13134
|
-
dateOfBirth: patientDoc.data().dateOfBirth ||
|
|
13261
|
+
dateOfBirth: patientDoc.data().dateOfBirth || import_firestore37.Timestamp.now(),
|
|
13135
13262
|
gender: patientDoc.data().gender || "other" /* OTHER */
|
|
13136
13263
|
};
|
|
13137
13264
|
}
|
|
@@ -13153,8 +13280,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
13153
13280
|
};
|
|
13154
13281
|
|
|
13155
13282
|
// src/services/calendar/calendar.v3.service.ts
|
|
13156
|
-
var import_firestore38 = require("firebase/firestore");
|
|
13157
13283
|
var import_firestore39 = require("firebase/firestore");
|
|
13284
|
+
var import_firestore40 = require("firebase/firestore");
|
|
13158
13285
|
var CalendarServiceV3 = class extends BaseService {
|
|
13159
13286
|
/**
|
|
13160
13287
|
* Creates a new CalendarServiceV3 instance
|
|
@@ -13178,7 +13305,7 @@ var CalendarServiceV3 = class extends BaseService {
|
|
|
13178
13305
|
params.entityType,
|
|
13179
13306
|
params.entityId
|
|
13180
13307
|
);
|
|
13181
|
-
const eventRef = (0,
|
|
13308
|
+
const eventRef = (0, import_firestore40.doc)(this.db, collectionPath, eventId);
|
|
13182
13309
|
const eventData = {
|
|
13183
13310
|
id: eventId,
|
|
13184
13311
|
eventName: params.eventName,
|
|
@@ -13188,19 +13315,19 @@ var CalendarServiceV3 = class extends BaseService {
|
|
|
13188
13315
|
status: "confirmed" /* CONFIRMED */,
|
|
13189
13316
|
// Blocking events are always confirmed
|
|
13190
13317
|
syncStatus: "internal" /* INTERNAL */,
|
|
13191
|
-
createdAt: (0,
|
|
13192
|
-
updatedAt: (0,
|
|
13318
|
+
createdAt: (0, import_firestore39.serverTimestamp)(),
|
|
13319
|
+
updatedAt: (0, import_firestore39.serverTimestamp)()
|
|
13193
13320
|
};
|
|
13194
13321
|
if (params.entityType === "practitioner") {
|
|
13195
13322
|
eventData.practitionerProfileId = params.entityId;
|
|
13196
13323
|
} else {
|
|
13197
13324
|
eventData.clinicBranchId = params.entityId;
|
|
13198
13325
|
}
|
|
13199
|
-
await (0,
|
|
13326
|
+
await (0, import_firestore40.setDoc)(eventRef, eventData);
|
|
13200
13327
|
return {
|
|
13201
13328
|
...eventData,
|
|
13202
|
-
createdAt:
|
|
13203
|
-
updatedAt:
|
|
13329
|
+
createdAt: import_firestore39.Timestamp.now(),
|
|
13330
|
+
updatedAt: import_firestore39.Timestamp.now()
|
|
13204
13331
|
};
|
|
13205
13332
|
}
|
|
13206
13333
|
/**
|
|
@@ -13213,13 +13340,13 @@ var CalendarServiceV3 = class extends BaseService {
|
|
|
13213
13340
|
params.entityType,
|
|
13214
13341
|
params.entityId
|
|
13215
13342
|
);
|
|
13216
|
-
const eventRef = (0,
|
|
13217
|
-
const eventDoc = await (0,
|
|
13343
|
+
const eventRef = (0, import_firestore40.doc)(this.db, collectionPath, params.eventId);
|
|
13344
|
+
const eventDoc = await (0, import_firestore40.getDoc)(eventRef);
|
|
13218
13345
|
if (!eventDoc.exists()) {
|
|
13219
13346
|
throw new Error(`Blocking event with ID ${params.eventId} not found`);
|
|
13220
13347
|
}
|
|
13221
13348
|
const updateData = {
|
|
13222
|
-
updatedAt: (0,
|
|
13349
|
+
updatedAt: (0, import_firestore39.serverTimestamp)()
|
|
13223
13350
|
};
|
|
13224
13351
|
if (params.eventName !== void 0) {
|
|
13225
13352
|
updateData.eventName = params.eventName;
|
|
@@ -13233,8 +13360,8 @@ var CalendarServiceV3 = class extends BaseService {
|
|
|
13233
13360
|
if (params.status !== void 0) {
|
|
13234
13361
|
updateData.status = params.status;
|
|
13235
13362
|
}
|
|
13236
|
-
await (0,
|
|
13237
|
-
const updatedEventDoc = await (0,
|
|
13363
|
+
await (0, import_firestore40.updateDoc)(eventRef, updateData);
|
|
13364
|
+
const updatedEventDoc = await (0, import_firestore40.getDoc)(eventRef);
|
|
13238
13365
|
return updatedEventDoc.data();
|
|
13239
13366
|
}
|
|
13240
13367
|
/**
|
|
@@ -13245,12 +13372,12 @@ var CalendarServiceV3 = class extends BaseService {
|
|
|
13245
13372
|
*/
|
|
13246
13373
|
async deleteBlockingEvent(entityType, entityId, eventId) {
|
|
13247
13374
|
const collectionPath = this.getEntityCalendarPath(entityType, entityId);
|
|
13248
|
-
const eventRef = (0,
|
|
13249
|
-
const eventDoc = await (0,
|
|
13375
|
+
const eventRef = (0, import_firestore40.doc)(this.db, collectionPath, eventId);
|
|
13376
|
+
const eventDoc = await (0, import_firestore40.getDoc)(eventRef);
|
|
13250
13377
|
if (!eventDoc.exists()) {
|
|
13251
13378
|
throw new Error(`Blocking event with ID ${eventId} not found`);
|
|
13252
13379
|
}
|
|
13253
|
-
await (0,
|
|
13380
|
+
await (0, import_firestore40.deleteDoc)(eventRef);
|
|
13254
13381
|
}
|
|
13255
13382
|
/**
|
|
13256
13383
|
* Gets a specific blocking event
|
|
@@ -13261,8 +13388,8 @@ var CalendarServiceV3 = class extends BaseService {
|
|
|
13261
13388
|
*/
|
|
13262
13389
|
async getBlockingEvent(entityType, entityId, eventId) {
|
|
13263
13390
|
const collectionPath = this.getEntityCalendarPath(entityType, entityId);
|
|
13264
|
-
const eventRef = (0,
|
|
13265
|
-
const eventDoc = await (0,
|
|
13391
|
+
const eventRef = (0, import_firestore40.doc)(this.db, collectionPath, eventId);
|
|
13392
|
+
const eventDoc = await (0, import_firestore40.getDoc)(eventRef);
|
|
13266
13393
|
if (!eventDoc.exists()) {
|
|
13267
13394
|
return null;
|
|
13268
13395
|
}
|
|
@@ -13455,7 +13582,7 @@ var ExternalCalendarService = class extends BaseService {
|
|
|
13455
13582
|
};
|
|
13456
13583
|
|
|
13457
13584
|
// src/services/clinic/practitioner-invite.service.ts
|
|
13458
|
-
var
|
|
13585
|
+
var import_firestore41 = require("firebase/firestore");
|
|
13459
13586
|
var PractitionerInviteService = class extends BaseService {
|
|
13460
13587
|
constructor(db, auth, app) {
|
|
13461
13588
|
super(db, auth, app);
|
|
@@ -13517,7 +13644,7 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
13517
13644
|
message: message || null,
|
|
13518
13645
|
status: "pending" /* PENDING */
|
|
13519
13646
|
};
|
|
13520
|
-
const now =
|
|
13647
|
+
const now = import_firestore41.Timestamp.now();
|
|
13521
13648
|
const invite = {
|
|
13522
13649
|
id: inviteId,
|
|
13523
13650
|
...inviteData,
|
|
@@ -13528,8 +13655,8 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
13528
13655
|
rejectedAt: null,
|
|
13529
13656
|
cancelledAt: null
|
|
13530
13657
|
};
|
|
13531
|
-
const docRef = (0,
|
|
13532
|
-
await (0,
|
|
13658
|
+
const docRef = (0, import_firestore41.doc)(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
13659
|
+
await (0, import_firestore41.setDoc)(docRef, invite);
|
|
13533
13660
|
return invite;
|
|
13534
13661
|
} catch (error) {
|
|
13535
13662
|
console.error(
|
|
@@ -13548,17 +13675,17 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
13548
13675
|
async getAllInvitesDoctor(practitionerId, statusFilter) {
|
|
13549
13676
|
try {
|
|
13550
13677
|
const constraints = [
|
|
13551
|
-
(0,
|
|
13552
|
-
(0,
|
|
13678
|
+
(0, import_firestore41.where)("practitionerId", "==", practitionerId),
|
|
13679
|
+
(0, import_firestore41.orderBy)("createdAt", "desc")
|
|
13553
13680
|
];
|
|
13554
13681
|
if (statusFilter && statusFilter.length > 0) {
|
|
13555
|
-
constraints.push((0,
|
|
13682
|
+
constraints.push((0, import_firestore41.where)("status", "in", statusFilter));
|
|
13556
13683
|
}
|
|
13557
|
-
const q = (0,
|
|
13558
|
-
(0,
|
|
13684
|
+
const q = (0, import_firestore41.query)(
|
|
13685
|
+
(0, import_firestore41.collection)(this.db, PRACTITIONER_INVITES_COLLECTION),
|
|
13559
13686
|
...constraints
|
|
13560
13687
|
);
|
|
13561
|
-
const querySnapshot = await (0,
|
|
13688
|
+
const querySnapshot = await (0, import_firestore41.getDocs)(q);
|
|
13562
13689
|
return querySnapshot.docs.map((doc38) => doc38.data());
|
|
13563
13690
|
} catch (error) {
|
|
13564
13691
|
console.error(
|
|
@@ -13577,17 +13704,17 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
13577
13704
|
async getAllInvitesClinic(clinicId, statusFilter) {
|
|
13578
13705
|
try {
|
|
13579
13706
|
const constraints = [
|
|
13580
|
-
(0,
|
|
13581
|
-
(0,
|
|
13707
|
+
(0, import_firestore41.where)("clinicId", "==", clinicId),
|
|
13708
|
+
(0, import_firestore41.orderBy)("createdAt", "desc")
|
|
13582
13709
|
];
|
|
13583
13710
|
if (statusFilter && statusFilter.length > 0) {
|
|
13584
|
-
constraints.push((0,
|
|
13711
|
+
constraints.push((0, import_firestore41.where)("status", "in", statusFilter));
|
|
13585
13712
|
}
|
|
13586
|
-
const q = (0,
|
|
13587
|
-
(0,
|
|
13713
|
+
const q = (0, import_firestore41.query)(
|
|
13714
|
+
(0, import_firestore41.collection)(this.db, PRACTITIONER_INVITES_COLLECTION),
|
|
13588
13715
|
...constraints
|
|
13589
13716
|
);
|
|
13590
|
-
const querySnapshot = await (0,
|
|
13717
|
+
const querySnapshot = await (0, import_firestore41.getDocs)(q);
|
|
13591
13718
|
return querySnapshot.docs.map((doc38) => doc38.data());
|
|
13592
13719
|
} catch (error) {
|
|
13593
13720
|
console.error(
|
|
@@ -13613,11 +13740,11 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
13613
13740
|
}
|
|
13614
13741
|
const updateData = {
|
|
13615
13742
|
status: "accepted" /* ACCEPTED */,
|
|
13616
|
-
acceptedAt:
|
|
13617
|
-
updatedAt: (0,
|
|
13743
|
+
acceptedAt: import_firestore41.Timestamp.now(),
|
|
13744
|
+
updatedAt: (0, import_firestore41.serverTimestamp)()
|
|
13618
13745
|
};
|
|
13619
|
-
const docRef = (0,
|
|
13620
|
-
await (0,
|
|
13746
|
+
const docRef = (0, import_firestore41.doc)(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
13747
|
+
await (0, import_firestore41.updateDoc)(docRef, updateData);
|
|
13621
13748
|
return await this.getInviteById(inviteId);
|
|
13622
13749
|
} catch (error) {
|
|
13623
13750
|
console.error(
|
|
@@ -13645,11 +13772,11 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
13645
13772
|
const updateData = {
|
|
13646
13773
|
status: "rejected" /* REJECTED */,
|
|
13647
13774
|
rejectionReason: rejectionReason || null,
|
|
13648
|
-
rejectedAt:
|
|
13649
|
-
updatedAt: (0,
|
|
13775
|
+
rejectedAt: import_firestore41.Timestamp.now(),
|
|
13776
|
+
updatedAt: (0, import_firestore41.serverTimestamp)()
|
|
13650
13777
|
};
|
|
13651
|
-
const docRef = (0,
|
|
13652
|
-
await (0,
|
|
13778
|
+
const docRef = (0, import_firestore41.doc)(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
13779
|
+
await (0, import_firestore41.updateDoc)(docRef, updateData);
|
|
13653
13780
|
return await this.getInviteById(inviteId);
|
|
13654
13781
|
} catch (error) {
|
|
13655
13782
|
console.error(
|
|
@@ -13677,11 +13804,11 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
13677
13804
|
const updateData = {
|
|
13678
13805
|
status: "cancelled" /* CANCELLED */,
|
|
13679
13806
|
cancelReason: cancelReason || null,
|
|
13680
|
-
cancelledAt:
|
|
13681
|
-
updatedAt: (0,
|
|
13807
|
+
cancelledAt: import_firestore41.Timestamp.now(),
|
|
13808
|
+
updatedAt: (0, import_firestore41.serverTimestamp)()
|
|
13682
13809
|
};
|
|
13683
|
-
const docRef = (0,
|
|
13684
|
-
await (0,
|
|
13810
|
+
const docRef = (0, import_firestore41.doc)(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
13811
|
+
await (0, import_firestore41.updateDoc)(docRef, updateData);
|
|
13685
13812
|
return await this.getInviteById(inviteId);
|
|
13686
13813
|
} catch (error) {
|
|
13687
13814
|
console.error(
|
|
@@ -13698,8 +13825,8 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
13698
13825
|
*/
|
|
13699
13826
|
async getInviteById(inviteId) {
|
|
13700
13827
|
try {
|
|
13701
|
-
const docRef = (0,
|
|
13702
|
-
const docSnap = await (0,
|
|
13828
|
+
const docRef = (0, import_firestore41.doc)(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
13829
|
+
const docSnap = await (0, import_firestore41.getDoc)(docRef);
|
|
13703
13830
|
if (docSnap.exists()) {
|
|
13704
13831
|
return docSnap.data();
|
|
13705
13832
|
}
|
|
@@ -13721,28 +13848,28 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
13721
13848
|
try {
|
|
13722
13849
|
const constraints = [];
|
|
13723
13850
|
if (filters.practitionerId) {
|
|
13724
|
-
constraints.push((0,
|
|
13851
|
+
constraints.push((0, import_firestore41.where)("practitionerId", "==", filters.practitionerId));
|
|
13725
13852
|
}
|
|
13726
13853
|
if (filters.clinicId) {
|
|
13727
|
-
constraints.push((0,
|
|
13854
|
+
constraints.push((0, import_firestore41.where)("clinicId", "==", filters.clinicId));
|
|
13728
13855
|
}
|
|
13729
13856
|
if (filters.invitedBy) {
|
|
13730
|
-
constraints.push((0,
|
|
13857
|
+
constraints.push((0, import_firestore41.where)("invitedBy", "==", filters.invitedBy));
|
|
13731
13858
|
}
|
|
13732
13859
|
if (filters.status && filters.status.length > 0) {
|
|
13733
|
-
constraints.push((0,
|
|
13860
|
+
constraints.push((0, import_firestore41.where)("status", "in", filters.status));
|
|
13734
13861
|
}
|
|
13735
13862
|
const orderField = filters.orderBy || "createdAt";
|
|
13736
13863
|
const orderDirection = filters.orderDirection || "desc";
|
|
13737
|
-
constraints.push((0,
|
|
13864
|
+
constraints.push((0, import_firestore41.orderBy)(orderField, orderDirection));
|
|
13738
13865
|
if (filters.limit) {
|
|
13739
|
-
constraints.push((0,
|
|
13866
|
+
constraints.push((0, import_firestore41.limit)(filters.limit));
|
|
13740
13867
|
}
|
|
13741
|
-
const q = (0,
|
|
13742
|
-
(0,
|
|
13868
|
+
const q = (0, import_firestore41.query)(
|
|
13869
|
+
(0, import_firestore41.collection)(this.db, PRACTITIONER_INVITES_COLLECTION),
|
|
13743
13870
|
...constraints
|
|
13744
13871
|
);
|
|
13745
|
-
const querySnapshot = await (0,
|
|
13872
|
+
const querySnapshot = await (0, import_firestore41.getDocs)(q);
|
|
13746
13873
|
let invites = querySnapshot.docs.map(
|
|
13747
13874
|
(doc38) => doc38.data()
|
|
13748
13875
|
);
|
|
@@ -13771,8 +13898,8 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
13771
13898
|
*/
|
|
13772
13899
|
async deleteInvite(inviteId) {
|
|
13773
13900
|
try {
|
|
13774
|
-
const docRef = (0,
|
|
13775
|
-
await (0,
|
|
13901
|
+
const docRef = (0, import_firestore41.doc)(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
13902
|
+
await (0, import_firestore41.deleteDoc)(docRef);
|
|
13776
13903
|
} catch (error) {
|
|
13777
13904
|
console.error(
|
|
13778
13905
|
"[PractitionerInviteService] Error deleting invite:",
|
|
@@ -13789,8 +13916,8 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
13789
13916
|
*/
|
|
13790
13917
|
async getPractitionerById(practitionerId) {
|
|
13791
13918
|
try {
|
|
13792
|
-
const docRef = (0,
|
|
13793
|
-
const docSnap = await (0,
|
|
13919
|
+
const docRef = (0, import_firestore41.doc)(this.db, PRACTITIONERS_COLLECTION, practitionerId);
|
|
13920
|
+
const docSnap = await (0, import_firestore41.getDoc)(docRef);
|
|
13794
13921
|
return docSnap.exists() ? docSnap.data() : null;
|
|
13795
13922
|
} catch (error) {
|
|
13796
13923
|
console.error(
|
|
@@ -13807,8 +13934,8 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
13807
13934
|
*/
|
|
13808
13935
|
async getClinicById(clinicId) {
|
|
13809
13936
|
try {
|
|
13810
|
-
const docRef = (0,
|
|
13811
|
-
const docSnap = await (0,
|
|
13937
|
+
const docRef = (0, import_firestore41.doc)(this.db, CLINICS_COLLECTION, clinicId);
|
|
13938
|
+
const docSnap = await (0, import_firestore41.getDoc)(docRef);
|
|
13812
13939
|
return docSnap.exists() ? docSnap.data() : null;
|
|
13813
13940
|
} catch (error) {
|
|
13814
13941
|
console.error("[PractitionerInviteService] Error getting clinic:", error);
|
|
@@ -13823,14 +13950,14 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
13823
13950
|
*/
|
|
13824
13951
|
async findExistingInvite(practitionerId, clinicId) {
|
|
13825
13952
|
try {
|
|
13826
|
-
const q = (0,
|
|
13827
|
-
(0,
|
|
13828
|
-
(0,
|
|
13829
|
-
(0,
|
|
13830
|
-
(0,
|
|
13831
|
-
(0,
|
|
13832
|
-
);
|
|
13833
|
-
const querySnapshot = await (0,
|
|
13953
|
+
const q = (0, import_firestore41.query)(
|
|
13954
|
+
(0, import_firestore41.collection)(this.db, PRACTITIONER_INVITES_COLLECTION),
|
|
13955
|
+
(0, import_firestore41.where)("practitionerId", "==", practitionerId),
|
|
13956
|
+
(0, import_firestore41.where)("clinicId", "==", clinicId),
|
|
13957
|
+
(0, import_firestore41.orderBy)("createdAt", "desc"),
|
|
13958
|
+
(0, import_firestore41.limit)(1)
|
|
13959
|
+
);
|
|
13960
|
+
const querySnapshot = await (0, import_firestore41.getDocs)(q);
|
|
13834
13961
|
if (querySnapshot.empty) {
|
|
13835
13962
|
return null;
|
|
13836
13963
|
}
|
|
@@ -13846,12 +13973,12 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
13846
13973
|
};
|
|
13847
13974
|
|
|
13848
13975
|
// src/services/documentation-templates/documentation-template.service.ts
|
|
13849
|
-
var import_firestore41 = require("firebase/firestore");
|
|
13850
13976
|
var import_firestore42 = require("firebase/firestore");
|
|
13977
|
+
var import_firestore43 = require("firebase/firestore");
|
|
13851
13978
|
var DocumentationTemplateService = class extends BaseService {
|
|
13852
13979
|
constructor(...args) {
|
|
13853
13980
|
super(...args);
|
|
13854
|
-
this.collectionRef = (0,
|
|
13981
|
+
this.collectionRef = (0, import_firestore42.collection)(
|
|
13855
13982
|
this.db,
|
|
13856
13983
|
DOCUMENTATION_TEMPLATES_COLLECTION
|
|
13857
13984
|
);
|
|
@@ -13885,8 +14012,8 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
13885
14012
|
isRequired: validatedData.isRequired || false,
|
|
13886
14013
|
sortingOrder: validatedData.sortingOrder || 0
|
|
13887
14014
|
};
|
|
13888
|
-
const docRef = (0,
|
|
13889
|
-
await (0,
|
|
14015
|
+
const docRef = (0, import_firestore42.doc)(this.collectionRef, templateId);
|
|
14016
|
+
await (0, import_firestore42.setDoc)(docRef, template);
|
|
13890
14017
|
return template;
|
|
13891
14018
|
}
|
|
13892
14019
|
/**
|
|
@@ -13896,8 +14023,8 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
13896
14023
|
* @returns The template or null if not found
|
|
13897
14024
|
*/
|
|
13898
14025
|
async getTemplateById(templateId, version) {
|
|
13899
|
-
const docRef = (0,
|
|
13900
|
-
const docSnap = await (0,
|
|
14026
|
+
const docRef = (0, import_firestore42.doc)(this.collectionRef, templateId);
|
|
14027
|
+
const docSnap = await (0, import_firestore42.getDoc)(docRef);
|
|
13901
14028
|
if (!docSnap.exists()) {
|
|
13902
14029
|
return null;
|
|
13903
14030
|
}
|
|
@@ -13935,15 +14062,15 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
13935
14062
|
if (!template) {
|
|
13936
14063
|
throw new Error(`Template with ID ${templateId} not found`);
|
|
13937
14064
|
}
|
|
13938
|
-
const versionsCollectionRef = (0,
|
|
14065
|
+
const versionsCollectionRef = (0, import_firestore42.collection)(
|
|
13939
14066
|
this.db,
|
|
13940
14067
|
`${DOCUMENTATION_TEMPLATES_COLLECTION}/${templateId}/versions`
|
|
13941
14068
|
);
|
|
13942
|
-
const versionDocRef = (0,
|
|
14069
|
+
const versionDocRef = (0, import_firestore42.doc)(
|
|
13943
14070
|
versionsCollectionRef,
|
|
13944
14071
|
template.version.toString()
|
|
13945
14072
|
);
|
|
13946
|
-
await (0,
|
|
14073
|
+
await (0, import_firestore42.setDoc)(versionDocRef, template);
|
|
13947
14074
|
let updatedElements = template.elements;
|
|
13948
14075
|
if (validatedData.elements) {
|
|
13949
14076
|
updatedElements = validatedData.elements.map((element) => ({
|
|
@@ -13967,9 +14094,9 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
13967
14094
|
updatePayload.isUserForm = (_a = validatedData.isUserForm) != null ? _a : false;
|
|
13968
14095
|
updatePayload.isRequired = (_b = validatedData.isRequired) != null ? _b : false;
|
|
13969
14096
|
updatePayload.sortingOrder = (_c = validatedData.sortingOrder) != null ? _c : 0;
|
|
13970
|
-
const docRef = (0,
|
|
14097
|
+
const docRef = (0, import_firestore42.doc)(this.collectionRef, templateId);
|
|
13971
14098
|
console.log("Update payload", updatePayload);
|
|
13972
|
-
await (0,
|
|
14099
|
+
await (0, import_firestore42.updateDoc)(docRef, updatePayload);
|
|
13973
14100
|
return { ...template, ...updatePayload };
|
|
13974
14101
|
}
|
|
13975
14102
|
/**
|
|
@@ -13979,11 +14106,11 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
13979
14106
|
* @returns The template version or null if not found
|
|
13980
14107
|
*/
|
|
13981
14108
|
async getTemplateVersion(templateId, versionNumber) {
|
|
13982
|
-
const versionDocRef = (0,
|
|
14109
|
+
const versionDocRef = (0, import_firestore42.doc)(
|
|
13983
14110
|
this.db,
|
|
13984
14111
|
`${DOCUMENTATION_TEMPLATES_COLLECTION}/${templateId}/versions/${versionNumber}`
|
|
13985
14112
|
);
|
|
13986
|
-
const versionDocSnap = await (0,
|
|
14113
|
+
const versionDocSnap = await (0, import_firestore42.getDoc)(versionDocRef);
|
|
13987
14114
|
if (!versionDocSnap.exists()) {
|
|
13988
14115
|
return null;
|
|
13989
14116
|
}
|
|
@@ -13995,12 +14122,12 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
13995
14122
|
* @returns Array of template versions
|
|
13996
14123
|
*/
|
|
13997
14124
|
async getTemplateOldVersions(templateId) {
|
|
13998
|
-
const versionsCollectionRef = (0,
|
|
14125
|
+
const versionsCollectionRef = (0, import_firestore42.collection)(
|
|
13999
14126
|
this.db,
|
|
14000
14127
|
`${DOCUMENTATION_TEMPLATES_COLLECTION}/${templateId}/versions`
|
|
14001
14128
|
);
|
|
14002
|
-
const q = (0,
|
|
14003
|
-
const querySnapshot = await (0,
|
|
14129
|
+
const q = (0, import_firestore42.query)(versionsCollectionRef, (0, import_firestore42.orderBy)("version", "desc"));
|
|
14130
|
+
const querySnapshot = await (0, import_firestore42.getDocs)(q);
|
|
14004
14131
|
const versions = [];
|
|
14005
14132
|
querySnapshot.forEach((doc38) => {
|
|
14006
14133
|
versions.push(doc38.data());
|
|
@@ -14012,8 +14139,8 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
14012
14139
|
* @param templateId - ID of the template to delete
|
|
14013
14140
|
*/
|
|
14014
14141
|
async deleteTemplate(templateId) {
|
|
14015
|
-
const docRef = (0,
|
|
14016
|
-
await (0,
|
|
14142
|
+
const docRef = (0, import_firestore42.doc)(this.collectionRef, templateId);
|
|
14143
|
+
await (0, import_firestore42.deleteDoc)(docRef);
|
|
14017
14144
|
}
|
|
14018
14145
|
/**
|
|
14019
14146
|
* Get all active templates
|
|
@@ -14022,16 +14149,16 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
14022
14149
|
* @returns Array of templates and the last document for pagination
|
|
14023
14150
|
*/
|
|
14024
14151
|
async getActiveTemplates(pageSize = 20, lastDoc) {
|
|
14025
|
-
let q = (0,
|
|
14152
|
+
let q = (0, import_firestore42.query)(
|
|
14026
14153
|
this.collectionRef,
|
|
14027
|
-
(0,
|
|
14028
|
-
(0,
|
|
14029
|
-
(0,
|
|
14154
|
+
(0, import_firestore42.where)("isActive", "==", true),
|
|
14155
|
+
(0, import_firestore42.orderBy)("updatedAt", "desc"),
|
|
14156
|
+
(0, import_firestore42.limit)(pageSize)
|
|
14030
14157
|
);
|
|
14031
14158
|
if (lastDoc) {
|
|
14032
|
-
q = (0,
|
|
14159
|
+
q = (0, import_firestore42.query)(q, (0, import_firestore42.startAfter)(lastDoc));
|
|
14033
14160
|
}
|
|
14034
|
-
const querySnapshot = await (0,
|
|
14161
|
+
const querySnapshot = await (0, import_firestore42.getDocs)(q);
|
|
14035
14162
|
const templates = [];
|
|
14036
14163
|
let lastVisible = null;
|
|
14037
14164
|
querySnapshot.forEach((doc38) => {
|
|
@@ -14057,25 +14184,25 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
14057
14184
|
sortingOrder
|
|
14058
14185
|
} = options;
|
|
14059
14186
|
const constraints = [
|
|
14060
|
-
(0,
|
|
14061
|
-
(0,
|
|
14062
|
-
(0,
|
|
14063
|
-
(0,
|
|
14187
|
+
(0, import_firestore42.where)("isActive", "==", true),
|
|
14188
|
+
(0, import_firestore42.orderBy)("sortingOrder", "asc"),
|
|
14189
|
+
(0, import_firestore42.orderBy)("title", "asc"),
|
|
14190
|
+
(0, import_firestore42.limit)(pageSize)
|
|
14064
14191
|
];
|
|
14065
14192
|
if (isUserForm !== void 0) {
|
|
14066
|
-
constraints.push((0,
|
|
14193
|
+
constraints.push((0, import_firestore42.where)("isUserForm", "==", isUserForm));
|
|
14067
14194
|
}
|
|
14068
14195
|
if (isRequired !== void 0) {
|
|
14069
|
-
constraints.push((0,
|
|
14196
|
+
constraints.push((0, import_firestore42.where)("isRequired", "==", isRequired));
|
|
14070
14197
|
}
|
|
14071
14198
|
if (sortingOrder !== void 0) {
|
|
14072
|
-
constraints.push((0,
|
|
14199
|
+
constraints.push((0, import_firestore42.where)("sortingOrder", "==", sortingOrder));
|
|
14073
14200
|
}
|
|
14074
14201
|
if (lastDoc) {
|
|
14075
|
-
constraints.push((0,
|
|
14202
|
+
constraints.push((0, import_firestore42.startAfter)(lastDoc));
|
|
14076
14203
|
}
|
|
14077
|
-
const q = (0,
|
|
14078
|
-
const querySnapshot = await (0,
|
|
14204
|
+
const q = (0, import_firestore42.query)(this.collectionRef, ...constraints.filter((c) => c));
|
|
14205
|
+
const querySnapshot = await (0, import_firestore42.getDocs)(q);
|
|
14079
14206
|
const templates = [];
|
|
14080
14207
|
let lastVisible = null;
|
|
14081
14208
|
querySnapshot.forEach((doc38) => {
|
|
@@ -14094,18 +14221,18 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
14094
14221
|
*/
|
|
14095
14222
|
async getTemplatesCount(options) {
|
|
14096
14223
|
const { isUserForm, isRequired, sortingOrder } = options;
|
|
14097
|
-
const constraints = [(0,
|
|
14224
|
+
const constraints = [(0, import_firestore42.where)("isActive", "==", true)];
|
|
14098
14225
|
if (isUserForm !== void 0) {
|
|
14099
|
-
constraints.push((0,
|
|
14226
|
+
constraints.push((0, import_firestore42.where)("isUserForm", "==", isUserForm));
|
|
14100
14227
|
}
|
|
14101
14228
|
if (isRequired !== void 0) {
|
|
14102
|
-
constraints.push((0,
|
|
14229
|
+
constraints.push((0, import_firestore42.where)("isRequired", "==", isRequired));
|
|
14103
14230
|
}
|
|
14104
14231
|
if (sortingOrder !== void 0) {
|
|
14105
|
-
constraints.push((0,
|
|
14232
|
+
constraints.push((0, import_firestore42.where)("sortingOrder", "==", sortingOrder));
|
|
14106
14233
|
}
|
|
14107
|
-
const q = (0,
|
|
14108
|
-
const snapshot = await (0,
|
|
14234
|
+
const q = (0, import_firestore42.query)(this.collectionRef, ...constraints.filter((c) => c));
|
|
14235
|
+
const snapshot = await (0, import_firestore43.getCountFromServer)(q);
|
|
14109
14236
|
return snapshot.data().count;
|
|
14110
14237
|
}
|
|
14111
14238
|
/**
|
|
@@ -14113,12 +14240,12 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
14113
14240
|
* @returns A promise that resolves to an array of all active templates.
|
|
14114
14241
|
*/
|
|
14115
14242
|
async getAllActiveTemplates() {
|
|
14116
|
-
const q = (0,
|
|
14243
|
+
const q = (0, import_firestore42.query)(
|
|
14117
14244
|
this.collectionRef,
|
|
14118
|
-
(0,
|
|
14119
|
-
(0,
|
|
14245
|
+
(0, import_firestore42.where)("isActive", "==", true),
|
|
14246
|
+
(0, import_firestore42.orderBy)("title", "asc")
|
|
14120
14247
|
);
|
|
14121
|
-
const querySnapshot = await (0,
|
|
14248
|
+
const querySnapshot = await (0, import_firestore42.getDocs)(q);
|
|
14122
14249
|
const templates = [];
|
|
14123
14250
|
querySnapshot.forEach((doc38) => {
|
|
14124
14251
|
templates.push(doc38.data());
|
|
@@ -14133,17 +14260,17 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
14133
14260
|
* @returns Array of templates and the last document for pagination
|
|
14134
14261
|
*/
|
|
14135
14262
|
async getTemplatesByTags(tags, pageSize = 20, lastDoc) {
|
|
14136
|
-
let q = (0,
|
|
14263
|
+
let q = (0, import_firestore42.query)(
|
|
14137
14264
|
this.collectionRef,
|
|
14138
|
-
(0,
|
|
14139
|
-
(0,
|
|
14140
|
-
(0,
|
|
14141
|
-
(0,
|
|
14265
|
+
(0, import_firestore42.where)("isActive", "==", true),
|
|
14266
|
+
(0, import_firestore42.where)("tags", "array-contains-any", tags),
|
|
14267
|
+
(0, import_firestore42.orderBy)("updatedAt", "desc"),
|
|
14268
|
+
(0, import_firestore42.limit)(pageSize)
|
|
14142
14269
|
);
|
|
14143
14270
|
if (lastDoc) {
|
|
14144
|
-
q = (0,
|
|
14271
|
+
q = (0, import_firestore42.query)(q, (0, import_firestore42.startAfter)(lastDoc));
|
|
14145
14272
|
}
|
|
14146
|
-
const querySnapshot = await (0,
|
|
14273
|
+
const querySnapshot = await (0, import_firestore42.getDocs)(q);
|
|
14147
14274
|
const templates = [];
|
|
14148
14275
|
let lastVisible = null;
|
|
14149
14276
|
querySnapshot.forEach((doc38) => {
|
|
@@ -14163,16 +14290,16 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
14163
14290
|
* @returns Array of templates and the last document for pagination
|
|
14164
14291
|
*/
|
|
14165
14292
|
async getTemplatesByCreator(userId, pageSize = 20, lastDoc) {
|
|
14166
|
-
let q = (0,
|
|
14293
|
+
let q = (0, import_firestore42.query)(
|
|
14167
14294
|
this.collectionRef,
|
|
14168
|
-
(0,
|
|
14169
|
-
(0,
|
|
14170
|
-
(0,
|
|
14295
|
+
(0, import_firestore42.where)("createdBy", "==", userId),
|
|
14296
|
+
(0, import_firestore42.orderBy)("updatedAt", "desc"),
|
|
14297
|
+
(0, import_firestore42.limit)(pageSize)
|
|
14171
14298
|
);
|
|
14172
14299
|
if (lastDoc) {
|
|
14173
|
-
q = (0,
|
|
14300
|
+
q = (0, import_firestore42.query)(q, (0, import_firestore42.startAfter)(lastDoc));
|
|
14174
14301
|
}
|
|
14175
|
-
const querySnapshot = await (0,
|
|
14302
|
+
const querySnapshot = await (0, import_firestore42.getDocs)(q);
|
|
14176
14303
|
const templates = [];
|
|
14177
14304
|
let lastVisible = null;
|
|
14178
14305
|
querySnapshot.forEach((doc38) => {
|
|
@@ -14190,18 +14317,18 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
14190
14317
|
* @returns Array of templates
|
|
14191
14318
|
*/
|
|
14192
14319
|
async getAllTemplatesForSelection(options) {
|
|
14193
|
-
let q = (0,
|
|
14320
|
+
let q = (0, import_firestore42.query)(
|
|
14194
14321
|
this.collectionRef,
|
|
14195
|
-
(0,
|
|
14196
|
-
(0,
|
|
14322
|
+
(0, import_firestore42.where)("isActive", "==", true),
|
|
14323
|
+
(0, import_firestore42.orderBy)("updatedAt", "desc")
|
|
14197
14324
|
);
|
|
14198
14325
|
if ((options == null ? void 0 : options.isUserForm) !== void 0) {
|
|
14199
|
-
q = (0,
|
|
14326
|
+
q = (0, import_firestore42.query)(q, (0, import_firestore42.where)("isUserForm", "==", options.isUserForm));
|
|
14200
14327
|
}
|
|
14201
14328
|
if ((options == null ? void 0 : options.isRequired) !== void 0) {
|
|
14202
|
-
q = (0,
|
|
14329
|
+
q = (0, import_firestore42.query)(q, (0, import_firestore42.where)("isRequired", "==", options.isRequired));
|
|
14203
14330
|
}
|
|
14204
|
-
const querySnapshot = await (0,
|
|
14331
|
+
const querySnapshot = await (0, import_firestore42.getDocs)(q);
|
|
14205
14332
|
const templates = [];
|
|
14206
14333
|
querySnapshot.forEach((doc38) => {
|
|
14207
14334
|
templates.push(doc38.data());
|
|
@@ -14211,7 +14338,7 @@ var DocumentationTemplateService = class extends BaseService {
|
|
|
14211
14338
|
};
|
|
14212
14339
|
|
|
14213
14340
|
// src/services/documentation-templates/filled-document.service.ts
|
|
14214
|
-
var
|
|
14341
|
+
var import_firestore44 = require("firebase/firestore");
|
|
14215
14342
|
var FilledDocumentService = class extends BaseService {
|
|
14216
14343
|
constructor(...args) {
|
|
14217
14344
|
super(...args);
|
|
@@ -14266,7 +14393,7 @@ var FilledDocumentService = class extends BaseService {
|
|
|
14266
14393
|
values: initialValues,
|
|
14267
14394
|
status: initialStatus
|
|
14268
14395
|
};
|
|
14269
|
-
const docRef = (0,
|
|
14396
|
+
const docRef = (0, import_firestore44.doc)(
|
|
14270
14397
|
this.db,
|
|
14271
14398
|
APPOINTMENTS_COLLECTION,
|
|
14272
14399
|
// Replaced "appointments"
|
|
@@ -14274,7 +14401,7 @@ var FilledDocumentService = class extends BaseService {
|
|
|
14274
14401
|
formSubcollection,
|
|
14275
14402
|
documentId3
|
|
14276
14403
|
);
|
|
14277
|
-
await (0,
|
|
14404
|
+
await (0, import_firestore44.setDoc)(docRef, filledDocument);
|
|
14278
14405
|
return filledDocument;
|
|
14279
14406
|
}
|
|
14280
14407
|
/**
|
|
@@ -14286,7 +14413,7 @@ var FilledDocumentService = class extends BaseService {
|
|
|
14286
14413
|
*/
|
|
14287
14414
|
async getFilledDocumentFromAppointmentById(appointmentId, formId, isUserForm) {
|
|
14288
14415
|
const formSubcollection = this.getFormSubcollectionPath(isUserForm);
|
|
14289
|
-
const docRef = (0,
|
|
14416
|
+
const docRef = (0, import_firestore44.doc)(
|
|
14290
14417
|
this.db,
|
|
14291
14418
|
APPOINTMENTS_COLLECTION,
|
|
14292
14419
|
// Replaced "appointments"
|
|
@@ -14294,7 +14421,7 @@ var FilledDocumentService = class extends BaseService {
|
|
|
14294
14421
|
formSubcollection,
|
|
14295
14422
|
formId
|
|
14296
14423
|
);
|
|
14297
|
-
const docSnap = await (0,
|
|
14424
|
+
const docSnap = await (0, import_firestore44.getDoc)(docRef);
|
|
14298
14425
|
if (!docSnap.exists()) {
|
|
14299
14426
|
return null;
|
|
14300
14427
|
}
|
|
@@ -14311,7 +14438,7 @@ var FilledDocumentService = class extends BaseService {
|
|
|
14311
14438
|
*/
|
|
14312
14439
|
async updateFilledDocumentInAppointment(appointmentId, formId, isUserForm, values, status) {
|
|
14313
14440
|
const formSubcollection = this.getFormSubcollectionPath(isUserForm);
|
|
14314
|
-
const docRef = (0,
|
|
14441
|
+
const docRef = (0, import_firestore44.doc)(
|
|
14315
14442
|
this.db,
|
|
14316
14443
|
APPOINTMENTS_COLLECTION,
|
|
14317
14444
|
// Replaced "appointments"
|
|
@@ -14343,7 +14470,7 @@ var FilledDocumentService = class extends BaseService {
|
|
|
14343
14470
|
}
|
|
14344
14471
|
if (Object.keys(updatePayload).length === 1 && "updatedAt" in updatePayload) {
|
|
14345
14472
|
}
|
|
14346
|
-
await (0,
|
|
14473
|
+
await (0, import_firestore44.updateDoc)(docRef, updatePayload);
|
|
14347
14474
|
return { ...existingDoc, ...updatePayload };
|
|
14348
14475
|
}
|
|
14349
14476
|
/**
|
|
@@ -14353,20 +14480,20 @@ var FilledDocumentService = class extends BaseService {
|
|
|
14353
14480
|
* @param lastDoc Last document from previous page for pagination.
|
|
14354
14481
|
*/
|
|
14355
14482
|
async getFilledUserFormsForAppointment(appointmentId, pageSize = 20, lastDoc) {
|
|
14356
|
-
const subcollectionRef = (0,
|
|
14483
|
+
const subcollectionRef = (0, import_firestore44.collection)(
|
|
14357
14484
|
this.db,
|
|
14358
14485
|
APPOINTMENTS_COLLECTION,
|
|
14359
14486
|
// Replaced "appointments"
|
|
14360
14487
|
appointmentId,
|
|
14361
14488
|
USER_FORMS_SUBCOLLECTION
|
|
14362
14489
|
);
|
|
14363
|
-
let q = (0,
|
|
14490
|
+
let q = (0, import_firestore44.query)(
|
|
14364
14491
|
subcollectionRef,
|
|
14365
|
-
(0,
|
|
14366
|
-
(0,
|
|
14492
|
+
(0, import_firestore44.orderBy)("updatedAt", "desc"),
|
|
14493
|
+
(0, import_firestore44.limit)(pageSize)
|
|
14367
14494
|
);
|
|
14368
14495
|
if (lastDoc) {
|
|
14369
|
-
q = (0,
|
|
14496
|
+
q = (0, import_firestore44.query)(q, (0, import_firestore44.startAfter)(lastDoc));
|
|
14370
14497
|
}
|
|
14371
14498
|
return this.executeQuery(q);
|
|
14372
14499
|
}
|
|
@@ -14377,26 +14504,26 @@ var FilledDocumentService = class extends BaseService {
|
|
|
14377
14504
|
* @param lastDoc Last document from previous page for pagination.
|
|
14378
14505
|
*/
|
|
14379
14506
|
async getFilledDoctorFormsForAppointment(appointmentId, pageSize = 20, lastDoc) {
|
|
14380
|
-
const subcollectionRef = (0,
|
|
14507
|
+
const subcollectionRef = (0, import_firestore44.collection)(
|
|
14381
14508
|
this.db,
|
|
14382
14509
|
APPOINTMENTS_COLLECTION,
|
|
14383
14510
|
// Replaced "appointments"
|
|
14384
14511
|
appointmentId,
|
|
14385
14512
|
DOCTOR_FORMS_SUBCOLLECTION
|
|
14386
14513
|
);
|
|
14387
|
-
let q = (0,
|
|
14514
|
+
let q = (0, import_firestore44.query)(
|
|
14388
14515
|
subcollectionRef,
|
|
14389
|
-
(0,
|
|
14390
|
-
(0,
|
|
14516
|
+
(0, import_firestore44.orderBy)("updatedAt", "desc"),
|
|
14517
|
+
(0, import_firestore44.limit)(pageSize)
|
|
14391
14518
|
);
|
|
14392
14519
|
if (lastDoc) {
|
|
14393
|
-
q = (0,
|
|
14520
|
+
q = (0, import_firestore44.query)(q, (0, import_firestore44.startAfter)(lastDoc));
|
|
14394
14521
|
}
|
|
14395
14522
|
return this.executeQuery(q);
|
|
14396
14523
|
}
|
|
14397
14524
|
// Helper to execute query and return documents + lastDoc
|
|
14398
14525
|
async executeQuery(q) {
|
|
14399
|
-
const querySnapshot = await (0,
|
|
14526
|
+
const querySnapshot = await (0, import_firestore44.getDocs)(q);
|
|
14400
14527
|
const documents = [];
|
|
14401
14528
|
let lastVisible = null;
|
|
14402
14529
|
querySnapshot.forEach((doc38) => {
|
|
@@ -14560,14 +14687,14 @@ var FilledDocumentService = class extends BaseService {
|
|
|
14560
14687
|
};
|
|
14561
14688
|
|
|
14562
14689
|
// src/services/notifications/notification.service.ts
|
|
14563
|
-
var
|
|
14690
|
+
var import_firestore45 = require("firebase/firestore");
|
|
14564
14691
|
var NotificationService = class extends BaseService {
|
|
14565
14692
|
/**
|
|
14566
14693
|
* Kreira novu notifikaciju
|
|
14567
14694
|
*/
|
|
14568
14695
|
async createNotification(notification) {
|
|
14569
|
-
const notificationsRef = (0,
|
|
14570
|
-
const now =
|
|
14696
|
+
const notificationsRef = (0, import_firestore45.collection)(this.db, NOTIFICATIONS_COLLECTION);
|
|
14697
|
+
const now = import_firestore45.Timestamp.now();
|
|
14571
14698
|
const notificationData = {
|
|
14572
14699
|
...notification,
|
|
14573
14700
|
createdAt: now,
|
|
@@ -14576,7 +14703,7 @@ var NotificationService = class extends BaseService {
|
|
|
14576
14703
|
isRead: false,
|
|
14577
14704
|
userRole: notification.userRole || "patient" /* PATIENT */
|
|
14578
14705
|
};
|
|
14579
|
-
const docRef = await (0,
|
|
14706
|
+
const docRef = await (0, import_firestore45.addDoc)(notificationsRef, notificationData);
|
|
14580
14707
|
return {
|
|
14581
14708
|
...notificationData,
|
|
14582
14709
|
id: docRef.id
|
|
@@ -14586,12 +14713,12 @@ var NotificationService = class extends BaseService {
|
|
|
14586
14713
|
* Dohvata notifikaciju po ID-u
|
|
14587
14714
|
*/
|
|
14588
14715
|
async getNotification(notificationId) {
|
|
14589
|
-
const notificationRef = (0,
|
|
14716
|
+
const notificationRef = (0, import_firestore45.doc)(
|
|
14590
14717
|
this.db,
|
|
14591
14718
|
NOTIFICATIONS_COLLECTION,
|
|
14592
14719
|
notificationId
|
|
14593
14720
|
);
|
|
14594
|
-
const notificationDoc = await (0,
|
|
14721
|
+
const notificationDoc = await (0, import_firestore45.getDoc)(notificationRef);
|
|
14595
14722
|
if (!notificationDoc.exists()) {
|
|
14596
14723
|
return null;
|
|
14597
14724
|
}
|
|
@@ -14604,12 +14731,12 @@ var NotificationService = class extends BaseService {
|
|
|
14604
14731
|
* Dohvata sve notifikacije za korisnika
|
|
14605
14732
|
*/
|
|
14606
14733
|
async getUserNotifications(userId) {
|
|
14607
|
-
const q = (0,
|
|
14608
|
-
(0,
|
|
14609
|
-
(0,
|
|
14610
|
-
(0,
|
|
14734
|
+
const q = (0, import_firestore45.query)(
|
|
14735
|
+
(0, import_firestore45.collection)(this.db, NOTIFICATIONS_COLLECTION),
|
|
14736
|
+
(0, import_firestore45.where)("userId", "==", userId),
|
|
14737
|
+
(0, import_firestore45.orderBy)("notificationTime", "desc")
|
|
14611
14738
|
);
|
|
14612
|
-
const querySnapshot = await (0,
|
|
14739
|
+
const querySnapshot = await (0, import_firestore45.getDocs)(q);
|
|
14613
14740
|
return querySnapshot.docs.map((doc38) => ({
|
|
14614
14741
|
id: doc38.id,
|
|
14615
14742
|
...doc38.data()
|
|
@@ -14619,13 +14746,13 @@ var NotificationService = class extends BaseService {
|
|
|
14619
14746
|
* Dohvata nepročitane notifikacije za korisnika
|
|
14620
14747
|
*/
|
|
14621
14748
|
async getUnreadNotifications(userId) {
|
|
14622
|
-
const q = (0,
|
|
14623
|
-
(0,
|
|
14624
|
-
(0,
|
|
14625
|
-
(0,
|
|
14626
|
-
(0,
|
|
14749
|
+
const q = (0, import_firestore45.query)(
|
|
14750
|
+
(0, import_firestore45.collection)(this.db, NOTIFICATIONS_COLLECTION),
|
|
14751
|
+
(0, import_firestore45.where)("userId", "==", userId),
|
|
14752
|
+
(0, import_firestore45.where)("isRead", "==", false),
|
|
14753
|
+
(0, import_firestore45.orderBy)("notificationTime", "desc")
|
|
14627
14754
|
);
|
|
14628
|
-
const querySnapshot = await (0,
|
|
14755
|
+
const querySnapshot = await (0, import_firestore45.getDocs)(q);
|
|
14629
14756
|
return querySnapshot.docs.map((doc38) => ({
|
|
14630
14757
|
id: doc38.id,
|
|
14631
14758
|
...doc38.data()
|
|
@@ -14635,14 +14762,14 @@ var NotificationService = class extends BaseService {
|
|
|
14635
14762
|
* Označava notifikaciju kao pročitanu
|
|
14636
14763
|
*/
|
|
14637
14764
|
async markAsRead(notificationId) {
|
|
14638
|
-
const notificationRef = (0,
|
|
14765
|
+
const notificationRef = (0, import_firestore45.doc)(
|
|
14639
14766
|
this.db,
|
|
14640
14767
|
NOTIFICATIONS_COLLECTION,
|
|
14641
14768
|
notificationId
|
|
14642
14769
|
);
|
|
14643
|
-
await (0,
|
|
14770
|
+
await (0, import_firestore45.updateDoc)(notificationRef, {
|
|
14644
14771
|
isRead: true,
|
|
14645
|
-
updatedAt:
|
|
14772
|
+
updatedAt: import_firestore45.Timestamp.now()
|
|
14646
14773
|
});
|
|
14647
14774
|
}
|
|
14648
14775
|
/**
|
|
@@ -14650,16 +14777,16 @@ var NotificationService = class extends BaseService {
|
|
|
14650
14777
|
*/
|
|
14651
14778
|
async markAllAsRead(userId) {
|
|
14652
14779
|
const notifications = await this.getUnreadNotifications(userId);
|
|
14653
|
-
const batch = (0,
|
|
14780
|
+
const batch = (0, import_firestore45.writeBatch)(this.db);
|
|
14654
14781
|
notifications.forEach((notification) => {
|
|
14655
|
-
const notificationRef = (0,
|
|
14782
|
+
const notificationRef = (0, import_firestore45.doc)(
|
|
14656
14783
|
this.db,
|
|
14657
14784
|
NOTIFICATIONS_COLLECTION,
|
|
14658
14785
|
notification.id
|
|
14659
14786
|
);
|
|
14660
14787
|
batch.update(notificationRef, {
|
|
14661
14788
|
isRead: true,
|
|
14662
|
-
updatedAt:
|
|
14789
|
+
updatedAt: import_firestore45.Timestamp.now()
|
|
14663
14790
|
});
|
|
14664
14791
|
});
|
|
14665
14792
|
await batch.commit();
|
|
@@ -14668,38 +14795,38 @@ var NotificationService = class extends BaseService {
|
|
|
14668
14795
|
* Ažurira status notifikacije
|
|
14669
14796
|
*/
|
|
14670
14797
|
async updateNotificationStatus(notificationId, status) {
|
|
14671
|
-
const notificationRef = (0,
|
|
14798
|
+
const notificationRef = (0, import_firestore45.doc)(
|
|
14672
14799
|
this.db,
|
|
14673
14800
|
NOTIFICATIONS_COLLECTION,
|
|
14674
14801
|
notificationId
|
|
14675
14802
|
);
|
|
14676
|
-
await (0,
|
|
14803
|
+
await (0, import_firestore45.updateDoc)(notificationRef, {
|
|
14677
14804
|
status,
|
|
14678
|
-
updatedAt:
|
|
14805
|
+
updatedAt: import_firestore45.Timestamp.now()
|
|
14679
14806
|
});
|
|
14680
14807
|
}
|
|
14681
14808
|
/**
|
|
14682
14809
|
* Briše notifikaciju
|
|
14683
14810
|
*/
|
|
14684
14811
|
async deleteNotification(notificationId) {
|
|
14685
|
-
const notificationRef = (0,
|
|
14812
|
+
const notificationRef = (0, import_firestore45.doc)(
|
|
14686
14813
|
this.db,
|
|
14687
14814
|
NOTIFICATIONS_COLLECTION,
|
|
14688
14815
|
notificationId
|
|
14689
14816
|
);
|
|
14690
|
-
await (0,
|
|
14817
|
+
await (0, import_firestore45.deleteDoc)(notificationRef);
|
|
14691
14818
|
}
|
|
14692
14819
|
/**
|
|
14693
14820
|
* Dohvata notifikacije po tipu
|
|
14694
14821
|
*/
|
|
14695
14822
|
async getNotificationsByType(userId, type) {
|
|
14696
|
-
const q = (0,
|
|
14697
|
-
(0,
|
|
14698
|
-
(0,
|
|
14699
|
-
(0,
|
|
14700
|
-
(0,
|
|
14823
|
+
const q = (0, import_firestore45.query)(
|
|
14824
|
+
(0, import_firestore45.collection)(this.db, NOTIFICATIONS_COLLECTION),
|
|
14825
|
+
(0, import_firestore45.where)("userId", "==", userId),
|
|
14826
|
+
(0, import_firestore45.where)("notificationType", "==", type),
|
|
14827
|
+
(0, import_firestore45.orderBy)("notificationTime", "desc")
|
|
14701
14828
|
);
|
|
14702
|
-
const querySnapshot = await (0,
|
|
14829
|
+
const querySnapshot = await (0, import_firestore45.getDocs)(q);
|
|
14703
14830
|
return querySnapshot.docs.map((doc38) => ({
|
|
14704
14831
|
id: doc38.id,
|
|
14705
14832
|
...doc38.data()
|
|
@@ -14709,12 +14836,12 @@ var NotificationService = class extends BaseService {
|
|
|
14709
14836
|
* Dohvata notifikacije za određeni termin
|
|
14710
14837
|
*/
|
|
14711
14838
|
async getAppointmentNotifications(appointmentId) {
|
|
14712
|
-
const q = (0,
|
|
14713
|
-
(0,
|
|
14714
|
-
(0,
|
|
14715
|
-
(0,
|
|
14839
|
+
const q = (0, import_firestore45.query)(
|
|
14840
|
+
(0, import_firestore45.collection)(this.db, NOTIFICATIONS_COLLECTION),
|
|
14841
|
+
(0, import_firestore45.where)("appointmentId", "==", appointmentId),
|
|
14842
|
+
(0, import_firestore45.orderBy)("notificationTime", "desc")
|
|
14716
14843
|
);
|
|
14717
|
-
const querySnapshot = await (0,
|
|
14844
|
+
const querySnapshot = await (0, import_firestore45.getDocs)(q);
|
|
14718
14845
|
return querySnapshot.docs.map((doc38) => ({
|
|
14719
14846
|
id: doc38.id,
|
|
14720
14847
|
...doc38.data()
|
|
@@ -14723,19 +14850,19 @@ var NotificationService = class extends BaseService {
|
|
|
14723
14850
|
};
|
|
14724
14851
|
|
|
14725
14852
|
// src/services/patient/patientRequirements.service.ts
|
|
14726
|
-
var
|
|
14853
|
+
var import_firestore46 = require("firebase/firestore");
|
|
14727
14854
|
var PatientRequirementsService = class extends BaseService {
|
|
14728
14855
|
constructor(db, auth, app) {
|
|
14729
14856
|
super(db, auth, app);
|
|
14730
14857
|
}
|
|
14731
14858
|
getPatientRequirementsCollectionRef(patientId) {
|
|
14732
|
-
return (0,
|
|
14859
|
+
return (0, import_firestore46.collection)(
|
|
14733
14860
|
this.db,
|
|
14734
14861
|
`patients/${patientId}/${PATIENT_REQUIREMENTS_SUBCOLLECTION_NAME}`
|
|
14735
14862
|
);
|
|
14736
14863
|
}
|
|
14737
14864
|
getPatientRequirementDocRef(patientId, instanceId) {
|
|
14738
|
-
return (0,
|
|
14865
|
+
return (0, import_firestore46.doc)(
|
|
14739
14866
|
this.getPatientRequirementsCollectionRef(patientId),
|
|
14740
14867
|
instanceId
|
|
14741
14868
|
);
|
|
@@ -14748,7 +14875,7 @@ var PatientRequirementsService = class extends BaseService {
|
|
|
14748
14875
|
*/
|
|
14749
14876
|
async getPatientRequirementInstance(patientId, instanceId) {
|
|
14750
14877
|
const docRef = this.getPatientRequirementDocRef(patientId, instanceId);
|
|
14751
|
-
const docSnap = await (0,
|
|
14878
|
+
const docSnap = await (0, import_firestore46.getDoc)(docRef);
|
|
14752
14879
|
if (!docSnap.exists()) {
|
|
14753
14880
|
return null;
|
|
14754
14881
|
}
|
|
@@ -14767,22 +14894,22 @@ var PatientRequirementsService = class extends BaseService {
|
|
|
14767
14894
|
*/
|
|
14768
14895
|
async getAllPatientRequirementInstances(patientId, filters, pageLimit = 20, lastVisible) {
|
|
14769
14896
|
const collRef = this.getPatientRequirementsCollectionRef(patientId);
|
|
14770
|
-
let q = (0,
|
|
14897
|
+
let q = (0, import_firestore46.query)(collRef, (0, import_firestore46.orderBy)("createdAt", "desc"));
|
|
14771
14898
|
const queryConstraints = [];
|
|
14772
14899
|
if ((filters == null ? void 0 : filters.appointmentId) && filters.appointmentId !== "all") {
|
|
14773
14900
|
queryConstraints.push(
|
|
14774
|
-
(0,
|
|
14901
|
+
(0, import_firestore46.where)("appointmentId", "==", filters.appointmentId)
|
|
14775
14902
|
);
|
|
14776
14903
|
}
|
|
14777
14904
|
if ((filters == null ? void 0 : filters.statuses) && filters.statuses.length > 0) {
|
|
14778
|
-
queryConstraints.push((0,
|
|
14905
|
+
queryConstraints.push((0, import_firestore46.where)("overallStatus", "in", filters.statuses));
|
|
14779
14906
|
}
|
|
14780
14907
|
if (lastVisible) {
|
|
14781
|
-
queryConstraints.push((0,
|
|
14908
|
+
queryConstraints.push((0, import_firestore46.startAfter)(lastVisible));
|
|
14782
14909
|
}
|
|
14783
|
-
queryConstraints.push((0,
|
|
14784
|
-
q = (0,
|
|
14785
|
-
const snapshot = await (0,
|
|
14910
|
+
queryConstraints.push((0, import_firestore46.limit)(pageLimit));
|
|
14911
|
+
q = (0, import_firestore46.query)(collRef, ...queryConstraints);
|
|
14912
|
+
const snapshot = await (0, import_firestore46.getDocs)(q);
|
|
14786
14913
|
let requirements = snapshot.docs.map((docSnap) => {
|
|
14787
14914
|
const data = docSnap.data();
|
|
14788
14915
|
return { id: docSnap.id, ...data };
|
|
@@ -14825,7 +14952,7 @@ var PatientRequirementsService = class extends BaseService {
|
|
|
14825
14952
|
*/
|
|
14826
14953
|
async completeInstruction(patientId, instanceId, instructionId) {
|
|
14827
14954
|
const instanceRef = this.getPatientRequirementDocRef(patientId, instanceId);
|
|
14828
|
-
const instanceSnap = await (0,
|
|
14955
|
+
const instanceSnap = await (0, import_firestore46.getDoc)(instanceRef);
|
|
14829
14956
|
if (!instanceSnap.exists()) {
|
|
14830
14957
|
throw new Error(
|
|
14831
14958
|
`PatientRequirementInstance ${instanceId} not found for patient ${patientId}.`
|
|
@@ -14853,7 +14980,7 @@ var PatientRequirementsService = class extends BaseService {
|
|
|
14853
14980
|
`Instruction ${instructionId} is in status ${instructionToUpdate.status} and cannot be marked as completed.`
|
|
14854
14981
|
);
|
|
14855
14982
|
}
|
|
14856
|
-
const now =
|
|
14983
|
+
const now = import_firestore46.Timestamp.now();
|
|
14857
14984
|
const updatedInstructions = [...instance.instructions];
|
|
14858
14985
|
updatedInstructions[instructionIndex] = {
|
|
14859
14986
|
...instructionToUpdate,
|
|
@@ -14880,7 +15007,7 @@ var PatientRequirementsService = class extends BaseService {
|
|
|
14880
15007
|
if (newOverallStatus !== instance.overallStatus) {
|
|
14881
15008
|
updatePayload.overallStatus = newOverallStatus;
|
|
14882
15009
|
}
|
|
14883
|
-
await (0,
|
|
15010
|
+
await (0, import_firestore46.updateDoc)(instanceRef, updatePayload);
|
|
14884
15011
|
return {
|
|
14885
15012
|
...instance,
|
|
14886
15013
|
instructions: updatedInstructions,
|
|
@@ -14893,7 +15020,7 @@ var PatientRequirementsService = class extends BaseService {
|
|
|
14893
15020
|
};
|
|
14894
15021
|
|
|
14895
15022
|
// src/services/procedure/procedure.service.ts
|
|
14896
|
-
var
|
|
15023
|
+
var import_firestore47 = require("firebase/firestore");
|
|
14897
15024
|
|
|
14898
15025
|
// src/validations/procedure.schema.ts
|
|
14899
15026
|
var import_zod25 = require("zod");
|
|
@@ -15139,14 +15266,14 @@ var ProcedureService = class extends BaseService {
|
|
|
15139
15266
|
if (!category || !subcategory || !technology || !product) {
|
|
15140
15267
|
throw new Error("One or more required base entities not found");
|
|
15141
15268
|
}
|
|
15142
|
-
const clinicRef = (0,
|
|
15143
|
-
const clinicSnapshot = await (0,
|
|
15269
|
+
const clinicRef = (0, import_firestore47.doc)(this.db, CLINICS_COLLECTION, validatedData.clinicBranchId);
|
|
15270
|
+
const clinicSnapshot = await (0, import_firestore47.getDoc)(clinicRef);
|
|
15144
15271
|
if (!clinicSnapshot.exists()) {
|
|
15145
15272
|
throw new Error(`Clinic with ID ${validatedData.clinicBranchId} not found`);
|
|
15146
15273
|
}
|
|
15147
15274
|
const clinic = clinicSnapshot.data();
|
|
15148
|
-
const practitionerRef = (0,
|
|
15149
|
-
const practitionerSnapshot = await (0,
|
|
15275
|
+
const practitionerRef = (0, import_firestore47.doc)(this.db, PRACTITIONERS_COLLECTION, validatedData.practitionerId);
|
|
15276
|
+
const practitionerSnapshot = await (0, import_firestore47.getDoc)(practitionerRef);
|
|
15150
15277
|
if (!practitionerSnapshot.exists()) {
|
|
15151
15278
|
throw new Error(`Practitioner with ID ${validatedData.practitionerId} not found`);
|
|
15152
15279
|
}
|
|
@@ -15221,13 +15348,13 @@ var ProcedureService = class extends BaseService {
|
|
|
15221
15348
|
isActive: true
|
|
15222
15349
|
// Default to active
|
|
15223
15350
|
};
|
|
15224
|
-
const procedureRef = (0,
|
|
15225
|
-
await (0,
|
|
15351
|
+
const procedureRef = (0, import_firestore47.doc)(this.db, PROCEDURES_COLLECTION, procedureId);
|
|
15352
|
+
await (0, import_firestore47.setDoc)(procedureRef, {
|
|
15226
15353
|
...newProcedure,
|
|
15227
|
-
createdAt: (0,
|
|
15228
|
-
updatedAt: (0,
|
|
15354
|
+
createdAt: (0, import_firestore47.serverTimestamp)(),
|
|
15355
|
+
updatedAt: (0, import_firestore47.serverTimestamp)()
|
|
15229
15356
|
});
|
|
15230
|
-
const savedDoc = await (0,
|
|
15357
|
+
const savedDoc = await (0, import_firestore47.getDoc)(procedureRef);
|
|
15231
15358
|
return savedDoc.data();
|
|
15232
15359
|
}
|
|
15233
15360
|
/**
|
|
@@ -15250,7 +15377,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15250
15377
|
this.subcategoryService.getById(validatedData.categoryId, validatedData.subcategoryId),
|
|
15251
15378
|
this.technologyService.getById(validatedData.technologyId),
|
|
15252
15379
|
this.productService.getById(validatedData.technologyId, validatedData.productId),
|
|
15253
|
-
(0,
|
|
15380
|
+
(0, import_firestore47.getDoc)((0, import_firestore47.doc)(this.db, CLINICS_COLLECTION, validatedData.clinicBranchId))
|
|
15254
15381
|
]);
|
|
15255
15382
|
if (!category || !subcategory || !technology || !product) {
|
|
15256
15383
|
throw new Error("One or more required base entities not found");
|
|
@@ -15275,11 +15402,11 @@ var ProcedureService = class extends BaseService {
|
|
|
15275
15402
|
const practitionersMap = /* @__PURE__ */ new Map();
|
|
15276
15403
|
for (let i = 0; i < practitionerIds.length; i += 30) {
|
|
15277
15404
|
const chunk = practitionerIds.slice(i, i + 30);
|
|
15278
|
-
const practitionersQuery = (0,
|
|
15279
|
-
(0,
|
|
15280
|
-
(0,
|
|
15405
|
+
const practitionersQuery = (0, import_firestore47.query)(
|
|
15406
|
+
(0, import_firestore47.collection)(this.db, PRACTITIONERS_COLLECTION),
|
|
15407
|
+
(0, import_firestore47.where)((0, import_firestore47.documentId)(), "in", chunk)
|
|
15281
15408
|
);
|
|
15282
|
-
const practitionersSnapshot = await (0,
|
|
15409
|
+
const practitionersSnapshot = await (0, import_firestore47.getDocs)(practitionersQuery);
|
|
15283
15410
|
practitionersSnapshot.docs.forEach((doc38) => {
|
|
15284
15411
|
practitionersMap.set(doc38.id, doc38.data());
|
|
15285
15412
|
});
|
|
@@ -15289,7 +15416,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15289
15416
|
const notFoundIds = practitionerIds.filter((id) => !foundIds.includes(id));
|
|
15290
15417
|
throw new Error(`The following practitioners were not found: ${notFoundIds.join(", ")}`);
|
|
15291
15418
|
}
|
|
15292
|
-
const batch = (0,
|
|
15419
|
+
const batch = (0, import_firestore47.writeBatch)(this.db);
|
|
15293
15420
|
const createdProcedureIds = [];
|
|
15294
15421
|
const clinicInfo = {
|
|
15295
15422
|
id: clinicSnapshot.id,
|
|
@@ -15311,7 +15438,7 @@ var ProcedureService = class extends BaseService {
|
|
|
15311
15438
|
};
|
|
15312
15439
|
const procedureId = this.generateId();
|
|
15313
15440
|
createdProcedureIds.push(procedureId);
|
|
15314
|
-
const procedureRef = (0,
|
|
15441
|
+
const procedureRef = (0, import_firestore47.doc)(this.db, PROCEDURES_COLLECTION, procedureId);
|
|
15315
15442
|
const { productsMetadata: _, ...validatedDataWithoutProductsMetadata } = validatedData;
|
|
15316
15443
|
const newProcedure = {
|
|
15317
15444
|
id: procedureId,
|
|
@@ -15352,16 +15479,16 @@ var ProcedureService = class extends BaseService {
|
|
|
15352
15479
|
};
|
|
15353
15480
|
batch.set(procedureRef, {
|
|
15354
15481
|
...newProcedure,
|
|
15355
|
-
createdAt: (0,
|
|
15356
|
-
updatedAt: (0,
|
|
15482
|
+
createdAt: (0, import_firestore47.serverTimestamp)(),
|
|
15483
|
+
updatedAt: (0, import_firestore47.serverTimestamp)()
|
|
15357
15484
|
});
|
|
15358
15485
|
}
|
|
15359
15486
|
await batch.commit();
|
|
15360
15487
|
const fetchedProcedures = [];
|
|
15361
15488
|
for (let i = 0; i < createdProcedureIds.length; i += 30) {
|
|
15362
15489
|
const chunk = createdProcedureIds.slice(i, i + 30);
|
|
15363
|
-
const q = (0,
|
|
15364
|
-
const snapshot = await (0,
|
|
15490
|
+
const q = (0, import_firestore47.query)((0, import_firestore47.collection)(this.db, PROCEDURES_COLLECTION), (0, import_firestore47.where)((0, import_firestore47.documentId)(), "in", chunk));
|
|
15491
|
+
const snapshot = await (0, import_firestore47.getDocs)(q);
|
|
15365
15492
|
snapshot.forEach((doc38) => {
|
|
15366
15493
|
fetchedProcedures.push(doc38.data());
|
|
15367
15494
|
});
|
|
@@ -15374,8 +15501,8 @@ var ProcedureService = class extends BaseService {
|
|
|
15374
15501
|
* @returns The procedure if found, null otherwise
|
|
15375
15502
|
*/
|
|
15376
15503
|
async getProcedure(id) {
|
|
15377
|
-
const docRef = (0,
|
|
15378
|
-
const docSnap = await (0,
|
|
15504
|
+
const docRef = (0, import_firestore47.doc)(this.db, PROCEDURES_COLLECTION, id);
|
|
15505
|
+
const docSnap = await (0, import_firestore47.getDoc)(docRef);
|
|
15379
15506
|
if (!docSnap.exists()) {
|
|
15380
15507
|
return null;
|
|
15381
15508
|
}
|
|
@@ -15387,12 +15514,12 @@ var ProcedureService = class extends BaseService {
|
|
|
15387
15514
|
* @returns List of procedures
|
|
15388
15515
|
*/
|
|
15389
15516
|
async getProceduresByClinicBranch(clinicBranchId) {
|
|
15390
|
-
const q = (0,
|
|
15391
|
-
(0,
|
|
15392
|
-
(0,
|
|
15393
|
-
(0,
|
|
15517
|
+
const q = (0, import_firestore47.query)(
|
|
15518
|
+
(0, import_firestore47.collection)(this.db, PROCEDURES_COLLECTION),
|
|
15519
|
+
(0, import_firestore47.where)("clinicBranchId", "==", clinicBranchId),
|
|
15520
|
+
(0, import_firestore47.where)("isActive", "==", true)
|
|
15394
15521
|
);
|
|
15395
|
-
const snapshot = await (0,
|
|
15522
|
+
const snapshot = await (0, import_firestore47.getDocs)(q);
|
|
15396
15523
|
return snapshot.docs.map((doc38) => doc38.data());
|
|
15397
15524
|
}
|
|
15398
15525
|
/**
|
|
@@ -15401,12 +15528,12 @@ var ProcedureService = class extends BaseService {
|
|
|
15401
15528
|
* @returns List of procedures
|
|
15402
15529
|
*/
|
|
15403
15530
|
async getProceduresByPractitioner(practitionerId) {
|
|
15404
|
-
const q = (0,
|
|
15405
|
-
(0,
|
|
15406
|
-
(0,
|
|
15407
|
-
(0,
|
|
15531
|
+
const q = (0, import_firestore47.query)(
|
|
15532
|
+
(0, import_firestore47.collection)(this.db, PROCEDURES_COLLECTION),
|
|
15533
|
+
(0, import_firestore47.where)("practitionerId", "==", practitionerId),
|
|
15534
|
+
(0, import_firestore47.where)("isActive", "==", true)
|
|
15408
15535
|
);
|
|
15409
|
-
const snapshot = await (0,
|
|
15536
|
+
const snapshot = await (0, import_firestore47.getDocs)(q);
|
|
15410
15537
|
return snapshot.docs.map((doc38) => doc38.data());
|
|
15411
15538
|
}
|
|
15412
15539
|
/**
|
|
@@ -15415,12 +15542,12 @@ var ProcedureService = class extends BaseService {
|
|
|
15415
15542
|
* @returns List of inactive procedures
|
|
15416
15543
|
*/
|
|
15417
15544
|
async getInactiveProceduresByPractitioner(practitionerId) {
|
|
15418
|
-
const q = (0,
|
|
15419
|
-
(0,
|
|
15420
|
-
(0,
|
|
15421
|
-
(0,
|
|
15545
|
+
const q = (0, import_firestore47.query)(
|
|
15546
|
+
(0, import_firestore47.collection)(this.db, PROCEDURES_COLLECTION),
|
|
15547
|
+
(0, import_firestore47.where)("practitionerId", "==", practitionerId),
|
|
15548
|
+
(0, import_firestore47.where)("isActive", "==", false)
|
|
15422
15549
|
);
|
|
15423
|
-
const snapshot = await (0,
|
|
15550
|
+
const snapshot = await (0, import_firestore47.getDocs)(q);
|
|
15424
15551
|
return snapshot.docs.map((doc38) => doc38.data());
|
|
15425
15552
|
}
|
|
15426
15553
|
/**
|
|
@@ -15432,8 +15559,8 @@ var ProcedureService = class extends BaseService {
|
|
|
15432
15559
|
async updateProcedure(id, data) {
|
|
15433
15560
|
var _a, _b, _c, _d;
|
|
15434
15561
|
const validatedData = updateProcedureSchema.parse(data);
|
|
15435
|
-
const procedureRef = (0,
|
|
15436
|
-
const procedureSnapshot = await (0,
|
|
15562
|
+
const procedureRef = (0, import_firestore47.doc)(this.db, PROCEDURES_COLLECTION, id);
|
|
15563
|
+
const procedureSnapshot = await (0, import_firestore47.getDoc)(procedureRef);
|
|
15437
15564
|
if (!procedureSnapshot.exists()) {
|
|
15438
15565
|
throw new Error(`Procedure with ID ${id} not found`);
|
|
15439
15566
|
}
|
|
@@ -15476,12 +15603,12 @@ var ProcedureService = class extends BaseService {
|
|
|
15476
15603
|
}
|
|
15477
15604
|
if (validatedData.practitionerId && validatedData.practitionerId !== oldPractitionerId) {
|
|
15478
15605
|
practitionerChanged = true;
|
|
15479
|
-
const newPractitionerRef = (0,
|
|
15606
|
+
const newPractitionerRef = (0, import_firestore47.doc)(
|
|
15480
15607
|
this.db,
|
|
15481
15608
|
PRACTITIONERS_COLLECTION,
|
|
15482
15609
|
validatedData.practitionerId
|
|
15483
15610
|
);
|
|
15484
|
-
const newPractitionerSnap = await (0,
|
|
15611
|
+
const newPractitionerSnap = await (0, import_firestore47.getDoc)(newPractitionerRef);
|
|
15485
15612
|
if (!newPractitionerSnap.exists())
|
|
15486
15613
|
throw new Error(`New Practitioner ${validatedData.practitionerId} not found`);
|
|
15487
15614
|
newPractitioner = newPractitionerSnap.data();
|
|
@@ -15497,8 +15624,8 @@ var ProcedureService = class extends BaseService {
|
|
|
15497
15624
|
}
|
|
15498
15625
|
if (validatedData.clinicBranchId && validatedData.clinicBranchId !== oldClinicId) {
|
|
15499
15626
|
clinicChanged = true;
|
|
15500
|
-
const newClinicRef = (0,
|
|
15501
|
-
const newClinicSnap = await (0,
|
|
15627
|
+
const newClinicRef = (0, import_firestore47.doc)(this.db, CLINICS_COLLECTION, validatedData.clinicBranchId);
|
|
15628
|
+
const newClinicSnap = await (0, import_firestore47.getDoc)(newClinicRef);
|
|
15502
15629
|
if (!newClinicSnap.exists())
|
|
15503
15630
|
throw new Error(`New Clinic ${validatedData.clinicBranchId} not found`);
|
|
15504
15631
|
newClinic = newClinicSnap.data();
|
|
@@ -15560,11 +15687,11 @@ var ProcedureService = class extends BaseService {
|
|
|
15560
15687
|
} else if (validatedData.productId) {
|
|
15561
15688
|
console.warn("Attempted to update product without a valid technologyId");
|
|
15562
15689
|
}
|
|
15563
|
-
await (0,
|
|
15690
|
+
await (0, import_firestore47.updateDoc)(procedureRef, {
|
|
15564
15691
|
...updatedProcedureData,
|
|
15565
|
-
updatedAt: (0,
|
|
15692
|
+
updatedAt: (0, import_firestore47.serverTimestamp)()
|
|
15566
15693
|
});
|
|
15567
|
-
const updatedSnapshot = await (0,
|
|
15694
|
+
const updatedSnapshot = await (0, import_firestore47.getDoc)(procedureRef);
|
|
15568
15695
|
return updatedSnapshot.data();
|
|
15569
15696
|
}
|
|
15570
15697
|
/**
|
|
@@ -15572,15 +15699,15 @@ var ProcedureService = class extends BaseService {
|
|
|
15572
15699
|
* @param id - The ID of the procedure to deactivate
|
|
15573
15700
|
*/
|
|
15574
15701
|
async deactivateProcedure(id) {
|
|
15575
|
-
const procedureRef = (0,
|
|
15576
|
-
const procedureSnap = await (0,
|
|
15702
|
+
const procedureRef = (0, import_firestore47.doc)(this.db, PROCEDURES_COLLECTION, id);
|
|
15703
|
+
const procedureSnap = await (0, import_firestore47.getDoc)(procedureRef);
|
|
15577
15704
|
if (!procedureSnap.exists()) {
|
|
15578
15705
|
console.warn(`Procedure ${id} not found for deactivation.`);
|
|
15579
15706
|
return;
|
|
15580
15707
|
}
|
|
15581
|
-
await (0,
|
|
15708
|
+
await (0, import_firestore47.updateDoc)(procedureRef, {
|
|
15582
15709
|
isActive: false,
|
|
15583
|
-
updatedAt: (0,
|
|
15710
|
+
updatedAt: (0, import_firestore47.serverTimestamp)()
|
|
15584
15711
|
});
|
|
15585
15712
|
}
|
|
15586
15713
|
/**
|
|
@@ -15589,12 +15716,12 @@ var ProcedureService = class extends BaseService {
|
|
|
15589
15716
|
* @returns A boolean indicating if the deletion was successful
|
|
15590
15717
|
*/
|
|
15591
15718
|
async deleteProcedure(id) {
|
|
15592
|
-
const procedureRef = (0,
|
|
15593
|
-
const procedureSnapshot = await (0,
|
|
15719
|
+
const procedureRef = (0, import_firestore47.doc)(this.db, PROCEDURES_COLLECTION, id);
|
|
15720
|
+
const procedureSnapshot = await (0, import_firestore47.getDoc)(procedureRef);
|
|
15594
15721
|
if (!procedureSnapshot.exists()) {
|
|
15595
15722
|
return false;
|
|
15596
15723
|
}
|
|
15597
|
-
await (0,
|
|
15724
|
+
await (0, import_firestore47.deleteDoc)(procedureRef);
|
|
15598
15725
|
return true;
|
|
15599
15726
|
}
|
|
15600
15727
|
/**
|
|
@@ -15620,25 +15747,25 @@ var ProcedureService = class extends BaseService {
|
|
|
15620
15747
|
*/
|
|
15621
15748
|
async getAllProcedures(pagination, lastDoc) {
|
|
15622
15749
|
try {
|
|
15623
|
-
const proceduresCollection = (0,
|
|
15624
|
-
let proceduresQuery = (0,
|
|
15750
|
+
const proceduresCollection = (0, import_firestore47.collection)(this.db, PROCEDURES_COLLECTION);
|
|
15751
|
+
let proceduresQuery = (0, import_firestore47.query)(proceduresCollection);
|
|
15625
15752
|
if (pagination && pagination > 0) {
|
|
15626
|
-
const { limit:
|
|
15753
|
+
const { limit: limit22, startAfter: startAfter20 } = await import("firebase/firestore");
|
|
15627
15754
|
if (lastDoc) {
|
|
15628
|
-
proceduresQuery = (0,
|
|
15755
|
+
proceduresQuery = (0, import_firestore47.query)(
|
|
15629
15756
|
proceduresCollection,
|
|
15630
|
-
(0,
|
|
15757
|
+
(0, import_firestore47.orderBy)("name"),
|
|
15631
15758
|
// Use imported orderBy
|
|
15632
|
-
|
|
15633
|
-
|
|
15759
|
+
startAfter20(lastDoc),
|
|
15760
|
+
limit22(pagination)
|
|
15634
15761
|
);
|
|
15635
15762
|
} else {
|
|
15636
|
-
proceduresQuery = (0,
|
|
15763
|
+
proceduresQuery = (0, import_firestore47.query)(proceduresCollection, (0, import_firestore47.orderBy)("name"), limit22(pagination));
|
|
15637
15764
|
}
|
|
15638
15765
|
} else {
|
|
15639
|
-
proceduresQuery = (0,
|
|
15766
|
+
proceduresQuery = (0, import_firestore47.query)(proceduresCollection, (0, import_firestore47.orderBy)("name"));
|
|
15640
15767
|
}
|
|
15641
|
-
const proceduresSnapshot = await (0,
|
|
15768
|
+
const proceduresSnapshot = await (0, import_firestore47.getDocs)(proceduresQuery);
|
|
15642
15769
|
const lastVisible = proceduresSnapshot.docs[proceduresSnapshot.docs.length - 1];
|
|
15643
15770
|
const procedures = proceduresSnapshot.docs.map((doc38) => {
|
|
15644
15771
|
const data = doc38.data();
|
|
@@ -15702,37 +15829,37 @@ var ProcedureService = class extends BaseService {
|
|
|
15702
15829
|
const getBaseConstraints = () => {
|
|
15703
15830
|
const constraints = [];
|
|
15704
15831
|
if (filters.isActive !== void 0) {
|
|
15705
|
-
constraints.push((0,
|
|
15832
|
+
constraints.push((0, import_firestore47.where)("isActive", "==", filters.isActive));
|
|
15706
15833
|
} else {
|
|
15707
|
-
constraints.push((0,
|
|
15834
|
+
constraints.push((0, import_firestore47.where)("isActive", "==", true));
|
|
15708
15835
|
}
|
|
15709
15836
|
if (filters.procedureFamily) {
|
|
15710
|
-
constraints.push((0,
|
|
15837
|
+
constraints.push((0, import_firestore47.where)("family", "==", filters.procedureFamily));
|
|
15711
15838
|
}
|
|
15712
15839
|
if (filters.procedureCategory) {
|
|
15713
|
-
constraints.push((0,
|
|
15840
|
+
constraints.push((0, import_firestore47.where)("category.id", "==", filters.procedureCategory));
|
|
15714
15841
|
}
|
|
15715
15842
|
if (filters.procedureSubcategory) {
|
|
15716
|
-
constraints.push((0,
|
|
15843
|
+
constraints.push((0, import_firestore47.where)("subcategory.id", "==", filters.procedureSubcategory));
|
|
15717
15844
|
}
|
|
15718
15845
|
if (filters.procedureTechnology) {
|
|
15719
|
-
constraints.push((0,
|
|
15846
|
+
constraints.push((0, import_firestore47.where)("technology.id", "==", filters.procedureTechnology));
|
|
15720
15847
|
}
|
|
15721
15848
|
if (filters.minPrice !== void 0) {
|
|
15722
|
-
constraints.push((0,
|
|
15849
|
+
constraints.push((0, import_firestore47.where)("price", ">=", filters.minPrice));
|
|
15723
15850
|
}
|
|
15724
15851
|
if (filters.maxPrice !== void 0) {
|
|
15725
|
-
constraints.push((0,
|
|
15852
|
+
constraints.push((0, import_firestore47.where)("price", "<=", filters.maxPrice));
|
|
15726
15853
|
}
|
|
15727
15854
|
if (filters.minRating !== void 0) {
|
|
15728
|
-
constraints.push((0,
|
|
15855
|
+
constraints.push((0, import_firestore47.where)("reviewInfo.averageRating", ">=", filters.minRating));
|
|
15729
15856
|
}
|
|
15730
15857
|
if (filters.maxRating !== void 0) {
|
|
15731
|
-
constraints.push((0,
|
|
15858
|
+
constraints.push((0, import_firestore47.where)("reviewInfo.averageRating", "<=", filters.maxRating));
|
|
15732
15859
|
}
|
|
15733
15860
|
if (filters.treatmentBenefits && filters.treatmentBenefits.length > 0) {
|
|
15734
15861
|
const benefitIdsToMatch = filters.treatmentBenefits;
|
|
15735
|
-
constraints.push((0,
|
|
15862
|
+
constraints.push((0, import_firestore47.where)("treatmentBenefitIds", "array-contains-any", benefitIdsToMatch));
|
|
15736
15863
|
}
|
|
15737
15864
|
return constraints;
|
|
15738
15865
|
};
|
|
@@ -15741,21 +15868,21 @@ var ProcedureService = class extends BaseService {
|
|
|
15741
15868
|
console.log("[PROCEDURE_SERVICE] Strategy 1: Trying nameLower search");
|
|
15742
15869
|
const searchTerm = filters.nameSearch.trim().toLowerCase();
|
|
15743
15870
|
const constraints = getBaseConstraints();
|
|
15744
|
-
constraints.push((0,
|
|
15745
|
-
constraints.push((0,
|
|
15746
|
-
constraints.push((0,
|
|
15871
|
+
constraints.push((0, import_firestore47.where)("nameLower", ">=", searchTerm));
|
|
15872
|
+
constraints.push((0, import_firestore47.where)("nameLower", "<=", searchTerm + "\uF8FF"));
|
|
15873
|
+
constraints.push((0, import_firestore47.orderBy)("nameLower"));
|
|
15747
15874
|
if (filters.lastDoc) {
|
|
15748
15875
|
if (typeof filters.lastDoc.data === "function") {
|
|
15749
|
-
constraints.push((0,
|
|
15876
|
+
constraints.push((0, import_firestore47.startAfter)(filters.lastDoc));
|
|
15750
15877
|
} else if (Array.isArray(filters.lastDoc)) {
|
|
15751
|
-
constraints.push((0,
|
|
15878
|
+
constraints.push((0, import_firestore47.startAfter)(...filters.lastDoc));
|
|
15752
15879
|
} else {
|
|
15753
|
-
constraints.push((0,
|
|
15880
|
+
constraints.push((0, import_firestore47.startAfter)(filters.lastDoc));
|
|
15754
15881
|
}
|
|
15755
15882
|
}
|
|
15756
|
-
constraints.push((0,
|
|
15757
|
-
const q = (0,
|
|
15758
|
-
const querySnapshot = await (0,
|
|
15883
|
+
constraints.push((0, import_firestore47.limit)(filters.pagination || 10));
|
|
15884
|
+
const q = (0, import_firestore47.query)((0, import_firestore47.collection)(this.db, PROCEDURES_COLLECTION), ...constraints);
|
|
15885
|
+
const querySnapshot = await (0, import_firestore47.getDocs)(q);
|
|
15759
15886
|
const procedures = querySnapshot.docs.map(
|
|
15760
15887
|
(doc38) => ({ ...doc38.data(), id: doc38.id })
|
|
15761
15888
|
);
|
|
@@ -15774,21 +15901,21 @@ var ProcedureService = class extends BaseService {
|
|
|
15774
15901
|
console.log("[PROCEDURE_SERVICE] Strategy 2: Trying name field search");
|
|
15775
15902
|
const searchTerm = filters.nameSearch.trim().toLowerCase();
|
|
15776
15903
|
const constraints = getBaseConstraints();
|
|
15777
|
-
constraints.push((0,
|
|
15778
|
-
constraints.push((0,
|
|
15779
|
-
constraints.push((0,
|
|
15904
|
+
constraints.push((0, import_firestore47.where)("name", ">=", searchTerm));
|
|
15905
|
+
constraints.push((0, import_firestore47.where)("name", "<=", searchTerm + "\uF8FF"));
|
|
15906
|
+
constraints.push((0, import_firestore47.orderBy)("name"));
|
|
15780
15907
|
if (filters.lastDoc) {
|
|
15781
15908
|
if (typeof filters.lastDoc.data === "function") {
|
|
15782
|
-
constraints.push((0,
|
|
15909
|
+
constraints.push((0, import_firestore47.startAfter)(filters.lastDoc));
|
|
15783
15910
|
} else if (Array.isArray(filters.lastDoc)) {
|
|
15784
|
-
constraints.push((0,
|
|
15911
|
+
constraints.push((0, import_firestore47.startAfter)(...filters.lastDoc));
|
|
15785
15912
|
} else {
|
|
15786
|
-
constraints.push((0,
|
|
15913
|
+
constraints.push((0, import_firestore47.startAfter)(filters.lastDoc));
|
|
15787
15914
|
}
|
|
15788
15915
|
}
|
|
15789
|
-
constraints.push((0,
|
|
15790
|
-
const q = (0,
|
|
15791
|
-
const querySnapshot = await (0,
|
|
15916
|
+
constraints.push((0, import_firestore47.limit)(filters.pagination || 10));
|
|
15917
|
+
const q = (0, import_firestore47.query)((0, import_firestore47.collection)(this.db, PROCEDURES_COLLECTION), ...constraints);
|
|
15918
|
+
const querySnapshot = await (0, import_firestore47.getDocs)(q);
|
|
15792
15919
|
const procedures = querySnapshot.docs.map(
|
|
15793
15920
|
(doc38) => ({ ...doc38.data(), id: doc38.id })
|
|
15794
15921
|
);
|
|
@@ -15807,19 +15934,19 @@ var ProcedureService = class extends BaseService {
|
|
|
15807
15934
|
"[PROCEDURE_SERVICE] Strategy 3: Using createdAt orderBy with client-side filtering"
|
|
15808
15935
|
);
|
|
15809
15936
|
const constraints = getBaseConstraints();
|
|
15810
|
-
constraints.push((0,
|
|
15937
|
+
constraints.push((0, import_firestore47.orderBy)("createdAt", "desc"));
|
|
15811
15938
|
if (filters.lastDoc) {
|
|
15812
15939
|
if (typeof filters.lastDoc.data === "function") {
|
|
15813
|
-
constraints.push((0,
|
|
15940
|
+
constraints.push((0, import_firestore47.startAfter)(filters.lastDoc));
|
|
15814
15941
|
} else if (Array.isArray(filters.lastDoc)) {
|
|
15815
|
-
constraints.push((0,
|
|
15942
|
+
constraints.push((0, import_firestore47.startAfter)(...filters.lastDoc));
|
|
15816
15943
|
} else {
|
|
15817
|
-
constraints.push((0,
|
|
15944
|
+
constraints.push((0, import_firestore47.startAfter)(filters.lastDoc));
|
|
15818
15945
|
}
|
|
15819
15946
|
}
|
|
15820
|
-
constraints.push((0,
|
|
15821
|
-
const q = (0,
|
|
15822
|
-
const querySnapshot = await (0,
|
|
15947
|
+
constraints.push((0, import_firestore47.limit)(filters.pagination || 10));
|
|
15948
|
+
const q = (0, import_firestore47.query)((0, import_firestore47.collection)(this.db, PROCEDURES_COLLECTION), ...constraints);
|
|
15949
|
+
const querySnapshot = await (0, import_firestore47.getDocs)(q);
|
|
15823
15950
|
let procedures = querySnapshot.docs.map(
|
|
15824
15951
|
(doc38) => ({ ...doc38.data(), id: doc38.id })
|
|
15825
15952
|
);
|
|
@@ -15836,12 +15963,12 @@ var ProcedureService = class extends BaseService {
|
|
|
15836
15963
|
try {
|
|
15837
15964
|
console.log("[PROCEDURE_SERVICE] Strategy 4: Minimal query fallback");
|
|
15838
15965
|
const constraints = [
|
|
15839
|
-
(0,
|
|
15840
|
-
(0,
|
|
15841
|
-
(0,
|
|
15966
|
+
(0, import_firestore47.where)("isActive", "==", true),
|
|
15967
|
+
(0, import_firestore47.orderBy)("createdAt", "desc"),
|
|
15968
|
+
(0, import_firestore47.limit)(filters.pagination || 10)
|
|
15842
15969
|
];
|
|
15843
|
-
const q = (0,
|
|
15844
|
-
const querySnapshot = await (0,
|
|
15970
|
+
const q = (0, import_firestore47.query)((0, import_firestore47.collection)(this.db, PROCEDURES_COLLECTION), ...constraints);
|
|
15971
|
+
const querySnapshot = await (0, import_firestore47.getDocs)(q);
|
|
15845
15972
|
let procedures = querySnapshot.docs.map(
|
|
15846
15973
|
(doc38) => ({ ...doc38.data(), id: doc38.id })
|
|
15847
15974
|
);
|
|
@@ -15985,11 +16112,11 @@ var ProcedureService = class extends BaseService {
|
|
|
15985
16112
|
const bounds = (0, import_geofire_common8.geohashQueryBounds)([location.latitude, location.longitude], radiusInKm * 1e3);
|
|
15986
16113
|
const fetches = bounds.map((b) => {
|
|
15987
16114
|
const constraints = [
|
|
15988
|
-
(0,
|
|
15989
|
-
(0,
|
|
15990
|
-
(0,
|
|
16115
|
+
(0, import_firestore47.where)("clinicInfo.location.geohash", ">=", b[0]),
|
|
16116
|
+
(0, import_firestore47.where)("clinicInfo.location.geohash", "<=", b[1]),
|
|
16117
|
+
(0, import_firestore47.where)("isActive", "==", filters.isActive !== void 0 ? filters.isActive : true)
|
|
15991
16118
|
];
|
|
15992
|
-
return (0,
|
|
16119
|
+
return (0, import_firestore47.getDocs)((0, import_firestore47.query)((0, import_firestore47.collection)(this.db, PROCEDURES_COLLECTION), ...constraints));
|
|
15993
16120
|
});
|
|
15994
16121
|
return Promise.all(fetches).then((snaps) => {
|
|
15995
16122
|
const collected = [];
|
|
@@ -16040,14 +16167,14 @@ var ProcedureService = class extends BaseService {
|
|
|
16040
16167
|
if (!category || !subcategory || !technology) {
|
|
16041
16168
|
throw new Error("One or more required base entities not found");
|
|
16042
16169
|
}
|
|
16043
|
-
const clinicRef = (0,
|
|
16044
|
-
const clinicSnapshot = await (0,
|
|
16170
|
+
const clinicRef = (0, import_firestore47.doc)(this.db, CLINICS_COLLECTION, data.clinicBranchId);
|
|
16171
|
+
const clinicSnapshot = await (0, import_firestore47.getDoc)(clinicRef);
|
|
16045
16172
|
if (!clinicSnapshot.exists()) {
|
|
16046
16173
|
throw new Error(`Clinic with ID ${data.clinicBranchId} not found`);
|
|
16047
16174
|
}
|
|
16048
16175
|
const clinic = clinicSnapshot.data();
|
|
16049
|
-
const practitionerRef = (0,
|
|
16050
|
-
const practitionerSnapshot = await (0,
|
|
16176
|
+
const practitionerRef = (0, import_firestore47.doc)(this.db, PRACTITIONERS_COLLECTION, data.practitionerId);
|
|
16177
|
+
const practitionerSnapshot = await (0, import_firestore47.getDoc)(practitionerRef);
|
|
16051
16178
|
if (!practitionerSnapshot.exists()) {
|
|
16052
16179
|
throw new Error(`Practitioner with ID ${data.practitionerId} not found`);
|
|
16053
16180
|
}
|
|
@@ -16126,13 +16253,13 @@ var ProcedureService = class extends BaseService {
|
|
|
16126
16253
|
},
|
|
16127
16254
|
isActive: true
|
|
16128
16255
|
};
|
|
16129
|
-
const procedureRef = (0,
|
|
16130
|
-
await (0,
|
|
16256
|
+
const procedureRef = (0, import_firestore47.doc)(this.db, PROCEDURES_COLLECTION, procedureId);
|
|
16257
|
+
await (0, import_firestore47.setDoc)(procedureRef, {
|
|
16131
16258
|
...newProcedure,
|
|
16132
|
-
createdAt: (0,
|
|
16133
|
-
updatedAt: (0,
|
|
16259
|
+
createdAt: (0, import_firestore47.serverTimestamp)(),
|
|
16260
|
+
updatedAt: (0, import_firestore47.serverTimestamp)()
|
|
16134
16261
|
});
|
|
16135
|
-
const savedDoc = await (0,
|
|
16262
|
+
const savedDoc = await (0, import_firestore47.getDoc)(procedureRef);
|
|
16136
16263
|
return savedDoc.data();
|
|
16137
16264
|
}
|
|
16138
16265
|
/**
|
|
@@ -16141,8 +16268,8 @@ var ProcedureService = class extends BaseService {
|
|
|
16141
16268
|
* @returns Array of minimal procedure info for map
|
|
16142
16269
|
*/
|
|
16143
16270
|
async getProceduresForMap() {
|
|
16144
|
-
const proceduresRef = (0,
|
|
16145
|
-
const snapshot = await (0,
|
|
16271
|
+
const proceduresRef = (0, import_firestore47.collection)(this.db, PROCEDURES_COLLECTION);
|
|
16272
|
+
const snapshot = await (0, import_firestore47.getDocs)(proceduresRef);
|
|
16146
16273
|
const proceduresForMap = snapshot.docs.map((doc38) => {
|
|
16147
16274
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
16148
16275
|
const data = doc38.data();
|
|
@@ -16161,7 +16288,7 @@ var ProcedureService = class extends BaseService {
|
|
|
16161
16288
|
};
|
|
16162
16289
|
|
|
16163
16290
|
// src/services/reviews/reviews.service.ts
|
|
16164
|
-
var
|
|
16291
|
+
var import_firestore48 = require("firebase/firestore");
|
|
16165
16292
|
var import_zod26 = require("zod");
|
|
16166
16293
|
var ReviewService = class extends BaseService {
|
|
16167
16294
|
constructor(db, auth, app) {
|
|
@@ -16241,11 +16368,11 @@ var ReviewService = class extends BaseService {
|
|
|
16241
16368
|
updatedAt: now
|
|
16242
16369
|
};
|
|
16243
16370
|
reviewSchema.parse(review);
|
|
16244
|
-
const docRef = (0,
|
|
16245
|
-
await (0,
|
|
16371
|
+
const docRef = (0, import_firestore48.doc)(this.db, REVIEWS_COLLECTION, reviewId);
|
|
16372
|
+
await (0, import_firestore48.setDoc)(docRef, {
|
|
16246
16373
|
...review,
|
|
16247
|
-
createdAt: (0,
|
|
16248
|
-
updatedAt: (0,
|
|
16374
|
+
createdAt: (0, import_firestore48.serverTimestamp)(),
|
|
16375
|
+
updatedAt: (0, import_firestore48.serverTimestamp)()
|
|
16249
16376
|
});
|
|
16250
16377
|
return review;
|
|
16251
16378
|
} catch (error) {
|
|
@@ -16261,8 +16388,8 @@ var ReviewService = class extends BaseService {
|
|
|
16261
16388
|
* @returns The review if found, null otherwise
|
|
16262
16389
|
*/
|
|
16263
16390
|
async getReview(reviewId) {
|
|
16264
|
-
const docRef = (0,
|
|
16265
|
-
const docSnap = await (0,
|
|
16391
|
+
const docRef = (0, import_firestore48.doc)(this.db, REVIEWS_COLLECTION, reviewId);
|
|
16392
|
+
const docSnap = await (0, import_firestore48.getDoc)(docRef);
|
|
16266
16393
|
if (!docSnap.exists()) {
|
|
16267
16394
|
return null;
|
|
16268
16395
|
}
|
|
@@ -16274,11 +16401,11 @@ var ReviewService = class extends BaseService {
|
|
|
16274
16401
|
* @returns Array of reviews for the patient
|
|
16275
16402
|
*/
|
|
16276
16403
|
async getReviewsByPatient(patientId) {
|
|
16277
|
-
const q = (0,
|
|
16278
|
-
(0,
|
|
16279
|
-
(0,
|
|
16404
|
+
const q = (0, import_firestore48.query)(
|
|
16405
|
+
(0, import_firestore48.collection)(this.db, REVIEWS_COLLECTION),
|
|
16406
|
+
(0, import_firestore48.where)("patientId", "==", patientId)
|
|
16280
16407
|
);
|
|
16281
|
-
const snapshot = await (0,
|
|
16408
|
+
const snapshot = await (0, import_firestore48.getDocs)(q);
|
|
16282
16409
|
return snapshot.docs.map((doc38) => doc38.data());
|
|
16283
16410
|
}
|
|
16284
16411
|
/**
|
|
@@ -16287,11 +16414,11 @@ var ReviewService = class extends BaseService {
|
|
|
16287
16414
|
* @returns Array of reviews containing clinic reviews
|
|
16288
16415
|
*/
|
|
16289
16416
|
async getReviewsByClinic(clinicId) {
|
|
16290
|
-
const q = (0,
|
|
16291
|
-
(0,
|
|
16292
|
-
(0,
|
|
16417
|
+
const q = (0, import_firestore48.query)(
|
|
16418
|
+
(0, import_firestore48.collection)(this.db, REVIEWS_COLLECTION),
|
|
16419
|
+
(0, import_firestore48.where)("clinicReview.clinicId", "==", clinicId)
|
|
16293
16420
|
);
|
|
16294
|
-
const snapshot = await (0,
|
|
16421
|
+
const snapshot = await (0, import_firestore48.getDocs)(q);
|
|
16295
16422
|
return snapshot.docs.map((doc38) => doc38.data());
|
|
16296
16423
|
}
|
|
16297
16424
|
/**
|
|
@@ -16300,11 +16427,11 @@ var ReviewService = class extends BaseService {
|
|
|
16300
16427
|
* @returns Array of reviews containing practitioner reviews
|
|
16301
16428
|
*/
|
|
16302
16429
|
async getReviewsByPractitioner(practitionerId) {
|
|
16303
|
-
const q = (0,
|
|
16304
|
-
(0,
|
|
16305
|
-
(0,
|
|
16430
|
+
const q = (0, import_firestore48.query)(
|
|
16431
|
+
(0, import_firestore48.collection)(this.db, REVIEWS_COLLECTION),
|
|
16432
|
+
(0, import_firestore48.where)("practitionerReview.practitionerId", "==", practitionerId)
|
|
16306
16433
|
);
|
|
16307
|
-
const snapshot = await (0,
|
|
16434
|
+
const snapshot = await (0, import_firestore48.getDocs)(q);
|
|
16308
16435
|
return snapshot.docs.map((doc38) => doc38.data());
|
|
16309
16436
|
}
|
|
16310
16437
|
/**
|
|
@@ -16313,11 +16440,11 @@ var ReviewService = class extends BaseService {
|
|
|
16313
16440
|
* @returns Array of reviews containing procedure reviews
|
|
16314
16441
|
*/
|
|
16315
16442
|
async getReviewsByProcedure(procedureId) {
|
|
16316
|
-
const q = (0,
|
|
16317
|
-
(0,
|
|
16318
|
-
(0,
|
|
16443
|
+
const q = (0, import_firestore48.query)(
|
|
16444
|
+
(0, import_firestore48.collection)(this.db, REVIEWS_COLLECTION),
|
|
16445
|
+
(0, import_firestore48.where)("procedureReview.procedureId", "==", procedureId)
|
|
16319
16446
|
);
|
|
16320
|
-
const snapshot = await (0,
|
|
16447
|
+
const snapshot = await (0, import_firestore48.getDocs)(q);
|
|
16321
16448
|
return snapshot.docs.map((doc38) => doc38.data());
|
|
16322
16449
|
}
|
|
16323
16450
|
/**
|
|
@@ -16326,11 +16453,11 @@ var ReviewService = class extends BaseService {
|
|
|
16326
16453
|
* @returns The review for the appointment if found, null otherwise
|
|
16327
16454
|
*/
|
|
16328
16455
|
async getReviewByAppointment(appointmentId) {
|
|
16329
|
-
const q = (0,
|
|
16330
|
-
(0,
|
|
16331
|
-
(0,
|
|
16456
|
+
const q = (0, import_firestore48.query)(
|
|
16457
|
+
(0, import_firestore48.collection)(this.db, REVIEWS_COLLECTION),
|
|
16458
|
+
(0, import_firestore48.where)("appointmentId", "==", appointmentId)
|
|
16332
16459
|
);
|
|
16333
|
-
const snapshot = await (0,
|
|
16460
|
+
const snapshot = await (0, import_firestore48.getDocs)(q);
|
|
16334
16461
|
if (snapshot.empty) {
|
|
16335
16462
|
return null;
|
|
16336
16463
|
}
|
|
@@ -16345,7 +16472,7 @@ var ReviewService = class extends BaseService {
|
|
|
16345
16472
|
if (!review) {
|
|
16346
16473
|
throw new Error(`Review with ID ${reviewId} not found`);
|
|
16347
16474
|
}
|
|
16348
|
-
await (0,
|
|
16475
|
+
await (0, import_firestore48.deleteDoc)((0, import_firestore48.doc)(this.db, REVIEWS_COLLECTION, reviewId));
|
|
16349
16476
|
}
|
|
16350
16477
|
/**
|
|
16351
16478
|
* Calculates the average of an array of numbers
|
|
@@ -16364,7 +16491,7 @@ var ReviewService = class extends BaseService {
|
|
|
16364
16491
|
|
|
16365
16492
|
// src/config/firebase.ts
|
|
16366
16493
|
var import_app = require("firebase/app");
|
|
16367
|
-
var
|
|
16494
|
+
var import_firestore49 = require("firebase/firestore");
|
|
16368
16495
|
var import_auth9 = require("firebase/auth");
|
|
16369
16496
|
var import_analytics = require("firebase/analytics");
|
|
16370
16497
|
var import_react_native = require("react-native");
|
|
@@ -16374,7 +16501,7 @@ var firebaseInstance = null;
|
|
|
16374
16501
|
var initializeFirebase = (config) => {
|
|
16375
16502
|
if (!firebaseInstance) {
|
|
16376
16503
|
const app = (0, import_app.initializeApp)(config);
|
|
16377
|
-
const db = (0,
|
|
16504
|
+
const db = (0, import_firestore49.getFirestore)(app);
|
|
16378
16505
|
const auth = (0, import_auth9.getAuth)(app);
|
|
16379
16506
|
const storage = (0, import_storage4.getStorage)(app);
|
|
16380
16507
|
const functions = (0, import_functions3.getFunctions)(app);
|
|
@@ -16416,7 +16543,7 @@ var getFirebaseFunctions = async () => {
|
|
|
16416
16543
|
};
|
|
16417
16544
|
|
|
16418
16545
|
// src/backoffice/services/brand.service.ts
|
|
16419
|
-
var
|
|
16546
|
+
var import_firestore50 = require("firebase/firestore");
|
|
16420
16547
|
|
|
16421
16548
|
// src/backoffice/types/brand.types.ts
|
|
16422
16549
|
var BRANDS_COLLECTION = "brands";
|
|
@@ -16427,7 +16554,7 @@ var BrandService = class extends BaseService {
|
|
|
16427
16554
|
* Gets reference to brands collection
|
|
16428
16555
|
*/
|
|
16429
16556
|
getBrandsRef() {
|
|
16430
|
-
return (0,
|
|
16557
|
+
return (0, import_firestore50.collection)(this.db, BRANDS_COLLECTION);
|
|
16431
16558
|
}
|
|
16432
16559
|
/**
|
|
16433
16560
|
* Creates a new brand
|
|
@@ -16441,7 +16568,7 @@ var BrandService = class extends BaseService {
|
|
|
16441
16568
|
updatedAt: now,
|
|
16442
16569
|
isActive: true
|
|
16443
16570
|
};
|
|
16444
|
-
const docRef = await (0,
|
|
16571
|
+
const docRef = await (0, import_firestore50.addDoc)(this.getBrandsRef(), newBrand);
|
|
16445
16572
|
return { id: docRef.id, ...newBrand };
|
|
16446
16573
|
}
|
|
16447
16574
|
/**
|
|
@@ -16452,22 +16579,22 @@ var BrandService = class extends BaseService {
|
|
|
16452
16579
|
*/
|
|
16453
16580
|
async getAll(rowsPerPage, searchTerm, lastVisible) {
|
|
16454
16581
|
const constraints = [
|
|
16455
|
-
(0,
|
|
16456
|
-
(0,
|
|
16582
|
+
(0, import_firestore50.where)("isActive", "==", true),
|
|
16583
|
+
(0, import_firestore50.orderBy)("name_lowercase")
|
|
16457
16584
|
];
|
|
16458
16585
|
if (searchTerm) {
|
|
16459
16586
|
const lowercasedSearchTerm = searchTerm.toLowerCase();
|
|
16460
|
-
constraints.push((0,
|
|
16587
|
+
constraints.push((0, import_firestore50.where)("name_lowercase", ">=", lowercasedSearchTerm));
|
|
16461
16588
|
constraints.push(
|
|
16462
|
-
(0,
|
|
16589
|
+
(0, import_firestore50.where)("name_lowercase", "<=", lowercasedSearchTerm + "\uF8FF")
|
|
16463
16590
|
);
|
|
16464
16591
|
}
|
|
16465
16592
|
if (lastVisible) {
|
|
16466
|
-
constraints.push((0,
|
|
16593
|
+
constraints.push((0, import_firestore50.startAfter)(lastVisible));
|
|
16467
16594
|
}
|
|
16468
|
-
constraints.push((0,
|
|
16469
|
-
const q = (0,
|
|
16470
|
-
const snapshot = await (0,
|
|
16595
|
+
constraints.push((0, import_firestore50.limit)(rowsPerPage));
|
|
16596
|
+
const q = (0, import_firestore50.query)(this.getBrandsRef(), ...constraints);
|
|
16597
|
+
const snapshot = await (0, import_firestore50.getDocs)(q);
|
|
16471
16598
|
const brands = snapshot.docs.map(
|
|
16472
16599
|
(doc38) => ({
|
|
16473
16600
|
id: doc38.id,
|
|
@@ -16482,28 +16609,28 @@ var BrandService = class extends BaseService {
|
|
|
16482
16609
|
* @param searchTerm - An optional string to filter brand names by (starts-with search).
|
|
16483
16610
|
*/
|
|
16484
16611
|
async getBrandsCount(searchTerm) {
|
|
16485
|
-
const constraints = [(0,
|
|
16612
|
+
const constraints = [(0, import_firestore50.where)("isActive", "==", true)];
|
|
16486
16613
|
if (searchTerm) {
|
|
16487
16614
|
const lowercasedSearchTerm = searchTerm.toLowerCase();
|
|
16488
|
-
constraints.push((0,
|
|
16615
|
+
constraints.push((0, import_firestore50.where)("name_lowercase", ">=", lowercasedSearchTerm));
|
|
16489
16616
|
constraints.push(
|
|
16490
|
-
(0,
|
|
16617
|
+
(0, import_firestore50.where)("name_lowercase", "<=", lowercasedSearchTerm + "\uF8FF")
|
|
16491
16618
|
);
|
|
16492
16619
|
}
|
|
16493
|
-
const q = (0,
|
|
16494
|
-
const snapshot = await (0,
|
|
16620
|
+
const q = (0, import_firestore50.query)(this.getBrandsRef(), ...constraints);
|
|
16621
|
+
const snapshot = await (0, import_firestore50.getCountFromServer)(q);
|
|
16495
16622
|
return snapshot.data().count;
|
|
16496
16623
|
}
|
|
16497
16624
|
/**
|
|
16498
16625
|
* Gets all active brands for filter dropdowns (not paginated).
|
|
16499
16626
|
*/
|
|
16500
16627
|
async getAllForFilter() {
|
|
16501
|
-
const q = (0,
|
|
16628
|
+
const q = (0, import_firestore50.query)(
|
|
16502
16629
|
this.getBrandsRef(),
|
|
16503
|
-
(0,
|
|
16504
|
-
(0,
|
|
16630
|
+
(0, import_firestore50.where)("isActive", "==", true),
|
|
16631
|
+
(0, import_firestore50.orderBy)("name")
|
|
16505
16632
|
);
|
|
16506
|
-
const snapshot = await (0,
|
|
16633
|
+
const snapshot = await (0, import_firestore50.getDocs)(q);
|
|
16507
16634
|
return snapshot.docs.map(
|
|
16508
16635
|
(doc38) => ({
|
|
16509
16636
|
id: doc38.id,
|
|
@@ -16522,8 +16649,8 @@ var BrandService = class extends BaseService {
|
|
|
16522
16649
|
if (brand.name) {
|
|
16523
16650
|
updateData.name_lowercase = brand.name.toLowerCase();
|
|
16524
16651
|
}
|
|
16525
|
-
const docRef = (0,
|
|
16526
|
-
await (0,
|
|
16652
|
+
const docRef = (0, import_firestore50.doc)(this.getBrandsRef(), brandId);
|
|
16653
|
+
await (0, import_firestore50.updateDoc)(docRef, updateData);
|
|
16527
16654
|
return this.getById(brandId);
|
|
16528
16655
|
}
|
|
16529
16656
|
/**
|
|
@@ -16538,8 +16665,8 @@ var BrandService = class extends BaseService {
|
|
|
16538
16665
|
* Gets a brand by ID
|
|
16539
16666
|
*/
|
|
16540
16667
|
async getById(brandId) {
|
|
16541
|
-
const docRef = (0,
|
|
16542
|
-
const docSnap = await (0,
|
|
16668
|
+
const docRef = (0, import_firestore50.doc)(this.getBrandsRef(), brandId);
|
|
16669
|
+
const docSnap = await (0, import_firestore50.getDoc)(docRef);
|
|
16543
16670
|
if (!docSnap.exists()) return null;
|
|
16544
16671
|
return {
|
|
16545
16672
|
id: docSnap.id,
|
|
@@ -16549,7 +16676,7 @@ var BrandService = class extends BaseService {
|
|
|
16549
16676
|
};
|
|
16550
16677
|
|
|
16551
16678
|
// src/backoffice/services/category.service.ts
|
|
16552
|
-
var
|
|
16679
|
+
var import_firestore51 = require("firebase/firestore");
|
|
16553
16680
|
|
|
16554
16681
|
// src/backoffice/types/category.types.ts
|
|
16555
16682
|
var CATEGORIES_COLLECTION = "backoffice_categories";
|
|
@@ -16560,7 +16687,7 @@ var CategoryService = class extends BaseService {
|
|
|
16560
16687
|
* Referenca na Firestore kolekciju kategorija
|
|
16561
16688
|
*/
|
|
16562
16689
|
get categoriesRef() {
|
|
16563
|
-
return (0,
|
|
16690
|
+
return (0, import_firestore51.collection)(this.db, CATEGORIES_COLLECTION);
|
|
16564
16691
|
}
|
|
16565
16692
|
/**
|
|
16566
16693
|
* Kreira novu kategoriju u sistemu
|
|
@@ -16575,7 +16702,7 @@ var CategoryService = class extends BaseService {
|
|
|
16575
16702
|
updatedAt: now,
|
|
16576
16703
|
isActive: true
|
|
16577
16704
|
};
|
|
16578
|
-
const docRef = await (0,
|
|
16705
|
+
const docRef = await (0, import_firestore51.addDoc)(this.categoriesRef, newCategory);
|
|
16579
16706
|
return { id: docRef.id, ...newCategory };
|
|
16580
16707
|
}
|
|
16581
16708
|
/**
|
|
@@ -16587,12 +16714,12 @@ var CategoryService = class extends BaseService {
|
|
|
16587
16714
|
const counts = {};
|
|
16588
16715
|
const families = Object.values(ProcedureFamily);
|
|
16589
16716
|
for (const family of families) {
|
|
16590
|
-
const q = (0,
|
|
16717
|
+
const q = (0, import_firestore51.query)(
|
|
16591
16718
|
this.categoriesRef,
|
|
16592
|
-
(0,
|
|
16593
|
-
(0,
|
|
16719
|
+
(0, import_firestore51.where)("family", "==", family),
|
|
16720
|
+
(0, import_firestore51.where)("isActive", "==", active)
|
|
16594
16721
|
);
|
|
16595
|
-
const snapshot = await (0,
|
|
16722
|
+
const snapshot = await (0, import_firestore51.getCountFromServer)(q);
|
|
16596
16723
|
counts[family] = snapshot.data().count;
|
|
16597
16724
|
}
|
|
16598
16725
|
return counts;
|
|
@@ -16602,8 +16729,8 @@ var CategoryService = class extends BaseService {
|
|
|
16602
16729
|
* @returns Lista svih aktivnih kategorija
|
|
16603
16730
|
*/
|
|
16604
16731
|
async getAllForFilter() {
|
|
16605
|
-
const q = (0,
|
|
16606
|
-
const snapshot = await (0,
|
|
16732
|
+
const q = (0, import_firestore51.query)(this.categoriesRef, (0, import_firestore51.where)("isActive", "==", true));
|
|
16733
|
+
const snapshot = await (0, import_firestore51.getDocs)(q);
|
|
16607
16734
|
return snapshot.docs.map(
|
|
16608
16735
|
(doc38) => ({
|
|
16609
16736
|
id: doc38.id,
|
|
@@ -16617,13 +16744,13 @@ var CategoryService = class extends BaseService {
|
|
|
16617
16744
|
* @returns Lista aktivnih kategorija koje pripadaju traženoj familiji
|
|
16618
16745
|
*/
|
|
16619
16746
|
async getAllForFilterByFamily(family) {
|
|
16620
|
-
const q = (0,
|
|
16747
|
+
const q = (0, import_firestore51.query)(
|
|
16621
16748
|
this.categoriesRef,
|
|
16622
|
-
(0,
|
|
16623
|
-
(0,
|
|
16624
|
-
(0,
|
|
16749
|
+
(0, import_firestore51.where)("family", "==", family),
|
|
16750
|
+
(0, import_firestore51.where)("isActive", "==", true),
|
|
16751
|
+
(0, import_firestore51.orderBy)("name")
|
|
16625
16752
|
);
|
|
16626
|
-
const snapshot = await (0,
|
|
16753
|
+
const snapshot = await (0, import_firestore51.getDocs)(q);
|
|
16627
16754
|
return snapshot.docs.map(
|
|
16628
16755
|
(doc38) => ({
|
|
16629
16756
|
id: doc38.id,
|
|
@@ -16639,13 +16766,13 @@ var CategoryService = class extends BaseService {
|
|
|
16639
16766
|
async getAll(options = {}) {
|
|
16640
16767
|
const { active = true, limit: queryLimit = 10, lastVisible } = options;
|
|
16641
16768
|
const constraints = [
|
|
16642
|
-
(0,
|
|
16643
|
-
(0,
|
|
16644
|
-
queryLimit ? (0,
|
|
16645
|
-
lastVisible ? (0,
|
|
16769
|
+
(0, import_firestore51.where)("isActive", "==", active),
|
|
16770
|
+
(0, import_firestore51.orderBy)("name"),
|
|
16771
|
+
queryLimit ? (0, import_firestore51.limit)(queryLimit) : void 0,
|
|
16772
|
+
lastVisible ? (0, import_firestore51.startAfter)(lastVisible) : void 0
|
|
16646
16773
|
].filter((c) => !!c);
|
|
16647
|
-
const q = (0,
|
|
16648
|
-
const snapshot = await (0,
|
|
16774
|
+
const q = (0, import_firestore51.query)(this.categoriesRef, ...constraints);
|
|
16775
|
+
const snapshot = await (0, import_firestore51.getDocs)(q);
|
|
16649
16776
|
const categories = snapshot.docs.map(
|
|
16650
16777
|
(doc38) => ({
|
|
16651
16778
|
id: doc38.id,
|
|
@@ -16664,14 +16791,14 @@ var CategoryService = class extends BaseService {
|
|
|
16664
16791
|
async getAllByFamily(family, options = {}) {
|
|
16665
16792
|
const { active = true, limit: queryLimit = 10, lastVisible } = options;
|
|
16666
16793
|
const constraints = [
|
|
16667
|
-
(0,
|
|
16668
|
-
(0,
|
|
16669
|
-
(0,
|
|
16670
|
-
queryLimit ? (0,
|
|
16671
|
-
lastVisible ? (0,
|
|
16794
|
+
(0, import_firestore51.where)("family", "==", family),
|
|
16795
|
+
(0, import_firestore51.where)("isActive", "==", active),
|
|
16796
|
+
(0, import_firestore51.orderBy)("name"),
|
|
16797
|
+
queryLimit ? (0, import_firestore51.limit)(queryLimit) : void 0,
|
|
16798
|
+
lastVisible ? (0, import_firestore51.startAfter)(lastVisible) : void 0
|
|
16672
16799
|
].filter((c) => !!c);
|
|
16673
|
-
const q = (0,
|
|
16674
|
-
const snapshot = await (0,
|
|
16800
|
+
const q = (0, import_firestore51.query)(this.categoriesRef, ...constraints);
|
|
16801
|
+
const snapshot = await (0, import_firestore51.getDocs)(q);
|
|
16675
16802
|
const categories = snapshot.docs.map(
|
|
16676
16803
|
(doc38) => ({
|
|
16677
16804
|
id: doc38.id,
|
|
@@ -16692,8 +16819,8 @@ var CategoryService = class extends BaseService {
|
|
|
16692
16819
|
...category,
|
|
16693
16820
|
updatedAt: /* @__PURE__ */ new Date()
|
|
16694
16821
|
};
|
|
16695
|
-
const docRef = (0,
|
|
16696
|
-
await (0,
|
|
16822
|
+
const docRef = (0, import_firestore51.doc)(this.categoriesRef, id);
|
|
16823
|
+
await (0, import_firestore51.updateDoc)(docRef, updateData);
|
|
16697
16824
|
return this.getById(id);
|
|
16698
16825
|
}
|
|
16699
16826
|
/**
|
|
@@ -16716,8 +16843,8 @@ var CategoryService = class extends BaseService {
|
|
|
16716
16843
|
* @returns Kategorija ili null ako ne postoji
|
|
16717
16844
|
*/
|
|
16718
16845
|
async getById(id) {
|
|
16719
|
-
const docRef = (0,
|
|
16720
|
-
const docSnap = await (0,
|
|
16846
|
+
const docRef = (0, import_firestore51.doc)(this.categoriesRef, id);
|
|
16847
|
+
const docSnap = await (0, import_firestore51.getDoc)(docRef);
|
|
16721
16848
|
if (!docSnap.exists()) return null;
|
|
16722
16849
|
return {
|
|
16723
16850
|
id: docSnap.id,
|
|
@@ -16727,7 +16854,7 @@ var CategoryService = class extends BaseService {
|
|
|
16727
16854
|
};
|
|
16728
16855
|
|
|
16729
16856
|
// src/backoffice/services/subcategory.service.ts
|
|
16730
|
-
var
|
|
16857
|
+
var import_firestore52 = require("firebase/firestore");
|
|
16731
16858
|
|
|
16732
16859
|
// src/backoffice/types/subcategory.types.ts
|
|
16733
16860
|
var SUBCATEGORIES_COLLECTION = "subcategories";
|
|
@@ -16739,7 +16866,7 @@ var SubcategoryService = class extends BaseService {
|
|
|
16739
16866
|
* @param categoryId - ID roditeljske kategorije
|
|
16740
16867
|
*/
|
|
16741
16868
|
getSubcategoriesRef(categoryId) {
|
|
16742
|
-
return (0,
|
|
16869
|
+
return (0, import_firestore52.collection)(
|
|
16743
16870
|
this.db,
|
|
16744
16871
|
CATEGORIES_COLLECTION,
|
|
16745
16872
|
categoryId,
|
|
@@ -16761,7 +16888,7 @@ var SubcategoryService = class extends BaseService {
|
|
|
16761
16888
|
updatedAt: now,
|
|
16762
16889
|
isActive: true
|
|
16763
16890
|
};
|
|
16764
|
-
const docRef = await (0,
|
|
16891
|
+
const docRef = await (0, import_firestore52.addDoc)(
|
|
16765
16892
|
this.getSubcategoriesRef(categoryId),
|
|
16766
16893
|
newSubcategory
|
|
16767
16894
|
);
|
|
@@ -16773,14 +16900,14 @@ var SubcategoryService = class extends BaseService {
|
|
|
16773
16900
|
* @returns A record mapping category ID to subcategory count.
|
|
16774
16901
|
*/
|
|
16775
16902
|
async getSubcategoryCounts(active = true) {
|
|
16776
|
-
const categoriesRef = (0,
|
|
16777
|
-
const categoriesSnapshot = await (0,
|
|
16903
|
+
const categoriesRef = (0, import_firestore52.collection)(this.db, CATEGORIES_COLLECTION);
|
|
16904
|
+
const categoriesSnapshot = await (0, import_firestore52.getDocs)(categoriesRef);
|
|
16778
16905
|
const counts = {};
|
|
16779
16906
|
for (const categoryDoc of categoriesSnapshot.docs) {
|
|
16780
16907
|
const categoryId = categoryDoc.id;
|
|
16781
16908
|
const subcategoriesRef = this.getSubcategoriesRef(categoryId);
|
|
16782
|
-
const q = (0,
|
|
16783
|
-
const snapshot = await (0,
|
|
16909
|
+
const q = (0, import_firestore52.query)(subcategoriesRef, (0, import_firestore52.where)("isActive", "==", active));
|
|
16910
|
+
const snapshot = await (0, import_firestore52.getCountFromServer)(q);
|
|
16784
16911
|
counts[categoryId] = snapshot.data().count;
|
|
16785
16912
|
}
|
|
16786
16913
|
return counts;
|
|
@@ -16794,13 +16921,13 @@ var SubcategoryService = class extends BaseService {
|
|
|
16794
16921
|
async getAllByCategoryId(categoryId, options = {}) {
|
|
16795
16922
|
const { active = true, limit: queryLimit = 10, lastVisible } = options;
|
|
16796
16923
|
const constraints = [
|
|
16797
|
-
(0,
|
|
16798
|
-
(0,
|
|
16799
|
-
queryLimit ? (0,
|
|
16800
|
-
lastVisible ? (0,
|
|
16924
|
+
(0, import_firestore52.where)("isActive", "==", active),
|
|
16925
|
+
(0, import_firestore52.orderBy)("name"),
|
|
16926
|
+
queryLimit ? (0, import_firestore52.limit)(queryLimit) : void 0,
|
|
16927
|
+
lastVisible ? (0, import_firestore52.startAfter)(lastVisible) : void 0
|
|
16801
16928
|
].filter((c) => !!c);
|
|
16802
|
-
const q = (0,
|
|
16803
|
-
const querySnapshot = await (0,
|
|
16929
|
+
const q = (0, import_firestore52.query)(this.getSubcategoriesRef(categoryId), ...constraints);
|
|
16930
|
+
const querySnapshot = await (0, import_firestore52.getDocs)(q);
|
|
16804
16931
|
const subcategories = querySnapshot.docs.map(
|
|
16805
16932
|
(doc38) => ({
|
|
16806
16933
|
id: doc38.id,
|
|
@@ -16821,16 +16948,16 @@ var SubcategoryService = class extends BaseService {
|
|
|
16821
16948
|
async getAll(options = {}) {
|
|
16822
16949
|
const { active = true, limit: queryLimit = 10, lastVisible } = options;
|
|
16823
16950
|
const constraints = [
|
|
16824
|
-
(0,
|
|
16825
|
-
(0,
|
|
16826
|
-
queryLimit ? (0,
|
|
16827
|
-
lastVisible ? (0,
|
|
16951
|
+
(0, import_firestore52.where)("isActive", "==", active),
|
|
16952
|
+
(0, import_firestore52.orderBy)("name"),
|
|
16953
|
+
queryLimit ? (0, import_firestore52.limit)(queryLimit) : void 0,
|
|
16954
|
+
lastVisible ? (0, import_firestore52.startAfter)(lastVisible) : void 0
|
|
16828
16955
|
].filter((c) => !!c);
|
|
16829
|
-
const q = (0,
|
|
16830
|
-
(0,
|
|
16956
|
+
const q = (0, import_firestore52.query)(
|
|
16957
|
+
(0, import_firestore52.collectionGroup)(this.db, SUBCATEGORIES_COLLECTION),
|
|
16831
16958
|
...constraints
|
|
16832
16959
|
);
|
|
16833
|
-
const querySnapshot = await (0,
|
|
16960
|
+
const querySnapshot = await (0, import_firestore52.getDocs)(q);
|
|
16834
16961
|
const subcategories = querySnapshot.docs.map(
|
|
16835
16962
|
(doc38) => ({
|
|
16836
16963
|
id: doc38.id,
|
|
@@ -16846,11 +16973,11 @@ var SubcategoryService = class extends BaseService {
|
|
|
16846
16973
|
* @returns Lista svih aktivnih subkategorija
|
|
16847
16974
|
*/
|
|
16848
16975
|
async getAllForFilterByCategoryId(categoryId) {
|
|
16849
|
-
const q = (0,
|
|
16976
|
+
const q = (0, import_firestore52.query)(
|
|
16850
16977
|
this.getSubcategoriesRef(categoryId),
|
|
16851
|
-
(0,
|
|
16978
|
+
(0, import_firestore52.where)("isActive", "==", true)
|
|
16852
16979
|
);
|
|
16853
|
-
const querySnapshot = await (0,
|
|
16980
|
+
const querySnapshot = await (0, import_firestore52.getDocs)(q);
|
|
16854
16981
|
return querySnapshot.docs.map(
|
|
16855
16982
|
(doc38) => ({
|
|
16856
16983
|
id: doc38.id,
|
|
@@ -16863,11 +16990,11 @@ var SubcategoryService = class extends BaseService {
|
|
|
16863
16990
|
* @returns Lista svih aktivnih subkategorija
|
|
16864
16991
|
*/
|
|
16865
16992
|
async getAllForFilter() {
|
|
16866
|
-
const q = (0,
|
|
16867
|
-
(0,
|
|
16868
|
-
(0,
|
|
16993
|
+
const q = (0, import_firestore52.query)(
|
|
16994
|
+
(0, import_firestore52.collectionGroup)(this.db, SUBCATEGORIES_COLLECTION),
|
|
16995
|
+
(0, import_firestore52.where)("isActive", "==", true)
|
|
16869
16996
|
);
|
|
16870
|
-
const querySnapshot = await (0,
|
|
16997
|
+
const querySnapshot = await (0, import_firestore52.getDocs)(q);
|
|
16871
16998
|
return querySnapshot.docs.map(
|
|
16872
16999
|
(doc38) => ({
|
|
16873
17000
|
id: doc38.id,
|
|
@@ -16885,11 +17012,11 @@ var SubcategoryService = class extends BaseService {
|
|
|
16885
17012
|
async update(categoryId, subcategoryId, subcategory) {
|
|
16886
17013
|
const newCategoryId = subcategory.categoryId;
|
|
16887
17014
|
if (newCategoryId && newCategoryId !== categoryId) {
|
|
16888
|
-
const oldDocRef = (0,
|
|
17015
|
+
const oldDocRef = (0, import_firestore52.doc)(
|
|
16889
17016
|
this.getSubcategoriesRef(categoryId),
|
|
16890
17017
|
subcategoryId
|
|
16891
17018
|
);
|
|
16892
|
-
const docSnap = await (0,
|
|
17019
|
+
const docSnap = await (0, import_firestore52.getDoc)(oldDocRef);
|
|
16893
17020
|
if (!docSnap.exists()) {
|
|
16894
17021
|
throw new Error("Subcategory to update does not exist.");
|
|
16895
17022
|
}
|
|
@@ -16903,20 +17030,20 @@ var SubcategoryService = class extends BaseService {
|
|
|
16903
17030
|
// Preserve original creation date
|
|
16904
17031
|
updatedAt: /* @__PURE__ */ new Date()
|
|
16905
17032
|
};
|
|
16906
|
-
const newDocRef = (0,
|
|
17033
|
+
const newDocRef = (0, import_firestore52.doc)(
|
|
16907
17034
|
this.getSubcategoriesRef(newCategoryId),
|
|
16908
17035
|
subcategoryId
|
|
16909
17036
|
);
|
|
16910
|
-
await (0,
|
|
16911
|
-
await (0,
|
|
17037
|
+
await (0, import_firestore52.setDoc)(newDocRef, newData);
|
|
17038
|
+
await (0, import_firestore52.deleteDoc)(oldDocRef);
|
|
16912
17039
|
return { id: subcategoryId, ...newData };
|
|
16913
17040
|
} else {
|
|
16914
17041
|
const updateData = {
|
|
16915
17042
|
...subcategory,
|
|
16916
17043
|
updatedAt: /* @__PURE__ */ new Date()
|
|
16917
17044
|
};
|
|
16918
|
-
const docRef = (0,
|
|
16919
|
-
await (0,
|
|
17045
|
+
const docRef = (0, import_firestore52.doc)(this.getSubcategoriesRef(categoryId), subcategoryId);
|
|
17046
|
+
await (0, import_firestore52.updateDoc)(docRef, updateData);
|
|
16920
17047
|
return this.getById(categoryId, subcategoryId);
|
|
16921
17048
|
}
|
|
16922
17049
|
}
|
|
@@ -16943,8 +17070,8 @@ var SubcategoryService = class extends BaseService {
|
|
|
16943
17070
|
* @returns Podkategorija ili null ako ne postoji
|
|
16944
17071
|
*/
|
|
16945
17072
|
async getById(categoryId, subcategoryId) {
|
|
16946
|
-
const docRef = (0,
|
|
16947
|
-
const docSnap = await (0,
|
|
17073
|
+
const docRef = (0, import_firestore52.doc)(this.getSubcategoriesRef(categoryId), subcategoryId);
|
|
17074
|
+
const docSnap = await (0, import_firestore52.getDoc)(docRef);
|
|
16948
17075
|
if (!docSnap.exists()) return null;
|
|
16949
17076
|
return {
|
|
16950
17077
|
id: docSnap.id,
|
|
@@ -16954,7 +17081,7 @@ var SubcategoryService = class extends BaseService {
|
|
|
16954
17081
|
};
|
|
16955
17082
|
|
|
16956
17083
|
// src/backoffice/services/technology.service.ts
|
|
16957
|
-
var
|
|
17084
|
+
var import_firestore53 = require("firebase/firestore");
|
|
16958
17085
|
var DEFAULT_CERTIFICATION_REQUIREMENT = {
|
|
16959
17086
|
minimumLevel: "aesthetician" /* AESTHETICIAN */,
|
|
16960
17087
|
requiredSpecialties: []
|
|
@@ -16964,7 +17091,7 @@ var TechnologyService = class extends BaseService {
|
|
|
16964
17091
|
* Reference to the Firestore collection of technologies.
|
|
16965
17092
|
*/
|
|
16966
17093
|
get technologiesRef() {
|
|
16967
|
-
return (0,
|
|
17094
|
+
return (0, import_firestore53.collection)(this.db, TECHNOLOGIES_COLLECTION);
|
|
16968
17095
|
}
|
|
16969
17096
|
/**
|
|
16970
17097
|
* Creates a new technology.
|
|
@@ -16992,7 +17119,7 @@ var TechnologyService = class extends BaseService {
|
|
|
16992
17119
|
if (technology.technicalDetails) {
|
|
16993
17120
|
newTechnology.technicalDetails = technology.technicalDetails;
|
|
16994
17121
|
}
|
|
16995
|
-
const docRef = await (0,
|
|
17122
|
+
const docRef = await (0, import_firestore53.addDoc)(this.technologiesRef, newTechnology);
|
|
16996
17123
|
return { id: docRef.id, ...newTechnology };
|
|
16997
17124
|
}
|
|
16998
17125
|
/**
|
|
@@ -17001,8 +17128,8 @@ var TechnologyService = class extends BaseService {
|
|
|
17001
17128
|
* @returns A record mapping subcategory ID to technology count.
|
|
17002
17129
|
*/
|
|
17003
17130
|
async getTechnologyCounts(active = true) {
|
|
17004
|
-
const q = (0,
|
|
17005
|
-
const snapshot = await (0,
|
|
17131
|
+
const q = (0, import_firestore53.query)(this.technologiesRef, (0, import_firestore53.where)("isActive", "==", active));
|
|
17132
|
+
const snapshot = await (0, import_firestore53.getDocs)(q);
|
|
17006
17133
|
const counts = {};
|
|
17007
17134
|
snapshot.docs.forEach((doc38) => {
|
|
17008
17135
|
const tech = doc38.data();
|
|
@@ -17016,8 +17143,8 @@ var TechnologyService = class extends BaseService {
|
|
|
17016
17143
|
* @returns A record mapping category ID to technology count.
|
|
17017
17144
|
*/
|
|
17018
17145
|
async getTechnologyCountsByCategory(active = true) {
|
|
17019
|
-
const q = (0,
|
|
17020
|
-
const snapshot = await (0,
|
|
17146
|
+
const q = (0, import_firestore53.query)(this.technologiesRef, (0, import_firestore53.where)("isActive", "==", active));
|
|
17147
|
+
const snapshot = await (0, import_firestore53.getDocs)(q);
|
|
17021
17148
|
const counts = {};
|
|
17022
17149
|
snapshot.docs.forEach((doc38) => {
|
|
17023
17150
|
const tech = doc38.data();
|
|
@@ -17033,13 +17160,13 @@ var TechnologyService = class extends BaseService {
|
|
|
17033
17160
|
async getAll(options = {}) {
|
|
17034
17161
|
const { active = true, limit: queryLimit = 10, lastVisible } = options;
|
|
17035
17162
|
const constraints = [
|
|
17036
|
-
(0,
|
|
17037
|
-
(0,
|
|
17038
|
-
queryLimit ? (0,
|
|
17039
|
-
lastVisible ? (0,
|
|
17163
|
+
(0, import_firestore53.where)("isActive", "==", active),
|
|
17164
|
+
(0, import_firestore53.orderBy)("name"),
|
|
17165
|
+
queryLimit ? (0, import_firestore53.limit)(queryLimit) : void 0,
|
|
17166
|
+
lastVisible ? (0, import_firestore53.startAfter)(lastVisible) : void 0
|
|
17040
17167
|
].filter((c) => !!c);
|
|
17041
|
-
const q = (0,
|
|
17042
|
-
const snapshot = await (0,
|
|
17168
|
+
const q = (0, import_firestore53.query)(this.technologiesRef, ...constraints);
|
|
17169
|
+
const snapshot = await (0, import_firestore53.getDocs)(q);
|
|
17043
17170
|
const technologies = snapshot.docs.map(
|
|
17044
17171
|
(doc38) => ({
|
|
17045
17172
|
id: doc38.id,
|
|
@@ -17058,14 +17185,14 @@ var TechnologyService = class extends BaseService {
|
|
|
17058
17185
|
async getAllByCategoryId(categoryId, options = {}) {
|
|
17059
17186
|
const { active = true, limit: queryLimit = 10, lastVisible } = options;
|
|
17060
17187
|
const constraints = [
|
|
17061
|
-
(0,
|
|
17062
|
-
(0,
|
|
17063
|
-
(0,
|
|
17064
|
-
queryLimit ? (0,
|
|
17065
|
-
lastVisible ? (0,
|
|
17188
|
+
(0, import_firestore53.where)("categoryId", "==", categoryId),
|
|
17189
|
+
(0, import_firestore53.where)("isActive", "==", active),
|
|
17190
|
+
(0, import_firestore53.orderBy)("name"),
|
|
17191
|
+
queryLimit ? (0, import_firestore53.limit)(queryLimit) : void 0,
|
|
17192
|
+
lastVisible ? (0, import_firestore53.startAfter)(lastVisible) : void 0
|
|
17066
17193
|
].filter((c) => !!c);
|
|
17067
|
-
const q = (0,
|
|
17068
|
-
const snapshot = await (0,
|
|
17194
|
+
const q = (0, import_firestore53.query)(this.technologiesRef, ...constraints);
|
|
17195
|
+
const snapshot = await (0, import_firestore53.getDocs)(q);
|
|
17069
17196
|
const technologies = snapshot.docs.map(
|
|
17070
17197
|
(doc38) => ({
|
|
17071
17198
|
id: doc38.id,
|
|
@@ -17084,14 +17211,14 @@ var TechnologyService = class extends BaseService {
|
|
|
17084
17211
|
async getAllBySubcategoryId(subcategoryId, options = {}) {
|
|
17085
17212
|
const { active = true, limit: queryLimit = 10, lastVisible } = options;
|
|
17086
17213
|
const constraints = [
|
|
17087
|
-
(0,
|
|
17088
|
-
(0,
|
|
17089
|
-
(0,
|
|
17090
|
-
queryLimit ? (0,
|
|
17091
|
-
lastVisible ? (0,
|
|
17214
|
+
(0, import_firestore53.where)("subcategoryId", "==", subcategoryId),
|
|
17215
|
+
(0, import_firestore53.where)("isActive", "==", active),
|
|
17216
|
+
(0, import_firestore53.orderBy)("name"),
|
|
17217
|
+
queryLimit ? (0, import_firestore53.limit)(queryLimit) : void 0,
|
|
17218
|
+
lastVisible ? (0, import_firestore53.startAfter)(lastVisible) : void 0
|
|
17092
17219
|
].filter((c) => !!c);
|
|
17093
|
-
const q = (0,
|
|
17094
|
-
const snapshot = await (0,
|
|
17220
|
+
const q = (0, import_firestore53.query)(this.technologiesRef, ...constraints);
|
|
17221
|
+
const snapshot = await (0, import_firestore53.getDocs)(q);
|
|
17095
17222
|
const technologies = snapshot.docs.map(
|
|
17096
17223
|
(doc38) => ({
|
|
17097
17224
|
id: doc38.id,
|
|
@@ -17115,8 +17242,8 @@ var TechnologyService = class extends BaseService {
|
|
|
17115
17242
|
}
|
|
17116
17243
|
});
|
|
17117
17244
|
updateData.updatedAt = /* @__PURE__ */ new Date();
|
|
17118
|
-
const docRef = (0,
|
|
17119
|
-
await (0,
|
|
17245
|
+
const docRef = (0, import_firestore53.doc)(this.technologiesRef, id);
|
|
17246
|
+
await (0, import_firestore53.updateDoc)(docRef, updateData);
|
|
17120
17247
|
return this.getById(id);
|
|
17121
17248
|
}
|
|
17122
17249
|
/**
|
|
@@ -17139,8 +17266,8 @@ var TechnologyService = class extends BaseService {
|
|
|
17139
17266
|
* @returns The technology or null if it doesn't exist.
|
|
17140
17267
|
*/
|
|
17141
17268
|
async getById(id) {
|
|
17142
|
-
const docRef = (0,
|
|
17143
|
-
const docSnap = await (0,
|
|
17269
|
+
const docRef = (0, import_firestore53.doc)(this.technologiesRef, id);
|
|
17270
|
+
const docSnap = await (0, import_firestore53.getDoc)(docRef);
|
|
17144
17271
|
if (!docSnap.exists()) return null;
|
|
17145
17272
|
return {
|
|
17146
17273
|
id: docSnap.id,
|
|
@@ -17154,10 +17281,10 @@ var TechnologyService = class extends BaseService {
|
|
|
17154
17281
|
* @returns Ažurirana tehnologija sa novim zahtevom
|
|
17155
17282
|
*/
|
|
17156
17283
|
async addRequirement(technologyId, requirement) {
|
|
17157
|
-
const docRef = (0,
|
|
17284
|
+
const docRef = (0, import_firestore53.doc)(this.technologiesRef, technologyId);
|
|
17158
17285
|
const requirementType = requirement.type === "pre" ? "requirements.pre" : "requirements.post";
|
|
17159
|
-
await (0,
|
|
17160
|
-
[requirementType]: (0,
|
|
17286
|
+
await (0, import_firestore53.updateDoc)(docRef, {
|
|
17287
|
+
[requirementType]: (0, import_firestore53.arrayUnion)(requirement),
|
|
17161
17288
|
updatedAt: /* @__PURE__ */ new Date()
|
|
17162
17289
|
});
|
|
17163
17290
|
return this.getById(technologyId);
|
|
@@ -17169,10 +17296,10 @@ var TechnologyService = class extends BaseService {
|
|
|
17169
17296
|
* @returns Ažurirana tehnologija bez uklonjenog zahteva
|
|
17170
17297
|
*/
|
|
17171
17298
|
async removeRequirement(technologyId, requirement) {
|
|
17172
|
-
const docRef = (0,
|
|
17299
|
+
const docRef = (0, import_firestore53.doc)(this.technologiesRef, technologyId);
|
|
17173
17300
|
const requirementType = requirement.type === "pre" ? "requirements.pre" : "requirements.post";
|
|
17174
|
-
await (0,
|
|
17175
|
-
[requirementType]: (0,
|
|
17301
|
+
await (0, import_firestore53.updateDoc)(docRef, {
|
|
17302
|
+
[requirementType]: (0, import_firestore53.arrayRemove)(requirement),
|
|
17176
17303
|
updatedAt: /* @__PURE__ */ new Date()
|
|
17177
17304
|
});
|
|
17178
17305
|
return this.getById(technologyId);
|
|
@@ -17209,9 +17336,9 @@ var TechnologyService = class extends BaseService {
|
|
|
17209
17336
|
* @returns Ažurirana tehnologija
|
|
17210
17337
|
*/
|
|
17211
17338
|
async addBlockingCondition(technologyId, condition) {
|
|
17212
|
-
const docRef = (0,
|
|
17213
|
-
await (0,
|
|
17214
|
-
blockingConditions: (0,
|
|
17339
|
+
const docRef = (0, import_firestore53.doc)(this.technologiesRef, technologyId);
|
|
17340
|
+
await (0, import_firestore53.updateDoc)(docRef, {
|
|
17341
|
+
blockingConditions: (0, import_firestore53.arrayUnion)(condition),
|
|
17215
17342
|
updatedAt: /* @__PURE__ */ new Date()
|
|
17216
17343
|
});
|
|
17217
17344
|
return this.getById(technologyId);
|
|
@@ -17223,9 +17350,9 @@ var TechnologyService = class extends BaseService {
|
|
|
17223
17350
|
* @returns Ažurirana tehnologija
|
|
17224
17351
|
*/
|
|
17225
17352
|
async removeBlockingCondition(technologyId, condition) {
|
|
17226
|
-
const docRef = (0,
|
|
17227
|
-
await (0,
|
|
17228
|
-
blockingConditions: (0,
|
|
17353
|
+
const docRef = (0, import_firestore53.doc)(this.technologiesRef, technologyId);
|
|
17354
|
+
await (0, import_firestore53.updateDoc)(docRef, {
|
|
17355
|
+
blockingConditions: (0, import_firestore53.arrayRemove)(condition),
|
|
17229
17356
|
updatedAt: /* @__PURE__ */ new Date()
|
|
17230
17357
|
});
|
|
17231
17358
|
return this.getById(technologyId);
|
|
@@ -17237,7 +17364,7 @@ var TechnologyService = class extends BaseService {
|
|
|
17237
17364
|
* @returns Ažurirana tehnologija
|
|
17238
17365
|
*/
|
|
17239
17366
|
async addContraindication(technologyId, contraindication) {
|
|
17240
|
-
const docRef = (0,
|
|
17367
|
+
const docRef = (0, import_firestore53.doc)(this.technologiesRef, technologyId);
|
|
17241
17368
|
const technology = await this.getById(technologyId);
|
|
17242
17369
|
if (!technology) {
|
|
17243
17370
|
throw new Error(`Technology with id ${technologyId} not found`);
|
|
@@ -17246,7 +17373,7 @@ var TechnologyService = class extends BaseService {
|
|
|
17246
17373
|
if (existingContraindications.some((c) => c.id === contraindication.id)) {
|
|
17247
17374
|
return technology;
|
|
17248
17375
|
}
|
|
17249
|
-
await (0,
|
|
17376
|
+
await (0, import_firestore53.updateDoc)(docRef, {
|
|
17250
17377
|
contraindications: [...existingContraindications, contraindication],
|
|
17251
17378
|
updatedAt: /* @__PURE__ */ new Date()
|
|
17252
17379
|
});
|
|
@@ -17259,7 +17386,7 @@ var TechnologyService = class extends BaseService {
|
|
|
17259
17386
|
* @returns Ažurirana tehnologija
|
|
17260
17387
|
*/
|
|
17261
17388
|
async removeContraindication(technologyId, contraindication) {
|
|
17262
|
-
const docRef = (0,
|
|
17389
|
+
const docRef = (0, import_firestore53.doc)(this.technologiesRef, technologyId);
|
|
17263
17390
|
const technology = await this.getById(technologyId);
|
|
17264
17391
|
if (!technology) {
|
|
17265
17392
|
throw new Error(`Technology with id ${technologyId} not found`);
|
|
@@ -17267,7 +17394,7 @@ var TechnologyService = class extends BaseService {
|
|
|
17267
17394
|
const updatedContraindications = (technology.contraindications || []).filter(
|
|
17268
17395
|
(c) => c.id !== contraindication.id
|
|
17269
17396
|
);
|
|
17270
|
-
await (0,
|
|
17397
|
+
await (0, import_firestore53.updateDoc)(docRef, {
|
|
17271
17398
|
contraindications: updatedContraindications,
|
|
17272
17399
|
updatedAt: /* @__PURE__ */ new Date()
|
|
17273
17400
|
});
|
|
@@ -17281,7 +17408,7 @@ var TechnologyService = class extends BaseService {
|
|
|
17281
17408
|
* @returns The updated technology
|
|
17282
17409
|
*/
|
|
17283
17410
|
async updateContraindication(technologyId, contraindication) {
|
|
17284
|
-
const docRef = (0,
|
|
17411
|
+
const docRef = (0, import_firestore53.doc)(this.technologiesRef, technologyId);
|
|
17285
17412
|
const technology = await this.getById(technologyId);
|
|
17286
17413
|
if (!technology) {
|
|
17287
17414
|
throw new Error(`Technology with id ${technologyId} not found`);
|
|
@@ -17296,7 +17423,7 @@ var TechnologyService = class extends BaseService {
|
|
|
17296
17423
|
}
|
|
17297
17424
|
const updatedContraindications = [...contraindications];
|
|
17298
17425
|
updatedContraindications[index] = contraindication;
|
|
17299
|
-
await (0,
|
|
17426
|
+
await (0, import_firestore53.updateDoc)(docRef, {
|
|
17300
17427
|
contraindications: updatedContraindications,
|
|
17301
17428
|
updatedAt: /* @__PURE__ */ new Date()
|
|
17302
17429
|
});
|
|
@@ -17309,7 +17436,7 @@ var TechnologyService = class extends BaseService {
|
|
|
17309
17436
|
* @returns Ažurirana tehnologija
|
|
17310
17437
|
*/
|
|
17311
17438
|
async addBenefit(technologyId, benefit) {
|
|
17312
|
-
const docRef = (0,
|
|
17439
|
+
const docRef = (0, import_firestore53.doc)(this.technologiesRef, technologyId);
|
|
17313
17440
|
const technology = await this.getById(technologyId);
|
|
17314
17441
|
if (!technology) {
|
|
17315
17442
|
throw new Error(`Technology with id ${technologyId} not found`);
|
|
@@ -17318,7 +17445,7 @@ var TechnologyService = class extends BaseService {
|
|
|
17318
17445
|
if (existingBenefits.some((b) => b.id === benefit.id)) {
|
|
17319
17446
|
return technology;
|
|
17320
17447
|
}
|
|
17321
|
-
await (0,
|
|
17448
|
+
await (0, import_firestore53.updateDoc)(docRef, {
|
|
17322
17449
|
benefits: [...existingBenefits, benefit],
|
|
17323
17450
|
updatedAt: /* @__PURE__ */ new Date()
|
|
17324
17451
|
});
|
|
@@ -17331,13 +17458,13 @@ var TechnologyService = class extends BaseService {
|
|
|
17331
17458
|
* @returns Ažurirana tehnologija
|
|
17332
17459
|
*/
|
|
17333
17460
|
async removeBenefit(technologyId, benefit) {
|
|
17334
|
-
const docRef = (0,
|
|
17461
|
+
const docRef = (0, import_firestore53.doc)(this.technologiesRef, technologyId);
|
|
17335
17462
|
const technology = await this.getById(technologyId);
|
|
17336
17463
|
if (!technology) {
|
|
17337
17464
|
throw new Error(`Technology with id ${technologyId} not found`);
|
|
17338
17465
|
}
|
|
17339
17466
|
const updatedBenefits = (technology.benefits || []).filter((b) => b.id !== benefit.id);
|
|
17340
|
-
await (0,
|
|
17467
|
+
await (0, import_firestore53.updateDoc)(docRef, {
|
|
17341
17468
|
benefits: updatedBenefits,
|
|
17342
17469
|
updatedAt: /* @__PURE__ */ new Date()
|
|
17343
17470
|
});
|
|
@@ -17351,7 +17478,7 @@ var TechnologyService = class extends BaseService {
|
|
|
17351
17478
|
* @returns The updated technology
|
|
17352
17479
|
*/
|
|
17353
17480
|
async updateBenefit(technologyId, benefit) {
|
|
17354
|
-
const docRef = (0,
|
|
17481
|
+
const docRef = (0, import_firestore53.doc)(this.technologiesRef, technologyId);
|
|
17355
17482
|
const technology = await this.getById(technologyId);
|
|
17356
17483
|
if (!technology) {
|
|
17357
17484
|
throw new Error(`Technology with id ${technologyId} not found`);
|
|
@@ -17366,7 +17493,7 @@ var TechnologyService = class extends BaseService {
|
|
|
17366
17493
|
}
|
|
17367
17494
|
const updatedBenefits = [...benefits];
|
|
17368
17495
|
updatedBenefits[index] = benefit;
|
|
17369
|
-
await (0,
|
|
17496
|
+
await (0, import_firestore53.updateDoc)(docRef, {
|
|
17370
17497
|
benefits: updatedBenefits,
|
|
17371
17498
|
updatedAt: /* @__PURE__ */ new Date()
|
|
17372
17499
|
});
|
|
@@ -17406,8 +17533,8 @@ var TechnologyService = class extends BaseService {
|
|
|
17406
17533
|
* @returns Ažurirana tehnologija
|
|
17407
17534
|
*/
|
|
17408
17535
|
async updateCertificationRequirement(technologyId, certificationRequirement) {
|
|
17409
|
-
const docRef = (0,
|
|
17410
|
-
await (0,
|
|
17536
|
+
const docRef = (0, import_firestore53.doc)(this.technologiesRef, technologyId);
|
|
17537
|
+
await (0, import_firestore53.updateDoc)(docRef, {
|
|
17411
17538
|
certificationRequirement,
|
|
17412
17539
|
updatedAt: /* @__PURE__ */ new Date()
|
|
17413
17540
|
});
|
|
@@ -17500,13 +17627,13 @@ var TechnologyService = class extends BaseService {
|
|
|
17500
17627
|
* @param subcategoryId - The ID of the subcategory.
|
|
17501
17628
|
*/
|
|
17502
17629
|
async getAllForFilterBySubcategory(subcategoryId) {
|
|
17503
|
-
const q = (0,
|
|
17504
|
-
(0,
|
|
17505
|
-
(0,
|
|
17506
|
-
(0,
|
|
17507
|
-
(0,
|
|
17630
|
+
const q = (0, import_firestore53.query)(
|
|
17631
|
+
(0, import_firestore53.collection)(this.db, TECHNOLOGIES_COLLECTION),
|
|
17632
|
+
(0, import_firestore53.where)("isActive", "==", true),
|
|
17633
|
+
(0, import_firestore53.where)("subcategoryId", "==", subcategoryId),
|
|
17634
|
+
(0, import_firestore53.orderBy)("name")
|
|
17508
17635
|
);
|
|
17509
|
-
const snapshot = await (0,
|
|
17636
|
+
const snapshot = await (0, import_firestore53.getDocs)(q);
|
|
17510
17637
|
return snapshot.docs.map(
|
|
17511
17638
|
(doc38) => ({
|
|
17512
17639
|
id: doc38.id,
|
|
@@ -17520,14 +17647,14 @@ var TechnologyService = class extends BaseService {
|
|
|
17520
17647
|
* @param subcategoryId - The ID of the subcategory.
|
|
17521
17648
|
*/
|
|
17522
17649
|
async getAllForFilterBySubcategoryId(categoryId, subcategoryId) {
|
|
17523
|
-
const q = (0,
|
|
17524
|
-
(0,
|
|
17525
|
-
(0,
|
|
17526
|
-
(0,
|
|
17527
|
-
(0,
|
|
17528
|
-
(0,
|
|
17650
|
+
const q = (0, import_firestore53.query)(
|
|
17651
|
+
(0, import_firestore53.collection)(this.db, TECHNOLOGIES_COLLECTION),
|
|
17652
|
+
(0, import_firestore53.where)("isActive", "==", true),
|
|
17653
|
+
(0, import_firestore53.where)("categoryId", "==", categoryId),
|
|
17654
|
+
(0, import_firestore53.where)("subcategoryId", "==", subcategoryId),
|
|
17655
|
+
(0, import_firestore53.orderBy)("name")
|
|
17529
17656
|
);
|
|
17530
|
-
const snapshot = await (0,
|
|
17657
|
+
const snapshot = await (0, import_firestore53.getDocs)(q);
|
|
17531
17658
|
return snapshot.docs.map(
|
|
17532
17659
|
(doc38) => ({
|
|
17533
17660
|
id: doc38.id,
|
|
@@ -17539,12 +17666,12 @@ var TechnologyService = class extends BaseService {
|
|
|
17539
17666
|
* Gets all active technologies for filter dropdowns.
|
|
17540
17667
|
*/
|
|
17541
17668
|
async getAllForFilter() {
|
|
17542
|
-
const q = (0,
|
|
17543
|
-
(0,
|
|
17544
|
-
(0,
|
|
17545
|
-
(0,
|
|
17669
|
+
const q = (0, import_firestore53.query)(
|
|
17670
|
+
(0, import_firestore53.collection)(this.db, TECHNOLOGIES_COLLECTION),
|
|
17671
|
+
(0, import_firestore53.where)("isActive", "==", true),
|
|
17672
|
+
(0, import_firestore53.orderBy)("name")
|
|
17546
17673
|
);
|
|
17547
|
-
const snapshot = await (0,
|
|
17674
|
+
const snapshot = await (0, import_firestore53.getDocs)(q);
|
|
17548
17675
|
return snapshot.docs.map(
|
|
17549
17676
|
(doc38) => ({
|
|
17550
17677
|
id: doc38.id,
|
|
@@ -17555,7 +17682,7 @@ var TechnologyService = class extends BaseService {
|
|
|
17555
17682
|
};
|
|
17556
17683
|
|
|
17557
17684
|
// src/backoffice/services/product.service.ts
|
|
17558
|
-
var
|
|
17685
|
+
var import_firestore54 = require("firebase/firestore");
|
|
17559
17686
|
|
|
17560
17687
|
// src/backoffice/types/product.types.ts
|
|
17561
17688
|
var PRODUCTS_COLLECTION = "products";
|
|
@@ -17568,7 +17695,7 @@ var ProductService = class extends BaseService {
|
|
|
17568
17695
|
* @returns Firestore collection reference
|
|
17569
17696
|
*/
|
|
17570
17697
|
getProductsRef(technologyId) {
|
|
17571
|
-
return (0,
|
|
17698
|
+
return (0, import_firestore54.collection)(this.db, TECHNOLOGIES_COLLECTION, technologyId, PRODUCTS_COLLECTION);
|
|
17572
17699
|
}
|
|
17573
17700
|
/**
|
|
17574
17701
|
* Creates a new product under technology
|
|
@@ -17583,7 +17710,7 @@ var ProductService = class extends BaseService {
|
|
|
17583
17710
|
updatedAt: now,
|
|
17584
17711
|
isActive: true
|
|
17585
17712
|
};
|
|
17586
|
-
const productRef = await (0,
|
|
17713
|
+
const productRef = await (0, import_firestore54.addDoc)(this.getProductsRef(technologyId), newProduct);
|
|
17587
17714
|
return { id: productRef.id, ...newProduct };
|
|
17588
17715
|
}
|
|
17589
17716
|
/**
|
|
@@ -17592,22 +17719,22 @@ var ProductService = class extends BaseService {
|
|
|
17592
17719
|
*/
|
|
17593
17720
|
async getAll(options) {
|
|
17594
17721
|
const { rowsPerPage, lastVisible, categoryId, subcategoryId, technologyId } = options;
|
|
17595
|
-
const constraints = [(0,
|
|
17722
|
+
const constraints = [(0, import_firestore54.where)("isActive", "==", true), (0, import_firestore54.orderBy)("name")];
|
|
17596
17723
|
if (categoryId) {
|
|
17597
|
-
constraints.push((0,
|
|
17724
|
+
constraints.push((0, import_firestore54.where)("categoryId", "==", categoryId));
|
|
17598
17725
|
}
|
|
17599
17726
|
if (subcategoryId) {
|
|
17600
|
-
constraints.push((0,
|
|
17727
|
+
constraints.push((0, import_firestore54.where)("subcategoryId", "==", subcategoryId));
|
|
17601
17728
|
}
|
|
17602
17729
|
if (technologyId) {
|
|
17603
|
-
constraints.push((0,
|
|
17730
|
+
constraints.push((0, import_firestore54.where)("technologyId", "==", technologyId));
|
|
17604
17731
|
}
|
|
17605
17732
|
if (lastVisible) {
|
|
17606
|
-
constraints.push((0,
|
|
17733
|
+
constraints.push((0, import_firestore54.startAfter)(lastVisible));
|
|
17607
17734
|
}
|
|
17608
|
-
constraints.push((0,
|
|
17609
|
-
const q = (0,
|
|
17610
|
-
const snapshot = await (0,
|
|
17735
|
+
constraints.push((0, import_firestore54.limit)(rowsPerPage));
|
|
17736
|
+
const q = (0, import_firestore54.query)((0, import_firestore54.collectionGroup)(this.db, PRODUCTS_COLLECTION), ...constraints);
|
|
17737
|
+
const snapshot = await (0, import_firestore54.getDocs)(q);
|
|
17611
17738
|
const products = snapshot.docs.map(
|
|
17612
17739
|
(doc38) => ({
|
|
17613
17740
|
id: doc38.id,
|
|
@@ -17622,18 +17749,18 @@ var ProductService = class extends BaseService {
|
|
|
17622
17749
|
*/
|
|
17623
17750
|
async getProductsCount(options) {
|
|
17624
17751
|
const { categoryId, subcategoryId, technologyId } = options;
|
|
17625
|
-
const constraints = [(0,
|
|
17752
|
+
const constraints = [(0, import_firestore54.where)("isActive", "==", true)];
|
|
17626
17753
|
if (categoryId) {
|
|
17627
|
-
constraints.push((0,
|
|
17754
|
+
constraints.push((0, import_firestore54.where)("categoryId", "==", categoryId));
|
|
17628
17755
|
}
|
|
17629
17756
|
if (subcategoryId) {
|
|
17630
|
-
constraints.push((0,
|
|
17757
|
+
constraints.push((0, import_firestore54.where)("subcategoryId", "==", subcategoryId));
|
|
17631
17758
|
}
|
|
17632
17759
|
if (technologyId) {
|
|
17633
|
-
constraints.push((0,
|
|
17760
|
+
constraints.push((0, import_firestore54.where)("technologyId", "==", technologyId));
|
|
17634
17761
|
}
|
|
17635
|
-
const q = (0,
|
|
17636
|
-
const snapshot = await (0,
|
|
17762
|
+
const q = (0, import_firestore54.query)((0, import_firestore54.collectionGroup)(this.db, PRODUCTS_COLLECTION), ...constraints);
|
|
17763
|
+
const snapshot = await (0, import_firestore54.getCountFromServer)(q);
|
|
17637
17764
|
return snapshot.data().count;
|
|
17638
17765
|
}
|
|
17639
17766
|
/**
|
|
@@ -17641,8 +17768,8 @@ var ProductService = class extends BaseService {
|
|
|
17641
17768
|
* This uses a single collectionGroup query for efficiency.
|
|
17642
17769
|
*/
|
|
17643
17770
|
async getProductCounts() {
|
|
17644
|
-
const q = (0,
|
|
17645
|
-
const snapshot = await (0,
|
|
17771
|
+
const q = (0, import_firestore54.query)((0, import_firestore54.collectionGroup)(this.db, PRODUCTS_COLLECTION), (0, import_firestore54.where)("isActive", "==", true));
|
|
17772
|
+
const snapshot = await (0, import_firestore54.getDocs)(q);
|
|
17646
17773
|
const counts = {
|
|
17647
17774
|
byCategory: {},
|
|
17648
17775
|
bySubcategory: {},
|
|
@@ -17670,12 +17797,12 @@ var ProductService = class extends BaseService {
|
|
|
17670
17797
|
* Gets all products for a specific technology (non-paginated, for filters/dropdowns)
|
|
17671
17798
|
*/
|
|
17672
17799
|
async getAllByTechnology(technologyId) {
|
|
17673
|
-
const q = (0,
|
|
17800
|
+
const q = (0, import_firestore54.query)(
|
|
17674
17801
|
this.getProductsRef(technologyId),
|
|
17675
|
-
(0,
|
|
17676
|
-
(0,
|
|
17802
|
+
(0, import_firestore54.where)("isActive", "==", true),
|
|
17803
|
+
(0, import_firestore54.orderBy)("name")
|
|
17677
17804
|
);
|
|
17678
|
-
const snapshot = await (0,
|
|
17805
|
+
const snapshot = await (0, import_firestore54.getDocs)(q);
|
|
17679
17806
|
return snapshot.docs.map(
|
|
17680
17807
|
(doc38) => ({
|
|
17681
17808
|
id: doc38.id,
|
|
@@ -17687,16 +17814,16 @@ var ProductService = class extends BaseService {
|
|
|
17687
17814
|
* Gets all products for a brand by filtering through all technologies
|
|
17688
17815
|
*/
|
|
17689
17816
|
async getAllByBrand(brandId) {
|
|
17690
|
-
const allTechnologiesRef = (0,
|
|
17691
|
-
const technologiesSnapshot = await (0,
|
|
17817
|
+
const allTechnologiesRef = (0, import_firestore54.collection)(this.db, TECHNOLOGIES_COLLECTION);
|
|
17818
|
+
const technologiesSnapshot = await (0, import_firestore54.getDocs)(allTechnologiesRef);
|
|
17692
17819
|
const products = [];
|
|
17693
17820
|
for (const techDoc of technologiesSnapshot.docs) {
|
|
17694
|
-
const q = (0,
|
|
17821
|
+
const q = (0, import_firestore54.query)(
|
|
17695
17822
|
this.getProductsRef(techDoc.id),
|
|
17696
|
-
(0,
|
|
17697
|
-
(0,
|
|
17823
|
+
(0, import_firestore54.where)("brandId", "==", brandId),
|
|
17824
|
+
(0, import_firestore54.where)("isActive", "==", true)
|
|
17698
17825
|
);
|
|
17699
|
-
const snapshot = await (0,
|
|
17826
|
+
const snapshot = await (0, import_firestore54.getDocs)(q);
|
|
17700
17827
|
products.push(
|
|
17701
17828
|
...snapshot.docs.map(
|
|
17702
17829
|
(doc38) => ({
|
|
@@ -17716,8 +17843,8 @@ var ProductService = class extends BaseService {
|
|
|
17716
17843
|
...product,
|
|
17717
17844
|
updatedAt: /* @__PURE__ */ new Date()
|
|
17718
17845
|
};
|
|
17719
|
-
const docRef = (0,
|
|
17720
|
-
await (0,
|
|
17846
|
+
const docRef = (0, import_firestore54.doc)(this.getProductsRef(technologyId), productId);
|
|
17847
|
+
await (0, import_firestore54.updateDoc)(docRef, updateData);
|
|
17721
17848
|
return this.getById(technologyId, productId);
|
|
17722
17849
|
}
|
|
17723
17850
|
/**
|
|
@@ -17732,8 +17859,8 @@ var ProductService = class extends BaseService {
|
|
|
17732
17859
|
* Gets a product by ID
|
|
17733
17860
|
*/
|
|
17734
17861
|
async getById(technologyId, productId) {
|
|
17735
|
-
const docRef = (0,
|
|
17736
|
-
const docSnap = await (0,
|
|
17862
|
+
const docRef = (0, import_firestore54.doc)(this.getProductsRef(technologyId), productId);
|
|
17863
|
+
const docSnap = await (0, import_firestore54.getDoc)(docRef);
|
|
17737
17864
|
if (!docSnap.exists()) return null;
|
|
17738
17865
|
return {
|
|
17739
17866
|
id: docSnap.id,
|
|
@@ -17743,7 +17870,7 @@ var ProductService = class extends BaseService {
|
|
|
17743
17870
|
};
|
|
17744
17871
|
|
|
17745
17872
|
// src/backoffice/services/constants.service.ts
|
|
17746
|
-
var
|
|
17873
|
+
var import_firestore55 = require("firebase/firestore");
|
|
17747
17874
|
var ADMIN_CONSTANTS_COLLECTION = "admin-constants";
|
|
17748
17875
|
var TREATMENT_BENEFITS_DOC = "treatment-benefits";
|
|
17749
17876
|
var CONTRAINDICATIONS_DOC = "contraindications";
|
|
@@ -17754,7 +17881,7 @@ var ConstantsService = class extends BaseService {
|
|
|
17754
17881
|
* @type {DocumentReference}
|
|
17755
17882
|
*/
|
|
17756
17883
|
get treatmentBenefitsDocRef() {
|
|
17757
|
-
return (0,
|
|
17884
|
+
return (0, import_firestore55.doc)(this.db, ADMIN_CONSTANTS_COLLECTION, TREATMENT_BENEFITS_DOC);
|
|
17758
17885
|
}
|
|
17759
17886
|
/**
|
|
17760
17887
|
* @description Gets the reference to the document holding contraindications.
|
|
@@ -17762,7 +17889,7 @@ var ConstantsService = class extends BaseService {
|
|
|
17762
17889
|
* @type {DocumentReference}
|
|
17763
17890
|
*/
|
|
17764
17891
|
get contraindicationsDocRef() {
|
|
17765
|
-
return (0,
|
|
17892
|
+
return (0, import_firestore55.doc)(this.db, ADMIN_CONSTANTS_COLLECTION, CONTRAINDICATIONS_DOC);
|
|
17766
17893
|
}
|
|
17767
17894
|
// =================================================================
|
|
17768
17895
|
// Treatment Benefits
|
|
@@ -17772,7 +17899,7 @@ var ConstantsService = class extends BaseService {
|
|
|
17772
17899
|
* @returns {Promise<TreatmentBenefitDynamic[]>} An array of all treatment benefits.
|
|
17773
17900
|
*/
|
|
17774
17901
|
async getAllBenefitsForFilter() {
|
|
17775
|
-
const docSnap = await (0,
|
|
17902
|
+
const docSnap = await (0, import_firestore55.getDoc)(this.treatmentBenefitsDocRef);
|
|
17776
17903
|
if (!docSnap.exists()) {
|
|
17777
17904
|
return [];
|
|
17778
17905
|
}
|
|
@@ -17785,9 +17912,9 @@ var ConstantsService = class extends BaseService {
|
|
|
17785
17912
|
*/
|
|
17786
17913
|
async getAllBenefits(options) {
|
|
17787
17914
|
const allBenefits = await this.getAllBenefitsForFilter();
|
|
17788
|
-
const { page, limit:
|
|
17789
|
-
const startIndex = page *
|
|
17790
|
-
const endIndex = startIndex +
|
|
17915
|
+
const { page, limit: limit22 } = options;
|
|
17916
|
+
const startIndex = page * limit22;
|
|
17917
|
+
const endIndex = startIndex + limit22;
|
|
17791
17918
|
const paginatedBenefits = allBenefits.slice(startIndex, endIndex);
|
|
17792
17919
|
return { benefits: paginatedBenefits, total: allBenefits.length };
|
|
17793
17920
|
}
|
|
@@ -17801,12 +17928,12 @@ var ConstantsService = class extends BaseService {
|
|
|
17801
17928
|
id: this.generateId(),
|
|
17802
17929
|
...benefit
|
|
17803
17930
|
};
|
|
17804
|
-
const docSnap = await (0,
|
|
17931
|
+
const docSnap = await (0, import_firestore55.getDoc)(this.treatmentBenefitsDocRef);
|
|
17805
17932
|
if (!docSnap.exists()) {
|
|
17806
|
-
await (0,
|
|
17933
|
+
await (0, import_firestore55.setDoc)(this.treatmentBenefitsDocRef, { benefits: [newBenefit] });
|
|
17807
17934
|
} else {
|
|
17808
|
-
await (0,
|
|
17809
|
-
benefits: (0,
|
|
17935
|
+
await (0, import_firestore55.updateDoc)(this.treatmentBenefitsDocRef, {
|
|
17936
|
+
benefits: (0, import_firestore55.arrayUnion)(newBenefit)
|
|
17810
17937
|
});
|
|
17811
17938
|
}
|
|
17812
17939
|
return newBenefit;
|
|
@@ -17845,7 +17972,7 @@ var ConstantsService = class extends BaseService {
|
|
|
17845
17972
|
throw new Error("Treatment benefit not found.");
|
|
17846
17973
|
}
|
|
17847
17974
|
benefits[benefitIndex] = benefit;
|
|
17848
|
-
await (0,
|
|
17975
|
+
await (0, import_firestore55.updateDoc)(this.treatmentBenefitsDocRef, { benefits });
|
|
17849
17976
|
return benefit;
|
|
17850
17977
|
}
|
|
17851
17978
|
/**
|
|
@@ -17859,8 +17986,8 @@ var ConstantsService = class extends BaseService {
|
|
|
17859
17986
|
if (!benefitToRemove) {
|
|
17860
17987
|
return;
|
|
17861
17988
|
}
|
|
17862
|
-
await (0,
|
|
17863
|
-
benefits: (0,
|
|
17989
|
+
await (0, import_firestore55.updateDoc)(this.treatmentBenefitsDocRef, {
|
|
17990
|
+
benefits: (0, import_firestore55.arrayRemove)(benefitToRemove)
|
|
17864
17991
|
});
|
|
17865
17992
|
}
|
|
17866
17993
|
// =================================================================
|
|
@@ -17871,7 +17998,7 @@ var ConstantsService = class extends BaseService {
|
|
|
17871
17998
|
* @returns {Promise<ContraindicationDynamic[]>} An array of all contraindications.
|
|
17872
17999
|
*/
|
|
17873
18000
|
async getAllContraindicationsForFilter() {
|
|
17874
|
-
const docSnap = await (0,
|
|
18001
|
+
const docSnap = await (0, import_firestore55.getDoc)(this.contraindicationsDocRef);
|
|
17875
18002
|
if (!docSnap.exists()) {
|
|
17876
18003
|
return [];
|
|
17877
18004
|
}
|
|
@@ -17884,9 +18011,9 @@ var ConstantsService = class extends BaseService {
|
|
|
17884
18011
|
*/
|
|
17885
18012
|
async getAllContraindications(options) {
|
|
17886
18013
|
const allContraindications = await this.getAllContraindicationsForFilter();
|
|
17887
|
-
const { page, limit:
|
|
17888
|
-
const startIndex = page *
|
|
17889
|
-
const endIndex = startIndex +
|
|
18014
|
+
const { page, limit: limit22 } = options;
|
|
18015
|
+
const startIndex = page * limit22;
|
|
18016
|
+
const endIndex = startIndex + limit22;
|
|
17890
18017
|
const paginatedContraindications = allContraindications.slice(
|
|
17891
18018
|
startIndex,
|
|
17892
18019
|
endIndex
|
|
@@ -17906,14 +18033,14 @@ var ConstantsService = class extends BaseService {
|
|
|
17906
18033
|
id: this.generateId(),
|
|
17907
18034
|
...contraindication
|
|
17908
18035
|
};
|
|
17909
|
-
const docSnap = await (0,
|
|
18036
|
+
const docSnap = await (0, import_firestore55.getDoc)(this.contraindicationsDocRef);
|
|
17910
18037
|
if (!docSnap.exists()) {
|
|
17911
|
-
await (0,
|
|
18038
|
+
await (0, import_firestore55.setDoc)(this.contraindicationsDocRef, {
|
|
17912
18039
|
contraindications: [newContraindication]
|
|
17913
18040
|
});
|
|
17914
18041
|
} else {
|
|
17915
|
-
await (0,
|
|
17916
|
-
contraindications: (0,
|
|
18042
|
+
await (0, import_firestore55.updateDoc)(this.contraindicationsDocRef, {
|
|
18043
|
+
contraindications: (0, import_firestore55.arrayUnion)(newContraindication)
|
|
17917
18044
|
});
|
|
17918
18045
|
}
|
|
17919
18046
|
return newContraindication;
|
|
@@ -17954,7 +18081,7 @@ var ConstantsService = class extends BaseService {
|
|
|
17954
18081
|
throw new Error("Contraindication not found.");
|
|
17955
18082
|
}
|
|
17956
18083
|
contraindications[index] = contraindication;
|
|
17957
|
-
await (0,
|
|
18084
|
+
await (0, import_firestore55.updateDoc)(this.contraindicationsDocRef, { contraindications });
|
|
17958
18085
|
return contraindication;
|
|
17959
18086
|
}
|
|
17960
18087
|
/**
|
|
@@ -17968,8 +18095,8 @@ var ConstantsService = class extends BaseService {
|
|
|
17968
18095
|
if (!toRemove) {
|
|
17969
18096
|
return;
|
|
17970
18097
|
}
|
|
17971
|
-
await (0,
|
|
17972
|
-
contraindications: (0,
|
|
18098
|
+
await (0, import_firestore55.updateDoc)(this.contraindicationsDocRef, {
|
|
18099
|
+
contraindications: (0, import_firestore55.arrayRemove)(toRemove)
|
|
17973
18100
|
});
|
|
17974
18101
|
}
|
|
17975
18102
|
};
|
|
@@ -18032,6 +18159,7 @@ var RequirementType = /* @__PURE__ */ ((RequirementType2) => {
|
|
|
18032
18159
|
AuthService,
|
|
18033
18160
|
BaseService,
|
|
18034
18161
|
BillingTransactionType,
|
|
18162
|
+
BillingTransactionsService,
|
|
18035
18163
|
BlockingCondition,
|
|
18036
18164
|
BrandService,
|
|
18037
18165
|
CALENDAR_COLLECTION,
|