@blackcode_sa/metaestetics-api 1.14.18 → 1.14.23
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/admin/index.js +2 -13
- package/dist/admin/index.mjs +2 -13
- package/dist/index.d.mts +11 -14
- package/dist/index.d.ts +11 -14
- package/dist/index.js +64 -171
- package/dist/index.mjs +117 -224
- package/package.json +1 -1
- package/src/admin/mailing/practitionerInvite/templates/invitation.template.ts +2 -13
- package/src/services/auth/auth.service.ts +7 -203
- package/src/services/practitioner/practitioner.service.ts +79 -4
- package/src/services/user/user.service.ts +1 -51
package/dist/index.mjs
CHANGED
|
@@ -11556,6 +11556,24 @@ var PractitionerService = class extends BaseService {
|
|
|
11556
11556
|
if (!practitioner.clinics.includes(validatedData.clinicId)) {
|
|
11557
11557
|
throw new Error("Practitioner is not associated with this clinic");
|
|
11558
11558
|
}
|
|
11559
|
+
let expectedClinicGroupId = null;
|
|
11560
|
+
if (clinic.clinicGroupId === createdBy) {
|
|
11561
|
+
expectedClinicGroupId = createdBy;
|
|
11562
|
+
} else {
|
|
11563
|
+
try {
|
|
11564
|
+
const creatorClinic = await this.getClinicService().getClinic(createdBy);
|
|
11565
|
+
if (creatorClinic && creatorClinic.clinicGroupId === clinic.clinicGroupId) {
|
|
11566
|
+
expectedClinicGroupId = clinic.clinicGroupId;
|
|
11567
|
+
} else {
|
|
11568
|
+
throw new Error("Clinic does not belong to your clinic group");
|
|
11569
|
+
}
|
|
11570
|
+
} catch (error) {
|
|
11571
|
+
if (error.message === "Clinic does not belong to your clinic group") {
|
|
11572
|
+
throw error;
|
|
11573
|
+
}
|
|
11574
|
+
throw new Error("Clinic does not belong to your clinic group");
|
|
11575
|
+
}
|
|
11576
|
+
}
|
|
11559
11577
|
const expiration = validatedData.expiresAt || new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3);
|
|
11560
11578
|
const tokenString = this.generateId().slice(0, 6).toUpperCase();
|
|
11561
11579
|
const token = {
|
|
@@ -11583,18 +11601,22 @@ var PractitionerService = class extends BaseService {
|
|
|
11583
11601
|
/**
|
|
11584
11602
|
* Gets active tokens for a practitioner
|
|
11585
11603
|
* @param practitionerId ID of the practitioner
|
|
11604
|
+
* @param clinicId Optional clinic ID to filter tokens by. If provided, only returns tokens for this clinic.
|
|
11586
11605
|
* @returns Array of active tokens
|
|
11587
11606
|
*/
|
|
11588
|
-
async getPractitionerActiveTokens(practitionerId) {
|
|
11607
|
+
async getPractitionerActiveTokens(practitionerId, clinicId) {
|
|
11589
11608
|
const tokensRef = collection13(
|
|
11590
11609
|
this.db,
|
|
11591
11610
|
`${PRACTITIONERS_COLLECTION}/${practitionerId}/${REGISTER_TOKENS_COLLECTION}`
|
|
11592
11611
|
);
|
|
11593
|
-
const
|
|
11594
|
-
tokensRef,
|
|
11612
|
+
const conditions = [
|
|
11595
11613
|
where13("status", "==", "active" /* ACTIVE */),
|
|
11596
11614
|
where13("expiresAt", ">", Timestamp17.now())
|
|
11597
|
-
|
|
11615
|
+
];
|
|
11616
|
+
if (clinicId) {
|
|
11617
|
+
conditions.push(where13("clinicId", "==", clinicId));
|
|
11618
|
+
}
|
|
11619
|
+
const q = query13(tokensRef, ...conditions);
|
|
11598
11620
|
const querySnapshot = await getDocs13(q);
|
|
11599
11621
|
return querySnapshot.docs.map((doc47) => doc47.data());
|
|
11600
11622
|
}
|
|
@@ -11669,6 +11691,34 @@ var PractitionerService = class extends BaseService {
|
|
|
11669
11691
|
usedAt: Timestamp17.now()
|
|
11670
11692
|
});
|
|
11671
11693
|
}
|
|
11694
|
+
/**
|
|
11695
|
+
* Revokes a token by setting its status to REVOKED
|
|
11696
|
+
* @param tokenId ID of the token
|
|
11697
|
+
* @param practitionerId ID of the practitioner
|
|
11698
|
+
* @param clinicId ID of the clinic that owns the token. Used to verify ownership before revoking.
|
|
11699
|
+
* @throws Error if token doesn't exist or doesn't belong to the specified clinic
|
|
11700
|
+
*/
|
|
11701
|
+
async revokeToken(tokenId, practitionerId, clinicId) {
|
|
11702
|
+
const tokenRef = doc20(
|
|
11703
|
+
this.db,
|
|
11704
|
+
`${PRACTITIONERS_COLLECTION}/${practitionerId}/${REGISTER_TOKENS_COLLECTION}/${tokenId}`
|
|
11705
|
+
);
|
|
11706
|
+
const tokenDoc = await getDoc22(tokenRef);
|
|
11707
|
+
if (!tokenDoc.exists()) {
|
|
11708
|
+
throw new Error("Token not found");
|
|
11709
|
+
}
|
|
11710
|
+
const tokenData = tokenDoc.data();
|
|
11711
|
+
if (tokenData.clinicId !== clinicId) {
|
|
11712
|
+
throw new Error("Token does not belong to the specified clinic");
|
|
11713
|
+
}
|
|
11714
|
+
if (tokenData.status !== "active" /* ACTIVE */) {
|
|
11715
|
+
throw new Error("Token is not active and cannot be revoked");
|
|
11716
|
+
}
|
|
11717
|
+
await updateDoc16(tokenRef, {
|
|
11718
|
+
status: "revoked" /* REVOKED */,
|
|
11719
|
+
updatedAt: serverTimestamp17()
|
|
11720
|
+
});
|
|
11721
|
+
}
|
|
11672
11722
|
/**
|
|
11673
11723
|
* Dohvata zdravstvenog radnika po ID-u
|
|
11674
11724
|
*/
|
|
@@ -12903,11 +12953,6 @@ var PractitionerService = class extends BaseService {
|
|
|
12903
12953
|
var UserService = class extends BaseService {
|
|
12904
12954
|
constructor(db, auth, app, patientService, clinicAdminService, practitionerService) {
|
|
12905
12955
|
super(db, auth, app);
|
|
12906
|
-
if (!this.auth.__userServiceId) {
|
|
12907
|
-
this.auth.__userServiceId = "user-service-" + Date.now();
|
|
12908
|
-
}
|
|
12909
|
-
console.log("[USER_SERVICE] Constructor - auth ID:", this.auth.__userServiceId);
|
|
12910
|
-
console.log("[USER_SERVICE] Constructor - auth.__authServiceId:", this.auth.__authServiceId || "NOT SET");
|
|
12911
12956
|
if (!patientService) {
|
|
12912
12957
|
patientService = new PatientService(db, auth, app);
|
|
12913
12958
|
}
|
|
@@ -12934,25 +12979,6 @@ var UserService = class extends BaseService {
|
|
|
12934
12979
|
* Kreira novog korisnika na osnovu Firebase korisnika
|
|
12935
12980
|
*/
|
|
12936
12981
|
async createUser(firebaseUser, roles = ["patient" /* PATIENT */], options) {
|
|
12937
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
12938
|
-
console.log("[USER_SERVICE] ====== CREATE USER DEBUG ======");
|
|
12939
|
-
console.log(this.auth);
|
|
12940
|
-
console.log("[USER_SERVICE] Auth instance ID:", ((_a = this.auth) == null ? void 0 : _a.__debugId) || "no-id");
|
|
12941
|
-
console.log("[USER_SERVICE] Current auth state:", {
|
|
12942
|
-
currentUser: ((_c = (_b = this.auth) == null ? void 0 : _b.currentUser) == null ? void 0 : _c.uid) || "NULL",
|
|
12943
|
-
currentUserEmail: ((_e = (_d = this.auth) == null ? void 0 : _d.currentUser) == null ? void 0 : _e.email) || "NULL",
|
|
12944
|
-
currentUserProvider: ((_g = (_f = this.auth) == null ? void 0 : _f.currentUser) == null ? void 0 : _g.providerId) || "NULL"
|
|
12945
|
-
});
|
|
12946
|
-
console.log("[USER_SERVICE] Firebase user passed to createUser:", {
|
|
12947
|
-
uid: (firebaseUser == null ? void 0 : firebaseUser.uid) || "NULL",
|
|
12948
|
-
email: (firebaseUser == null ? void 0 : firebaseUser.email) || "NULL",
|
|
12949
|
-
providerId: (firebaseUser == null ? void 0 : firebaseUser.providerId) || "NULL",
|
|
12950
|
-
isAnonymous: firebaseUser == null ? void 0 : firebaseUser.isAnonymous
|
|
12951
|
-
});
|
|
12952
|
-
console.log("[USER_SERVICE] Auth instances match:", ((_i = (_h = this.auth) == null ? void 0 : _h.currentUser) == null ? void 0 : _i.uid) === (firebaseUser == null ? void 0 : firebaseUser.uid));
|
|
12953
|
-
console.log("[USER_SERVICE] Document path:", `${USERS_COLLECTION}/${firebaseUser == null ? void 0 : firebaseUser.uid}`);
|
|
12954
|
-
console.log("[USER_SERVICE] Roles:", roles);
|
|
12955
|
-
console.log("[USER_SERVICE] ================================");
|
|
12956
12982
|
const userData = {
|
|
12957
12983
|
uid: firebaseUser.uid,
|
|
12958
12984
|
email: firebaseUser.email,
|
|
@@ -12962,22 +12988,7 @@ var UserService = class extends BaseService {
|
|
|
12962
12988
|
updatedAt: serverTimestamp18(),
|
|
12963
12989
|
lastLoginAt: serverTimestamp18()
|
|
12964
12990
|
};
|
|
12965
|
-
|
|
12966
|
-
uid: userData.uid,
|
|
12967
|
-
email: userData.email,
|
|
12968
|
-
roles: userData.roles
|
|
12969
|
-
});
|
|
12970
|
-
try {
|
|
12971
|
-
await setDoc12(doc21(this.db, USERS_COLLECTION, userData.uid), userData);
|
|
12972
|
-
console.log("[USER_SERVICE] \u2705 setDoc SUCCEEDED for:", userData.uid);
|
|
12973
|
-
} catch (error) {
|
|
12974
|
-
console.error("[USER_SERVICE] \u274C setDoc FAILED:", {
|
|
12975
|
-
errorCode: error == null ? void 0 : error.code,
|
|
12976
|
-
errorMessage: error == null ? void 0 : error.message,
|
|
12977
|
-
uid: userData.uid
|
|
12978
|
-
});
|
|
12979
|
-
throw error;
|
|
12980
|
-
}
|
|
12991
|
+
await setDoc12(doc21(this.db, USERS_COLLECTION, userData.uid), userData);
|
|
12981
12992
|
if (options == null ? void 0 : options.skipProfileCreation) {
|
|
12982
12993
|
return this.getUserById(userData.uid);
|
|
12983
12994
|
}
|
|
@@ -15471,59 +15482,28 @@ var validatePractitionerProfileData = async (profileData) => {
|
|
|
15471
15482
|
// src/services/auth/auth.service.ts
|
|
15472
15483
|
var AuthService = class extends BaseService {
|
|
15473
15484
|
constructor(db, auth, app, userService) {
|
|
15474
|
-
var _a;
|
|
15475
15485
|
super(db, auth, app);
|
|
15476
15486
|
this.googleProvider = new GoogleAuthProvider();
|
|
15477
15487
|
this.userService = userService || new UserService(db, auth, app);
|
|
15478
|
-
onAuthStateChanged(this.auth, (user) => {
|
|
15479
|
-
var _a2, _b;
|
|
15480
|
-
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
15481
|
-
const stackTrace = ((_a2 = new Error().stack) == null ? void 0 : _a2.split("\n").slice(2, 5).join("\n")) || "N/A";
|
|
15482
|
-
console.log(`[AUTH STATE CHANGE] ${timestamp}`);
|
|
15483
|
-
console.log(`[AUTH STATE CHANGE] User: ${(user == null ? void 0 : user.uid) || "NULL"} (email: ${(user == null ? void 0 : user.email) || "N/A"})`);
|
|
15484
|
-
console.log(`[AUTH STATE CHANGE] auth.currentUser: ${((_b = this.auth.currentUser) == null ? void 0 : _b.uid) || "NULL"}`);
|
|
15485
|
-
console.log(`[AUTH STATE CHANGE] Stack trace (first 3 frames):
|
|
15486
|
-
${stackTrace}`);
|
|
15487
|
-
console.log("[AUTH STATE CHANGE] ---");
|
|
15488
|
-
});
|
|
15489
|
-
console.log("[AUTH] AuthService initialized");
|
|
15490
|
-
console.log("[AUTH] Initial auth.currentUser:", ((_a = this.auth.currentUser) == null ? void 0 : _a.uid) || "NULL");
|
|
15491
15488
|
}
|
|
15492
15489
|
/**
|
|
15493
15490
|
* Waits for Firebase Auth state to settle after sign-in.
|
|
15494
|
-
*
|
|
15495
|
-
* In React Native with AsyncStorage persistence, there's a critical issue:
|
|
15496
|
-
* 1. signInWithCredential() sets auth.currentUser in memory immediately
|
|
15497
|
-
* 2. But AsyncStorage persistence happens asynchronously
|
|
15498
|
-
* 3. If AsyncStorage reads an old NULL value, it can OVERWRITE the current auth state
|
|
15499
|
-
* 4. This causes auth.currentUser to become NULL even after it was set
|
|
15500
|
-
*
|
|
15501
|
-
* This method uses onAuthStateChanged to wait for the auth state to be SET and STABLE.
|
|
15502
|
-
* It ensures the auth state persists through AsyncStorage operations.
|
|
15503
|
-
*
|
|
15504
|
-
* @param expectedUid - The UID we expect to see in auth.currentUser
|
|
15505
|
-
* @param timeoutMs - Maximum time to wait (default 5 seconds)
|
|
15506
|
-
* @returns Promise that resolves when auth state is ready and stable
|
|
15491
|
+
* In React Native with AsyncStorage persistence, auth state may not be immediately available.
|
|
15507
15492
|
*/
|
|
15508
15493
|
async waitForAuthStateToSettle(expectedUid, timeoutMs = 5e3) {
|
|
15509
|
-
var _a, _b
|
|
15494
|
+
var _a, _b;
|
|
15510
15495
|
if (((_a = this.auth.currentUser) == null ? void 0 : _a.uid) === expectedUid) {
|
|
15511
|
-
console.log("[AUTH] Auth state appears set, waiting for stability...");
|
|
15512
15496
|
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
15513
15497
|
if (((_b = this.auth.currentUser) == null ? void 0 : _b.uid) === expectedUid) {
|
|
15514
|
-
console.log("[AUTH] \u2705 Auth state stable for:", expectedUid);
|
|
15515
15498
|
return;
|
|
15516
15499
|
}
|
|
15517
15500
|
}
|
|
15518
|
-
console.log("[AUTH] Waiting for auth state to settle for:", expectedUid);
|
|
15519
|
-
console.log("[AUTH] Current auth.currentUser:", ((_c = this.auth.currentUser) == null ? void 0 : _c.uid) || "NULL");
|
|
15520
15501
|
return new Promise((resolve, reject) => {
|
|
15521
15502
|
const startTime = Date.now();
|
|
15522
15503
|
let resolved = false;
|
|
15523
15504
|
const unsubscribe = onAuthStateChanged(this.auth, (user) => {
|
|
15524
15505
|
if (resolved) return;
|
|
15525
15506
|
const currentUid = (user == null ? void 0 : user.uid) || null;
|
|
15526
|
-
console.log("[AUTH] onAuthStateChanged fired:", currentUid || "NULL");
|
|
15527
15507
|
if (currentUid === expectedUid) {
|
|
15528
15508
|
setTimeout(() => {
|
|
15529
15509
|
var _a2;
|
|
@@ -15532,27 +15512,17 @@ ${stackTrace}`);
|
|
|
15532
15512
|
resolved = true;
|
|
15533
15513
|
unsubscribe();
|
|
15534
15514
|
clearTimeout(timeout);
|
|
15535
|
-
const elapsed = Date.now() - startTime;
|
|
15536
|
-
console.log(`[AUTH] \u2705 Auth state settled and stable after ${elapsed}ms for:`, expectedUid);
|
|
15537
15515
|
resolve();
|
|
15538
|
-
} else {
|
|
15539
|
-
console.warn("[AUTH] \u26A0\uFE0F Auth state became NULL after being set, waiting more...");
|
|
15540
15516
|
}
|
|
15541
15517
|
}, 300);
|
|
15542
|
-
} else if (currentUid === null && Date.now() - startTime > 1e3) {
|
|
15543
|
-
console.error("[AUTH] \u274C Auth state became NULL after being set!");
|
|
15544
|
-
console.error("[AUTH] This indicates AsyncStorage persistence issue");
|
|
15545
15518
|
}
|
|
15546
15519
|
});
|
|
15547
15520
|
const timeout = setTimeout(() => {
|
|
15548
|
-
var _a2
|
|
15521
|
+
var _a2;
|
|
15549
15522
|
if (resolved) return;
|
|
15550
15523
|
resolved = true;
|
|
15551
15524
|
unsubscribe();
|
|
15552
|
-
|
|
15553
|
-
console.error("[AUTH] Expected UID:", expectedUid);
|
|
15554
|
-
console.error("[AUTH] Actual auth.currentUser:", ((_a2 = this.auth.currentUser) == null ? void 0 : _a2.uid) || "NULL");
|
|
15555
|
-
reject(new Error(`Timeout waiting for auth state to settle. Expected: ${expectedUid}, Got: ${((_b2 = this.auth.currentUser) == null ? void 0 : _b2.uid) || "NULL"}`));
|
|
15525
|
+
reject(new Error(`Timeout waiting for auth state to settle. Expected: ${expectedUid}, Got: ${((_a2 = this.auth.currentUser) == null ? void 0 : _a2.uid) || "NULL"}`));
|
|
15556
15526
|
}, timeoutMs);
|
|
15557
15527
|
});
|
|
15558
15528
|
}
|
|
@@ -16124,7 +16094,6 @@ ${stackTrace}`);
|
|
|
16124
16094
|
* @returns Object containing user and claimed practitioner
|
|
16125
16095
|
*/
|
|
16126
16096
|
async claimDraftProfilesWithGoogle(idToken, practitionerIds) {
|
|
16127
|
-
var _a, _b;
|
|
16128
16097
|
try {
|
|
16129
16098
|
console.log("[AUTH] Starting claim draft profiles with Google", {
|
|
16130
16099
|
practitionerIdsCount: practitionerIds.length,
|
|
@@ -16133,21 +16102,14 @@ ${stackTrace}`);
|
|
|
16133
16102
|
if (practitionerIds.length === 0) {
|
|
16134
16103
|
throw new AuthError("No practitioner profiles selected to claim", "AUTH/NO_PROFILES_SELECTED", 400);
|
|
16135
16104
|
}
|
|
16136
|
-
console.log("[AUTH] currentUser BEFORE sign-in:", ((_a = this.auth.currentUser) == null ? void 0 : _a.uid) || "NULL");
|
|
16137
|
-
console.log("[AUTH] Signing in with Google credential...");
|
|
16138
16105
|
const credential = GoogleAuthProvider.credential(idToken);
|
|
16139
16106
|
const result = await signInWithCredential(this.auth, credential);
|
|
16140
16107
|
const firebaseUser = result.user;
|
|
16141
|
-
console.log("[AUTH] currentUser IMMEDIATELY AFTER sign-in:", ((_b = this.auth.currentUser) == null ? void 0 : _b.uid) || "NULL");
|
|
16142
|
-
console.log("[AUTH] User returned from signInWithCredential:", firebaseUser.uid);
|
|
16143
16108
|
const practitionerService = new PractitionerService(this.db, this.auth, this.app);
|
|
16144
16109
|
let user;
|
|
16145
16110
|
try {
|
|
16146
16111
|
user = await this.userService.getUserById(firebaseUser.uid);
|
|
16147
|
-
console.log("[AUTH] User document found:", user.uid);
|
|
16148
16112
|
} catch (userError) {
|
|
16149
|
-
console.error("[AUTH] \u274C User document should already exist! It should have been created in signUpPractitionerWithGoogle.");
|
|
16150
|
-
console.error("[AUTH] This indicates a bug - User doc creation failed in the initial Google sign-in flow.");
|
|
16151
16113
|
throw new AuthError(
|
|
16152
16114
|
"User account not properly initialized. Please try signing in again.",
|
|
16153
16115
|
"AUTH/USER_NOT_INITIALIZED",
|
|
@@ -16156,30 +16118,22 @@ ${stackTrace}`);
|
|
|
16156
16118
|
}
|
|
16157
16119
|
let practitioner;
|
|
16158
16120
|
if (practitionerIds.length === 1) {
|
|
16159
|
-
console.log("[AUTH] Claiming single draft profile:", practitionerIds[0]);
|
|
16160
16121
|
practitioner = await practitionerService.claimDraftProfileWithGoogle(
|
|
16161
16122
|
practitionerIds[0],
|
|
16162
16123
|
firebaseUser.uid
|
|
16163
16124
|
);
|
|
16164
16125
|
} else {
|
|
16165
|
-
console.log("[AUTH] Claiming multiple draft profiles:", practitionerIds);
|
|
16166
16126
|
practitioner = await practitionerService.claimMultipleDraftProfilesWithGoogle(
|
|
16167
16127
|
practitionerIds,
|
|
16168
16128
|
firebaseUser.uid
|
|
16169
16129
|
);
|
|
16170
16130
|
}
|
|
16171
|
-
console.log("[AUTH] Draft profiles claimed:", practitioner.id);
|
|
16172
16131
|
if (!user.practitionerProfile || user.practitionerProfile !== practitioner.id) {
|
|
16173
|
-
console.log("[AUTH] Linking practitioner to user");
|
|
16174
16132
|
await this.userService.updateUser(firebaseUser.uid, {
|
|
16175
16133
|
practitionerProfile: practitioner.id
|
|
16176
16134
|
});
|
|
16177
16135
|
}
|
|
16178
16136
|
const updatedUser = await this.userService.getUserById(firebaseUser.uid);
|
|
16179
|
-
console.log("[AUTH] Draft profiles claimed successfully", {
|
|
16180
|
-
userId: updatedUser.uid,
|
|
16181
|
-
practitionerId: practitioner.id
|
|
16182
|
-
});
|
|
16183
16137
|
return {
|
|
16184
16138
|
user: updatedUser,
|
|
16185
16139
|
practitioner
|
|
@@ -16308,9 +16262,6 @@ ${stackTrace}`);
|
|
|
16308
16262
|
const credential = GoogleAuthProvider.credential(idToken);
|
|
16309
16263
|
const { user: firebaseUser } = await signInWithCredential(this.auth, credential);
|
|
16310
16264
|
console.log("[AUTH] Firebase user signed in:", firebaseUser.uid);
|
|
16311
|
-
console.log("[AUTH] Waiting for auth state to settle after sign-in...");
|
|
16312
|
-
await this.waitForAuthStateToSettle(firebaseUser.uid);
|
|
16313
|
-
console.log("[AUTH] \u2705 Auth state settled, proceeding with Firestore queries");
|
|
16314
16265
|
const existingUser = await this.userService.getUserById(firebaseUser.uid);
|
|
16315
16266
|
if (existingUser) {
|
|
16316
16267
|
console.log("[AUTH] Existing user found, returning profile:", existingUser.uid);
|
|
@@ -16336,7 +16287,6 @@ ${stackTrace}`);
|
|
|
16336
16287
|
* @returns Object containing user, practitioner (if exists), and draft profiles (if any)
|
|
16337
16288
|
*/
|
|
16338
16289
|
async signUpPractitionerWithGoogle(idToken) {
|
|
16339
|
-
var _a, _b, _c, _d;
|
|
16340
16290
|
try {
|
|
16341
16291
|
console.log("[AUTH] Starting practitioner Google Sign-In/Sign-Up");
|
|
16342
16292
|
let email;
|
|
@@ -16361,52 +16311,30 @@ ${stackTrace}`);
|
|
|
16361
16311
|
);
|
|
16362
16312
|
}
|
|
16363
16313
|
const normalizedEmail = email.toLowerCase().trim();
|
|
16364
|
-
console.log("[AUTH] Extracted email from Google token:", normalizedEmail);
|
|
16365
16314
|
const methods = await fetchSignInMethodsForEmail2(this.auth, normalizedEmail);
|
|
16366
16315
|
const hasGoogleMethod = methods.includes(GoogleAuthProvider.GOOGLE_SIGN_IN_METHOD);
|
|
16367
16316
|
const hasEmailMethod = methods.includes(EmailAuthProvider.EMAIL_PASSWORD_SIGN_IN_METHOD);
|
|
16368
16317
|
const practitionerService = new PractitionerService(this.db, this.auth, this.app);
|
|
16369
16318
|
if (hasGoogleMethod) {
|
|
16370
|
-
console.log("[AUTH] User exists with Google provider, signing in");
|
|
16371
16319
|
const credential2 = GoogleAuthProvider.credential(idToken);
|
|
16372
16320
|
const { user: firebaseUser2 } = await signInWithCredential(this.auth, credential2);
|
|
16373
|
-
console.log("[AUTH] Waiting for auth state to settle after sign-in...");
|
|
16374
16321
|
await this.waitForAuthStateToSettle(firebaseUser2.uid);
|
|
16375
|
-
console.log("[AUTH] \u2705 Auth state settled, proceeding with Firestore queries");
|
|
16376
16322
|
let existingUser2 = null;
|
|
16377
16323
|
try {
|
|
16378
16324
|
existingUser2 = await this.userService.getUserById(firebaseUser2.uid);
|
|
16379
|
-
console.log("[AUTH] User document found:", existingUser2.uid);
|
|
16380
16325
|
} catch (userError) {
|
|
16381
|
-
console.log("[AUTH] User document not found in Firestore, checking for draft profiles", {
|
|
16382
|
-
errorCode: userError == null ? void 0 : userError.code,
|
|
16383
|
-
errorMessage: userError == null ? void 0 : userError.message,
|
|
16384
|
-
errorType: (_a = userError == null ? void 0 : userError.constructor) == null ? void 0 : _a.name,
|
|
16385
|
-
isAuthError: userError instanceof AuthError
|
|
16386
|
-
});
|
|
16387
16326
|
if (!this.auth.currentUser || this.auth.currentUser.uid !== firebaseUser2.uid) {
|
|
16388
|
-
console.error("[AUTH] \u274C auth.currentUser became NULL before draft profile query!");
|
|
16389
|
-
console.error("[AUTH] Expected UID:", firebaseUser2.uid);
|
|
16390
|
-
console.error("[AUTH] Actual auth.currentUser:", ((_b = this.auth.currentUser) == null ? void 0 : _b.uid) || "NULL");
|
|
16391
|
-
console.log("[AUTH] Re-signing in to restore auth state before query...");
|
|
16392
16327
|
const credential3 = GoogleAuthProvider.credential(idToken);
|
|
16393
16328
|
await signInWithCredential(this.auth, credential3);
|
|
16394
16329
|
await this.waitForAuthStateToSettle(firebaseUser2.uid, 2e3);
|
|
16395
|
-
console.log("[AUTH] \u2705 Auth state restored, proceeding with query");
|
|
16396
16330
|
}
|
|
16397
16331
|
const practitionerService2 = new PractitionerService(this.db, this.auth, this.app);
|
|
16398
16332
|
const draftProfiles3 = await practitionerService2.getDraftProfilesByEmail(normalizedEmail);
|
|
16399
|
-
console.log("[AUTH] Draft profiles check result:", {
|
|
16400
|
-
email: normalizedEmail,
|
|
16401
|
-
draftProfilesCount: draftProfiles3.length,
|
|
16402
|
-
draftProfileIds: draftProfiles3.map((p) => p.id)
|
|
16403
|
-
});
|
|
16404
16333
|
if (draftProfiles3.length === 0) {
|
|
16405
|
-
console.log("[AUTH] No draft profiles found, signing out and throwing error");
|
|
16406
16334
|
try {
|
|
16407
16335
|
await firebaseSignOut(this.auth);
|
|
16408
16336
|
} catch (signOutError) {
|
|
16409
|
-
console.warn("[AUTH] Error signing out
|
|
16337
|
+
console.warn("[AUTH] Error signing out:", signOutError);
|
|
16410
16338
|
}
|
|
16411
16339
|
throw new AuthError(
|
|
16412
16340
|
"No clinic invitation found for this email. Please contact your clinic administrator to receive an invitation, or use the token provided by your clinic.",
|
|
@@ -16414,28 +16342,20 @@ ${stackTrace}`);
|
|
|
16414
16342
|
404
|
|
16415
16343
|
);
|
|
16416
16344
|
}
|
|
16417
|
-
console.log("[AUTH] Draft profiles found, creating User document IMMEDIATELY after sign-in");
|
|
16418
|
-
console.log("[AUTH] auth.currentUser at User creation time:", ((_c = this.auth.currentUser) == null ? void 0 : _c.uid) || "NULL");
|
|
16419
16345
|
try {
|
|
16420
16346
|
const newUser = await this.userService.createUser(firebaseUser2, ["practitioner" /* PRACTITIONER */], {
|
|
16421
16347
|
skipProfileCreation: true
|
|
16422
16348
|
});
|
|
16423
|
-
console.log("[AUTH] \u2705 User document created successfully:", newUser.uid);
|
|
16424
16349
|
return {
|
|
16425
16350
|
user: newUser,
|
|
16426
16351
|
practitioner: null,
|
|
16427
16352
|
draftProfiles: draftProfiles3
|
|
16428
16353
|
};
|
|
16429
16354
|
} catch (createUserError) {
|
|
16430
|
-
console.error("[AUTH] \u274C Failed to create User document:", {
|
|
16431
|
-
errorCode: createUserError == null ? void 0 : createUserError.code,
|
|
16432
|
-
errorMessage: createUserError == null ? void 0 : createUserError.message,
|
|
16433
|
-
uid: firebaseUser2.uid
|
|
16434
|
-
});
|
|
16435
16355
|
try {
|
|
16436
16356
|
await firebaseSignOut(this.auth);
|
|
16437
16357
|
} catch (signOutError) {
|
|
16438
|
-
console.warn("[AUTH] Error signing out
|
|
16358
|
+
console.warn("[AUTH] Error signing out:", signOutError);
|
|
16439
16359
|
}
|
|
16440
16360
|
throw createUserError;
|
|
16441
16361
|
}
|
|
@@ -16460,14 +16380,12 @@ ${stackTrace}`);
|
|
|
16460
16380
|
};
|
|
16461
16381
|
}
|
|
16462
16382
|
if (hasEmailMethod && !hasGoogleMethod) {
|
|
16463
|
-
console.log("[AUTH] User exists with email/password only");
|
|
16464
16383
|
throw new AuthError(
|
|
16465
16384
|
"An account with this email already exists. Please sign in with your email and password, then link your Google account in settings.",
|
|
16466
16385
|
"AUTH/EMAIL_ALREADY_EXISTS",
|
|
16467
16386
|
409
|
|
16468
16387
|
);
|
|
16469
16388
|
}
|
|
16470
|
-
console.log("[AUTH] Signing in with Google credential");
|
|
16471
16389
|
const credential = GoogleAuthProvider.credential(idToken);
|
|
16472
16390
|
let firebaseUser;
|
|
16473
16391
|
try {
|
|
@@ -16483,30 +16401,23 @@ ${stackTrace}`);
|
|
|
16483
16401
|
}
|
|
16484
16402
|
throw error;
|
|
16485
16403
|
}
|
|
16486
|
-
console.log("[AUTH] Waiting for auth state to settle after sign-in...");
|
|
16487
16404
|
await this.waitForAuthStateToSettle(firebaseUser.uid);
|
|
16488
|
-
console.log("[AUTH] \u2705 Auth state settled, proceeding with Firestore queries");
|
|
16489
16405
|
let existingUser = null;
|
|
16490
16406
|
try {
|
|
16491
16407
|
const existingUserDoc = await this.userService.getUserById(firebaseUser.uid);
|
|
16492
16408
|
if (existingUserDoc) {
|
|
16493
16409
|
existingUser = existingUserDoc;
|
|
16494
|
-
console.log("[AUTH] Found existing User document");
|
|
16495
16410
|
}
|
|
16496
16411
|
} catch (error) {
|
|
16497
|
-
console.error("[AUTH] Error checking for existing user:", error);
|
|
16498
16412
|
}
|
|
16499
|
-
console.log("[AUTH] Checking for draft profiles");
|
|
16500
16413
|
let draftProfiles = [];
|
|
16501
16414
|
try {
|
|
16502
16415
|
draftProfiles = await practitionerService.getDraftProfilesByEmail(normalizedEmail);
|
|
16503
|
-
console.log("[AUTH] Draft profiles check complete", { count: draftProfiles.length });
|
|
16504
16416
|
} catch (draftCheckError) {
|
|
16505
|
-
console.error("[AUTH] Error checking draft profiles:", draftCheckError);
|
|
16506
16417
|
try {
|
|
16507
16418
|
await firebaseSignOut(this.auth);
|
|
16508
16419
|
} catch (signOutError) {
|
|
16509
|
-
console.warn("[AUTH] Error signing out
|
|
16420
|
+
console.warn("[AUTH] Error signing out:", signOutError);
|
|
16510
16421
|
}
|
|
16511
16422
|
throw new AuthError(
|
|
16512
16423
|
"No clinic invitation found for this email. Please contact your clinic administrator to receive an invitation, or use the token provided by your clinic.",
|
|
@@ -16517,55 +16428,38 @@ ${stackTrace}`);
|
|
|
16517
16428
|
let user;
|
|
16518
16429
|
if (existingUser) {
|
|
16519
16430
|
user = existingUser;
|
|
16520
|
-
console.log("[AUTH] Using existing user account");
|
|
16521
16431
|
} else {
|
|
16522
16432
|
if (draftProfiles.length === 0) {
|
|
16523
|
-
console.log("[AUTH] No draft profiles found, signing out and throwing error");
|
|
16524
16433
|
try {
|
|
16525
16434
|
await firebaseSignOut(this.auth);
|
|
16526
16435
|
} catch (signOutError) {
|
|
16527
|
-
console.warn("[AUTH] Error signing out
|
|
16436
|
+
console.warn("[AUTH] Error signing out:", signOutError);
|
|
16528
16437
|
}
|
|
16529
|
-
|
|
16438
|
+
throw new AuthError(
|
|
16530
16439
|
"No clinic invitation found for this email. Please contact your clinic administrator to receive an invitation, or use the token provided by your clinic.",
|
|
16531
16440
|
"AUTH/NO_DRAFT_PROFILES",
|
|
16532
16441
|
404
|
|
16533
16442
|
);
|
|
16534
|
-
console.log("[AUTH] Throwing NO_DRAFT_PROFILES error:", noDraftError.code);
|
|
16535
|
-
throw noDraftError;
|
|
16536
16443
|
}
|
|
16537
16444
|
user = await this.userService.createUser(firebaseUser, ["practitioner" /* PRACTITIONER */], {
|
|
16538
16445
|
skipProfileCreation: true
|
|
16539
16446
|
});
|
|
16540
|
-
console.log("[AUTH] Created new user account with draft profiles available");
|
|
16541
16447
|
}
|
|
16542
16448
|
let practitioner = null;
|
|
16543
16449
|
if (user.practitionerProfile) {
|
|
16544
16450
|
practitioner = await practitionerService.getPractitioner(user.practitionerProfile);
|
|
16545
16451
|
}
|
|
16546
|
-
console.log("[AUTH] Google Sign-In complete", {
|
|
16547
|
-
userId: user.uid,
|
|
16548
|
-
hasPractitioner: !!practitioner,
|
|
16549
|
-
draftProfilesCount: draftProfiles.length
|
|
16550
|
-
});
|
|
16551
16452
|
return {
|
|
16552
16453
|
user,
|
|
16553
16454
|
practitioner,
|
|
16554
16455
|
draftProfiles
|
|
16555
16456
|
};
|
|
16556
16457
|
} catch (error) {
|
|
16557
|
-
console.error("[AUTH] Error in signUpPractitionerWithGoogle:", error);
|
|
16558
|
-
console.error("[AUTH] Error type:", (_d = error == null ? void 0 : error.constructor) == null ? void 0 : _d.name);
|
|
16559
|
-
console.error("[AUTH] Error instanceof AuthError:", error instanceof AuthError);
|
|
16560
|
-
console.error("[AUTH] Error code:", error == null ? void 0 : error.code);
|
|
16561
|
-
console.error("[AUTH] Error message:", error == null ? void 0 : error.message);
|
|
16562
16458
|
if (error instanceof AuthError) {
|
|
16563
|
-
console.log("[AUTH] Preserving AuthError:", error.code);
|
|
16564
16459
|
throw error;
|
|
16565
16460
|
}
|
|
16566
16461
|
const errorMessage = (error == null ? void 0 : error.message) || (error == null ? void 0 : error.toString()) || "";
|
|
16567
16462
|
if (errorMessage.includes("NO_DRAFT_PROFILES") || errorMessage.includes("clinic invitation")) {
|
|
16568
|
-
console.log("[AUTH] Detected clinic invitation error in message, converting to AuthError");
|
|
16569
16463
|
throw new AuthError(
|
|
16570
16464
|
"No clinic invitation found for this email. Please contact your clinic administrator to receive an invitation, or use the token provided by your clinic.",
|
|
16571
16465
|
"AUTH/NO_DRAFT_PROFILES",
|
|
@@ -16573,7 +16467,6 @@ ${stackTrace}`);
|
|
|
16573
16467
|
);
|
|
16574
16468
|
}
|
|
16575
16469
|
const wrappedError = handleFirebaseError(error);
|
|
16576
|
-
console.log("[AUTH] Wrapped error:", wrappedError.message);
|
|
16577
16470
|
if (wrappedError.message.includes("permissions") || wrappedError.message.includes("Account creation failed")) {
|
|
16578
16471
|
throw new AuthError(
|
|
16579
16472
|
"No clinic invitation found for this email. Please contact your clinic administrator to receive an invitation, or use the token provided by your clinic.",
|
|
@@ -16620,7 +16513,7 @@ ${stackTrace}`);
|
|
|
16620
16513
|
};
|
|
16621
16514
|
|
|
16622
16515
|
// src/services/calendar/calendar.v2.service.ts
|
|
16623
|
-
import { Timestamp as Timestamp29, serverTimestamp as
|
|
16516
|
+
import { Timestamp as Timestamp29, serverTimestamp as serverTimestamp26 } from "firebase/firestore";
|
|
16624
16517
|
import {
|
|
16625
16518
|
doc as doc32,
|
|
16626
16519
|
getDoc as getDoc33,
|
|
@@ -16645,7 +16538,7 @@ import {
|
|
|
16645
16538
|
where as where22,
|
|
16646
16539
|
orderBy as orderBy8,
|
|
16647
16540
|
Timestamp as Timestamp23,
|
|
16648
|
-
serverTimestamp as
|
|
16541
|
+
serverTimestamp as serverTimestamp21
|
|
16649
16542
|
} from "firebase/firestore";
|
|
16650
16543
|
|
|
16651
16544
|
// src/services/calendar/utils/docs.utils.ts
|
|
@@ -16694,8 +16587,8 @@ async function createClinicCalendarEventUtil(db, clinicId, eventData, generateId
|
|
|
16694
16587
|
const newEvent = {
|
|
16695
16588
|
id: eventId,
|
|
16696
16589
|
...eventData,
|
|
16697
|
-
createdAt:
|
|
16698
|
-
updatedAt:
|
|
16590
|
+
createdAt: serverTimestamp21(),
|
|
16591
|
+
updatedAt: serverTimestamp21()
|
|
16699
16592
|
};
|
|
16700
16593
|
await setDoc17(eventRef, newEvent);
|
|
16701
16594
|
return {
|
|
@@ -16708,7 +16601,7 @@ async function updateClinicCalendarEventUtil(db, clinicId, eventId, updateData)
|
|
|
16708
16601
|
const eventRef = getClinicCalendarEventDocRef(db, clinicId, eventId);
|
|
16709
16602
|
const updates = {
|
|
16710
16603
|
...updateData,
|
|
16711
|
-
updatedAt:
|
|
16604
|
+
updatedAt: serverTimestamp21()
|
|
16712
16605
|
};
|
|
16713
16606
|
await updateDoc22(eventRef, updates);
|
|
16714
16607
|
const updatedDoc = await getDoc28(eventRef);
|
|
@@ -16749,7 +16642,7 @@ import {
|
|
|
16749
16642
|
where as where23,
|
|
16750
16643
|
orderBy as orderBy9,
|
|
16751
16644
|
Timestamp as Timestamp24,
|
|
16752
|
-
serverTimestamp as
|
|
16645
|
+
serverTimestamp as serverTimestamp22
|
|
16753
16646
|
} from "firebase/firestore";
|
|
16754
16647
|
async function createPatientCalendarEventUtil(db, patientId, eventData, generateId2) {
|
|
16755
16648
|
const eventId = generateId2();
|
|
@@ -16757,8 +16650,8 @@ async function createPatientCalendarEventUtil(db, patientId, eventData, generate
|
|
|
16757
16650
|
const newEvent = {
|
|
16758
16651
|
id: eventId,
|
|
16759
16652
|
...eventData,
|
|
16760
|
-
createdAt:
|
|
16761
|
-
updatedAt:
|
|
16653
|
+
createdAt: serverTimestamp22(),
|
|
16654
|
+
updatedAt: serverTimestamp22()
|
|
16762
16655
|
};
|
|
16763
16656
|
await setDoc18(eventRef, newEvent);
|
|
16764
16657
|
return {
|
|
@@ -16771,7 +16664,7 @@ async function updatePatientCalendarEventUtil(db, patientId, eventId, updateData
|
|
|
16771
16664
|
const eventRef = getPatientCalendarEventDocRef(db, patientId, eventId);
|
|
16772
16665
|
const updates = {
|
|
16773
16666
|
...updateData,
|
|
16774
|
-
updatedAt:
|
|
16667
|
+
updatedAt: serverTimestamp22()
|
|
16775
16668
|
};
|
|
16776
16669
|
await updateDoc23(eventRef, updates);
|
|
16777
16670
|
const updatedDoc = await getDoc29(eventRef);
|
|
@@ -16793,7 +16686,7 @@ import {
|
|
|
16793
16686
|
where as where24,
|
|
16794
16687
|
orderBy as orderBy10,
|
|
16795
16688
|
Timestamp as Timestamp25,
|
|
16796
|
-
serverTimestamp as
|
|
16689
|
+
serverTimestamp as serverTimestamp23
|
|
16797
16690
|
} from "firebase/firestore";
|
|
16798
16691
|
async function createPractitionerCalendarEventUtil(db, practitionerId, eventData, generateId2) {
|
|
16799
16692
|
const eventId = generateId2();
|
|
@@ -16805,8 +16698,8 @@ async function createPractitionerCalendarEventUtil(db, practitionerId, eventData
|
|
|
16805
16698
|
const newEvent = {
|
|
16806
16699
|
id: eventId,
|
|
16807
16700
|
...eventData,
|
|
16808
|
-
createdAt:
|
|
16809
|
-
updatedAt:
|
|
16701
|
+
createdAt: serverTimestamp23(),
|
|
16702
|
+
updatedAt: serverTimestamp23()
|
|
16810
16703
|
};
|
|
16811
16704
|
await setDoc19(eventRef, newEvent);
|
|
16812
16705
|
return {
|
|
@@ -16823,7 +16716,7 @@ async function updatePractitionerCalendarEventUtil(db, practitionerId, eventId,
|
|
|
16823
16716
|
);
|
|
16824
16717
|
const updates = {
|
|
16825
16718
|
...updateData,
|
|
16826
|
-
updatedAt:
|
|
16719
|
+
updatedAt: serverTimestamp23()
|
|
16827
16720
|
};
|
|
16828
16721
|
await updateDoc24(eventRef, updates);
|
|
16829
16722
|
const updatedDoc = await getDoc30(eventRef);
|
|
@@ -16896,7 +16789,7 @@ import {
|
|
|
16896
16789
|
where as where25,
|
|
16897
16790
|
orderBy as orderBy11,
|
|
16898
16791
|
Timestamp as Timestamp26,
|
|
16899
|
-
serverTimestamp as
|
|
16792
|
+
serverTimestamp as serverTimestamp24
|
|
16900
16793
|
} from "firebase/firestore";
|
|
16901
16794
|
async function searchCalendarEventsUtil(db, params) {
|
|
16902
16795
|
const { searchLocation, entityId, ...filters } = params;
|
|
@@ -17001,7 +16894,7 @@ import {
|
|
|
17001
16894
|
query as query26,
|
|
17002
16895
|
orderBy as orderBy12,
|
|
17003
16896
|
Timestamp as Timestamp27,
|
|
17004
|
-
serverTimestamp as
|
|
16897
|
+
serverTimestamp as serverTimestamp25
|
|
17005
16898
|
} from "firebase/firestore";
|
|
17006
16899
|
async function createPractitionerSyncedCalendarUtil(db, practitionerId, calendarData, generateId2) {
|
|
17007
16900
|
const calendarId = generateId2();
|
|
@@ -17013,8 +16906,8 @@ async function createPractitionerSyncedCalendarUtil(db, practitionerId, calendar
|
|
|
17013
16906
|
const newCalendar = {
|
|
17014
16907
|
id: calendarId,
|
|
17015
16908
|
...calendarData,
|
|
17016
|
-
createdAt:
|
|
17017
|
-
updatedAt:
|
|
16909
|
+
createdAt: serverTimestamp25(),
|
|
16910
|
+
updatedAt: serverTimestamp25()
|
|
17018
16911
|
};
|
|
17019
16912
|
await setDoc21(calendarRef, newCalendar);
|
|
17020
16913
|
return {
|
|
@@ -17029,8 +16922,8 @@ async function createPatientSyncedCalendarUtil(db, patientId, calendarData, gene
|
|
|
17029
16922
|
const newCalendar = {
|
|
17030
16923
|
id: calendarId,
|
|
17031
16924
|
...calendarData,
|
|
17032
|
-
createdAt:
|
|
17033
|
-
updatedAt:
|
|
16925
|
+
createdAt: serverTimestamp25(),
|
|
16926
|
+
updatedAt: serverTimestamp25()
|
|
17034
16927
|
};
|
|
17035
16928
|
await setDoc21(calendarRef, newCalendar);
|
|
17036
16929
|
return {
|
|
@@ -17045,8 +16938,8 @@ async function createClinicSyncedCalendarUtil(db, clinicId, calendarData, genera
|
|
|
17045
16938
|
const newCalendar = {
|
|
17046
16939
|
id: calendarId,
|
|
17047
16940
|
...calendarData,
|
|
17048
|
-
createdAt:
|
|
17049
|
-
updatedAt:
|
|
16941
|
+
createdAt: serverTimestamp25(),
|
|
16942
|
+
updatedAt: serverTimestamp25()
|
|
17050
16943
|
};
|
|
17051
16944
|
await setDoc21(calendarRef, newCalendar);
|
|
17052
16945
|
return {
|
|
@@ -17118,7 +17011,7 @@ async function updatePractitionerSyncedCalendarUtil(db, practitionerId, calendar
|
|
|
17118
17011
|
);
|
|
17119
17012
|
const updates = {
|
|
17120
17013
|
...updateData,
|
|
17121
|
-
updatedAt:
|
|
17014
|
+
updatedAt: serverTimestamp25()
|
|
17122
17015
|
};
|
|
17123
17016
|
await updateDoc26(calendarRef, updates);
|
|
17124
17017
|
const updatedDoc = await getDoc32(calendarRef);
|
|
@@ -17131,7 +17024,7 @@ async function updatePatientSyncedCalendarUtil(db, patientId, calendarId, update
|
|
|
17131
17024
|
const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
|
|
17132
17025
|
const updates = {
|
|
17133
17026
|
...updateData,
|
|
17134
|
-
updatedAt:
|
|
17027
|
+
updatedAt: serverTimestamp25()
|
|
17135
17028
|
};
|
|
17136
17029
|
await updateDoc26(calendarRef, updates);
|
|
17137
17030
|
const updatedDoc = await getDoc32(calendarRef);
|
|
@@ -17144,7 +17037,7 @@ async function updateClinicSyncedCalendarUtil(db, clinicId, calendarId, updateDa
|
|
|
17144
17037
|
const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
|
|
17145
17038
|
const updates = {
|
|
17146
17039
|
...updateData,
|
|
17147
|
-
updatedAt:
|
|
17040
|
+
updatedAt: serverTimestamp25()
|
|
17148
17041
|
};
|
|
17149
17042
|
await updateDoc26(calendarRef, updates);
|
|
17150
17043
|
const updatedDoc = await getDoc32(calendarRef);
|
|
@@ -18366,8 +18259,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
18366
18259
|
const newEvent = {
|
|
18367
18260
|
id: eventId,
|
|
18368
18261
|
...eventData,
|
|
18369
|
-
createdAt:
|
|
18370
|
-
updatedAt:
|
|
18262
|
+
createdAt: serverTimestamp26(),
|
|
18263
|
+
updatedAt: serverTimestamp26()
|
|
18371
18264
|
};
|
|
18372
18265
|
await setDoc22(eventRef, newEvent);
|
|
18373
18266
|
return {
|
|
@@ -18583,7 +18476,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
18583
18476
|
end: Timestamp29.fromDate(endTime)
|
|
18584
18477
|
},
|
|
18585
18478
|
description: externalEvent.description || "",
|
|
18586
|
-
updatedAt:
|
|
18479
|
+
updatedAt: serverTimestamp26()
|
|
18587
18480
|
});
|
|
18588
18481
|
console.log(`Updated local event ${eventId} from external event`);
|
|
18589
18482
|
} catch (error) {
|
|
@@ -18610,7 +18503,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
18610
18503
|
);
|
|
18611
18504
|
await updateDoc27(eventRef, {
|
|
18612
18505
|
status,
|
|
18613
|
-
updatedAt:
|
|
18506
|
+
updatedAt: serverTimestamp26()
|
|
18614
18507
|
});
|
|
18615
18508
|
console.log(`Updated event ${eventId} status to ${status}`);
|
|
18616
18509
|
} catch (error) {
|
|
@@ -19011,7 +18904,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
19011
18904
|
}
|
|
19012
18905
|
await updateDoc27(eventRef, {
|
|
19013
18906
|
syncedCalendarEventId: syncIds,
|
|
19014
|
-
updatedAt:
|
|
18907
|
+
updatedAt: serverTimestamp26()
|
|
19015
18908
|
});
|
|
19016
18909
|
console.log(
|
|
19017
18910
|
`Updated event ${eventId} with sync ID ${syncEvent.eventId}`
|
|
@@ -19234,7 +19127,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
19234
19127
|
};
|
|
19235
19128
|
|
|
19236
19129
|
// src/services/calendar/calendar.v3.service.ts
|
|
19237
|
-
import { Timestamp as Timestamp30, serverTimestamp as
|
|
19130
|
+
import { Timestamp as Timestamp30, serverTimestamp as serverTimestamp27 } from "firebase/firestore";
|
|
19238
19131
|
import { doc as doc33, getDoc as getDoc34, setDoc as setDoc23, updateDoc as updateDoc28, deleteDoc as deleteDoc15 } from "firebase/firestore";
|
|
19239
19132
|
var CalendarServiceV3 = class extends BaseService {
|
|
19240
19133
|
/**
|
|
@@ -19269,8 +19162,8 @@ var CalendarServiceV3 = class extends BaseService {
|
|
|
19269
19162
|
status: "confirmed" /* CONFIRMED */,
|
|
19270
19163
|
// Blocking events are always confirmed
|
|
19271
19164
|
syncStatus: "internal" /* INTERNAL */,
|
|
19272
|
-
createdAt:
|
|
19273
|
-
updatedAt:
|
|
19165
|
+
createdAt: serverTimestamp27(),
|
|
19166
|
+
updatedAt: serverTimestamp27()
|
|
19274
19167
|
};
|
|
19275
19168
|
if (params.entityType === "practitioner") {
|
|
19276
19169
|
eventData.practitionerProfileId = params.entityId;
|
|
@@ -19300,7 +19193,7 @@ var CalendarServiceV3 = class extends BaseService {
|
|
|
19300
19193
|
throw new Error(`Blocking event with ID ${params.eventId} not found`);
|
|
19301
19194
|
}
|
|
19302
19195
|
const updateData = {
|
|
19303
|
-
updatedAt:
|
|
19196
|
+
updatedAt: serverTimestamp27()
|
|
19304
19197
|
};
|
|
19305
19198
|
if (params.eventName !== void 0) {
|
|
19306
19199
|
updateData.eventName = params.eventName;
|
|
@@ -19547,7 +19440,7 @@ import {
|
|
|
19547
19440
|
setDoc as setDoc24,
|
|
19548
19441
|
deleteDoc as deleteDoc16,
|
|
19549
19442
|
Timestamp as Timestamp31,
|
|
19550
|
-
serverTimestamp as
|
|
19443
|
+
serverTimestamp as serverTimestamp28,
|
|
19551
19444
|
orderBy as orderBy13,
|
|
19552
19445
|
limit as limit12
|
|
19553
19446
|
} from "firebase/firestore";
|
|
@@ -19709,7 +19602,7 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
19709
19602
|
const updateData = {
|
|
19710
19603
|
status: "accepted" /* ACCEPTED */,
|
|
19711
19604
|
acceptedAt: Timestamp31.now(),
|
|
19712
|
-
updatedAt:
|
|
19605
|
+
updatedAt: serverTimestamp28()
|
|
19713
19606
|
};
|
|
19714
19607
|
const docRef = doc34(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
19715
19608
|
await updateDoc29(docRef, updateData);
|
|
@@ -19741,7 +19634,7 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
19741
19634
|
status: "rejected" /* REJECTED */,
|
|
19742
19635
|
rejectionReason: rejectionReason || null,
|
|
19743
19636
|
rejectedAt: Timestamp31.now(),
|
|
19744
|
-
updatedAt:
|
|
19637
|
+
updatedAt: serverTimestamp28()
|
|
19745
19638
|
};
|
|
19746
19639
|
const docRef = doc34(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
19747
19640
|
await updateDoc29(docRef, updateData);
|
|
@@ -19773,7 +19666,7 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
19773
19666
|
status: "cancelled" /* CANCELLED */,
|
|
19774
19667
|
cancelReason: cancelReason || null,
|
|
19775
19668
|
cancelledAt: Timestamp31.now(),
|
|
19776
|
-
updatedAt:
|
|
19669
|
+
updatedAt: serverTimestamp28()
|
|
19777
19670
|
};
|
|
19778
19671
|
const docRef = doc34(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
19779
19672
|
await updateDoc29(docRef, updateData);
|
|
@@ -21047,7 +20940,7 @@ import {
|
|
|
21047
20940
|
updateDoc as updateDoc34,
|
|
21048
20941
|
setDoc as setDoc27,
|
|
21049
20942
|
deleteDoc as deleteDoc19,
|
|
21050
|
-
serverTimestamp as
|
|
20943
|
+
serverTimestamp as serverTimestamp31,
|
|
21051
20944
|
writeBatch as writeBatch6,
|
|
21052
20945
|
orderBy as orderBy18,
|
|
21053
20946
|
limit as limit16,
|
|
@@ -21533,8 +21426,8 @@ var ProcedureService = class extends BaseService {
|
|
|
21533
21426
|
const procedureRef = doc39(this.db, PROCEDURES_COLLECTION, procedureId);
|
|
21534
21427
|
await setDoc27(procedureRef, {
|
|
21535
21428
|
...newProcedure,
|
|
21536
|
-
createdAt:
|
|
21537
|
-
updatedAt:
|
|
21429
|
+
createdAt: serverTimestamp31(),
|
|
21430
|
+
updatedAt: serverTimestamp31()
|
|
21538
21431
|
});
|
|
21539
21432
|
const savedDoc = await getDoc40(procedureRef);
|
|
21540
21433
|
return savedDoc.data();
|
|
@@ -21661,8 +21554,8 @@ var ProcedureService = class extends BaseService {
|
|
|
21661
21554
|
const procedureRef = doc39(this.db, PROCEDURES_COLLECTION, newProcedureId);
|
|
21662
21555
|
await setDoc27(procedureRef, {
|
|
21663
21556
|
...newProcedure,
|
|
21664
|
-
createdAt:
|
|
21665
|
-
updatedAt:
|
|
21557
|
+
createdAt: serverTimestamp31(),
|
|
21558
|
+
updatedAt: serverTimestamp31()
|
|
21666
21559
|
});
|
|
21667
21560
|
const savedDoc = await getDoc40(procedureRef);
|
|
21668
21561
|
return savedDoc.data();
|
|
@@ -21763,8 +21656,8 @@ var ProcedureService = class extends BaseService {
|
|
|
21763
21656
|
const procedureRef = doc39(this.db, PROCEDURES_COLLECTION, newProcedureId);
|
|
21764
21657
|
batch.set(procedureRef, {
|
|
21765
21658
|
...newProcedure,
|
|
21766
|
-
createdAt:
|
|
21767
|
-
updatedAt:
|
|
21659
|
+
createdAt: serverTimestamp31(),
|
|
21660
|
+
updatedAt: serverTimestamp31()
|
|
21768
21661
|
});
|
|
21769
21662
|
}
|
|
21770
21663
|
await batch.commit();
|
|
@@ -21968,8 +21861,8 @@ var ProcedureService = class extends BaseService {
|
|
|
21968
21861
|
console.log("\u{1F525}\u{1F525}\u{1F525} NO UNDEFINED FIELDS - Proceeding with batch.set");
|
|
21969
21862
|
batch.set(procedureRef, {
|
|
21970
21863
|
...newProcedure,
|
|
21971
|
-
createdAt:
|
|
21972
|
-
updatedAt:
|
|
21864
|
+
createdAt: serverTimestamp31(),
|
|
21865
|
+
updatedAt: serverTimestamp31()
|
|
21973
21866
|
});
|
|
21974
21867
|
}
|
|
21975
21868
|
await batch.commit();
|
|
@@ -22203,7 +22096,7 @@ var ProcedureService = class extends BaseService {
|
|
|
22203
22096
|
}
|
|
22204
22097
|
await updateDoc34(procedureRef, {
|
|
22205
22098
|
...updatedProcedureData,
|
|
22206
|
-
updatedAt:
|
|
22099
|
+
updatedAt: serverTimestamp31()
|
|
22207
22100
|
});
|
|
22208
22101
|
const updatedSnapshot = await getDoc40(procedureRef);
|
|
22209
22102
|
return updatedSnapshot.data();
|
|
@@ -22221,7 +22114,7 @@ var ProcedureService = class extends BaseService {
|
|
|
22221
22114
|
}
|
|
22222
22115
|
await updateDoc34(procedureRef, {
|
|
22223
22116
|
isActive: false,
|
|
22224
|
-
updatedAt:
|
|
22117
|
+
updatedAt: serverTimestamp31()
|
|
22225
22118
|
});
|
|
22226
22119
|
}
|
|
22227
22120
|
/**
|
|
@@ -22898,8 +22791,8 @@ var ProcedureService = class extends BaseService {
|
|
|
22898
22791
|
const procedureRef = doc39(this.db, PROCEDURES_COLLECTION, procedureId);
|
|
22899
22792
|
await setDoc27(procedureRef, {
|
|
22900
22793
|
...newProcedure,
|
|
22901
|
-
createdAt:
|
|
22902
|
-
updatedAt:
|
|
22794
|
+
createdAt: serverTimestamp31(),
|
|
22795
|
+
updatedAt: serverTimestamp31()
|
|
22903
22796
|
});
|
|
22904
22797
|
const savedDoc = await getDoc40(procedureRef);
|
|
22905
22798
|
return savedDoc.data();
|
|
@@ -22982,7 +22875,7 @@ import {
|
|
|
22982
22875
|
where as where34,
|
|
22983
22876
|
setDoc as setDoc28,
|
|
22984
22877
|
deleteDoc as deleteDoc20,
|
|
22985
|
-
serverTimestamp as
|
|
22878
|
+
serverTimestamp as serverTimestamp32
|
|
22986
22879
|
} from "firebase/firestore";
|
|
22987
22880
|
import { z as z27 } from "zod";
|
|
22988
22881
|
var ReviewService = class extends BaseService {
|
|
@@ -23136,8 +23029,8 @@ var ReviewService = class extends BaseService {
|
|
|
23136
23029
|
reviewSchema.parse(review);
|
|
23137
23030
|
const firestoreData = {
|
|
23138
23031
|
...review,
|
|
23139
|
-
createdAt:
|
|
23140
|
-
updatedAt:
|
|
23032
|
+
createdAt: serverTimestamp32(),
|
|
23033
|
+
updatedAt: serverTimestamp32()
|
|
23141
23034
|
};
|
|
23142
23035
|
Object.keys(firestoreData).forEach((key) => {
|
|
23143
23036
|
if (firestoreData[key] === void 0) {
|