@blackcode_sa/metaestetics-api 1.14.17 → 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 +66 -170
- package/dist/index.mjs +119 -223
- package/package.json +1 -1
- package/src/admin/mailing/practitionerInvite/templates/invitation.template.ts +2 -13
- package/src/services/auth/auth.service.ts +9 -197
- 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,49 +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
|
-
|
|
16389
|
-
|
|
16390
|
-
console.error("[AUTH] Actual auth.currentUser:", ((_b = this.auth.currentUser) == null ? void 0 : _b.uid) || "NULL");
|
|
16391
|
-
console.log("[AUTH] Waiting for auth state to recover...");
|
|
16327
|
+
const credential3 = GoogleAuthProvider.credential(idToken);
|
|
16328
|
+
await signInWithCredential(this.auth, credential3);
|
|
16392
16329
|
await this.waitForAuthStateToSettle(firebaseUser2.uid, 2e3);
|
|
16393
16330
|
}
|
|
16394
16331
|
const practitionerService2 = new PractitionerService(this.db, this.auth, this.app);
|
|
16395
16332
|
const draftProfiles3 = await practitionerService2.getDraftProfilesByEmail(normalizedEmail);
|
|
16396
|
-
console.log("[AUTH] Draft profiles check result:", {
|
|
16397
|
-
email: normalizedEmail,
|
|
16398
|
-
draftProfilesCount: draftProfiles3.length,
|
|
16399
|
-
draftProfileIds: draftProfiles3.map((p) => p.id)
|
|
16400
|
-
});
|
|
16401
16333
|
if (draftProfiles3.length === 0) {
|
|
16402
|
-
console.log("[AUTH] No draft profiles found, signing out and throwing error");
|
|
16403
16334
|
try {
|
|
16404
16335
|
await firebaseSignOut(this.auth);
|
|
16405
16336
|
} catch (signOutError) {
|
|
16406
|
-
console.warn("[AUTH] Error signing out
|
|
16337
|
+
console.warn("[AUTH] Error signing out:", signOutError);
|
|
16407
16338
|
}
|
|
16408
16339
|
throw new AuthError(
|
|
16409
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.",
|
|
@@ -16411,28 +16342,20 @@ ${stackTrace}`);
|
|
|
16411
16342
|
404
|
|
16412
16343
|
);
|
|
16413
16344
|
}
|
|
16414
|
-
console.log("[AUTH] Draft profiles found, creating User document IMMEDIATELY after sign-in");
|
|
16415
|
-
console.log("[AUTH] auth.currentUser at User creation time:", ((_c = this.auth.currentUser) == null ? void 0 : _c.uid) || "NULL");
|
|
16416
16345
|
try {
|
|
16417
16346
|
const newUser = await this.userService.createUser(firebaseUser2, ["practitioner" /* PRACTITIONER */], {
|
|
16418
16347
|
skipProfileCreation: true
|
|
16419
16348
|
});
|
|
16420
|
-
console.log("[AUTH] \u2705 User document created successfully:", newUser.uid);
|
|
16421
16349
|
return {
|
|
16422
16350
|
user: newUser,
|
|
16423
16351
|
practitioner: null,
|
|
16424
16352
|
draftProfiles: draftProfiles3
|
|
16425
16353
|
};
|
|
16426
16354
|
} catch (createUserError) {
|
|
16427
|
-
console.error("[AUTH] \u274C Failed to create User document:", {
|
|
16428
|
-
errorCode: createUserError == null ? void 0 : createUserError.code,
|
|
16429
|
-
errorMessage: createUserError == null ? void 0 : createUserError.message,
|
|
16430
|
-
uid: firebaseUser2.uid
|
|
16431
|
-
});
|
|
16432
16355
|
try {
|
|
16433
16356
|
await firebaseSignOut(this.auth);
|
|
16434
16357
|
} catch (signOutError) {
|
|
16435
|
-
console.warn("[AUTH] Error signing out
|
|
16358
|
+
console.warn("[AUTH] Error signing out:", signOutError);
|
|
16436
16359
|
}
|
|
16437
16360
|
throw createUserError;
|
|
16438
16361
|
}
|
|
@@ -16457,14 +16380,12 @@ ${stackTrace}`);
|
|
|
16457
16380
|
};
|
|
16458
16381
|
}
|
|
16459
16382
|
if (hasEmailMethod && !hasGoogleMethod) {
|
|
16460
|
-
console.log("[AUTH] User exists with email/password only");
|
|
16461
16383
|
throw new AuthError(
|
|
16462
16384
|
"An account with this email already exists. Please sign in with your email and password, then link your Google account in settings.",
|
|
16463
16385
|
"AUTH/EMAIL_ALREADY_EXISTS",
|
|
16464
16386
|
409
|
|
16465
16387
|
);
|
|
16466
16388
|
}
|
|
16467
|
-
console.log("[AUTH] Signing in with Google credential");
|
|
16468
16389
|
const credential = GoogleAuthProvider.credential(idToken);
|
|
16469
16390
|
let firebaseUser;
|
|
16470
16391
|
try {
|
|
@@ -16480,30 +16401,23 @@ ${stackTrace}`);
|
|
|
16480
16401
|
}
|
|
16481
16402
|
throw error;
|
|
16482
16403
|
}
|
|
16483
|
-
console.log("[AUTH] Waiting for auth state to settle after sign-in...");
|
|
16484
16404
|
await this.waitForAuthStateToSettle(firebaseUser.uid);
|
|
16485
|
-
console.log("[AUTH] \u2705 Auth state settled, proceeding with Firestore queries");
|
|
16486
16405
|
let existingUser = null;
|
|
16487
16406
|
try {
|
|
16488
16407
|
const existingUserDoc = await this.userService.getUserById(firebaseUser.uid);
|
|
16489
16408
|
if (existingUserDoc) {
|
|
16490
16409
|
existingUser = existingUserDoc;
|
|
16491
|
-
console.log("[AUTH] Found existing User document");
|
|
16492
16410
|
}
|
|
16493
16411
|
} catch (error) {
|
|
16494
|
-
console.error("[AUTH] Error checking for existing user:", error);
|
|
16495
16412
|
}
|
|
16496
|
-
console.log("[AUTH] Checking for draft profiles");
|
|
16497
16413
|
let draftProfiles = [];
|
|
16498
16414
|
try {
|
|
16499
16415
|
draftProfiles = await practitionerService.getDraftProfilesByEmail(normalizedEmail);
|
|
16500
|
-
console.log("[AUTH] Draft profiles check complete", { count: draftProfiles.length });
|
|
16501
16416
|
} catch (draftCheckError) {
|
|
16502
|
-
console.error("[AUTH] Error checking draft profiles:", draftCheckError);
|
|
16503
16417
|
try {
|
|
16504
16418
|
await firebaseSignOut(this.auth);
|
|
16505
16419
|
} catch (signOutError) {
|
|
16506
|
-
console.warn("[AUTH] Error signing out
|
|
16420
|
+
console.warn("[AUTH] Error signing out:", signOutError);
|
|
16507
16421
|
}
|
|
16508
16422
|
throw new AuthError(
|
|
16509
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.",
|
|
@@ -16514,55 +16428,38 @@ ${stackTrace}`);
|
|
|
16514
16428
|
let user;
|
|
16515
16429
|
if (existingUser) {
|
|
16516
16430
|
user = existingUser;
|
|
16517
|
-
console.log("[AUTH] Using existing user account");
|
|
16518
16431
|
} else {
|
|
16519
16432
|
if (draftProfiles.length === 0) {
|
|
16520
|
-
console.log("[AUTH] No draft profiles found, signing out and throwing error");
|
|
16521
16433
|
try {
|
|
16522
16434
|
await firebaseSignOut(this.auth);
|
|
16523
16435
|
} catch (signOutError) {
|
|
16524
|
-
console.warn("[AUTH] Error signing out
|
|
16436
|
+
console.warn("[AUTH] Error signing out:", signOutError);
|
|
16525
16437
|
}
|
|
16526
|
-
|
|
16438
|
+
throw new AuthError(
|
|
16527
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.",
|
|
16528
16440
|
"AUTH/NO_DRAFT_PROFILES",
|
|
16529
16441
|
404
|
|
16530
16442
|
);
|
|
16531
|
-
console.log("[AUTH] Throwing NO_DRAFT_PROFILES error:", noDraftError.code);
|
|
16532
|
-
throw noDraftError;
|
|
16533
16443
|
}
|
|
16534
16444
|
user = await this.userService.createUser(firebaseUser, ["practitioner" /* PRACTITIONER */], {
|
|
16535
16445
|
skipProfileCreation: true
|
|
16536
16446
|
});
|
|
16537
|
-
console.log("[AUTH] Created new user account with draft profiles available");
|
|
16538
16447
|
}
|
|
16539
16448
|
let practitioner = null;
|
|
16540
16449
|
if (user.practitionerProfile) {
|
|
16541
16450
|
practitioner = await practitionerService.getPractitioner(user.practitionerProfile);
|
|
16542
16451
|
}
|
|
16543
|
-
console.log("[AUTH] Google Sign-In complete", {
|
|
16544
|
-
userId: user.uid,
|
|
16545
|
-
hasPractitioner: !!practitioner,
|
|
16546
|
-
draftProfilesCount: draftProfiles.length
|
|
16547
|
-
});
|
|
16548
16452
|
return {
|
|
16549
16453
|
user,
|
|
16550
16454
|
practitioner,
|
|
16551
16455
|
draftProfiles
|
|
16552
16456
|
};
|
|
16553
16457
|
} catch (error) {
|
|
16554
|
-
console.error("[AUTH] Error in signUpPractitionerWithGoogle:", error);
|
|
16555
|
-
console.error("[AUTH] Error type:", (_d = error == null ? void 0 : error.constructor) == null ? void 0 : _d.name);
|
|
16556
|
-
console.error("[AUTH] Error instanceof AuthError:", error instanceof AuthError);
|
|
16557
|
-
console.error("[AUTH] Error code:", error == null ? void 0 : error.code);
|
|
16558
|
-
console.error("[AUTH] Error message:", error == null ? void 0 : error.message);
|
|
16559
16458
|
if (error instanceof AuthError) {
|
|
16560
|
-
console.log("[AUTH] Preserving AuthError:", error.code);
|
|
16561
16459
|
throw error;
|
|
16562
16460
|
}
|
|
16563
16461
|
const errorMessage = (error == null ? void 0 : error.message) || (error == null ? void 0 : error.toString()) || "";
|
|
16564
16462
|
if (errorMessage.includes("NO_DRAFT_PROFILES") || errorMessage.includes("clinic invitation")) {
|
|
16565
|
-
console.log("[AUTH] Detected clinic invitation error in message, converting to AuthError");
|
|
16566
16463
|
throw new AuthError(
|
|
16567
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.",
|
|
16568
16465
|
"AUTH/NO_DRAFT_PROFILES",
|
|
@@ -16570,7 +16467,6 @@ ${stackTrace}`);
|
|
|
16570
16467
|
);
|
|
16571
16468
|
}
|
|
16572
16469
|
const wrappedError = handleFirebaseError(error);
|
|
16573
|
-
console.log("[AUTH] Wrapped error:", wrappedError.message);
|
|
16574
16470
|
if (wrappedError.message.includes("permissions") || wrappedError.message.includes("Account creation failed")) {
|
|
16575
16471
|
throw new AuthError(
|
|
16576
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.",
|
|
@@ -16617,7 +16513,7 @@ ${stackTrace}`);
|
|
|
16617
16513
|
};
|
|
16618
16514
|
|
|
16619
16515
|
// src/services/calendar/calendar.v2.service.ts
|
|
16620
|
-
import { Timestamp as Timestamp29, serverTimestamp as
|
|
16516
|
+
import { Timestamp as Timestamp29, serverTimestamp as serverTimestamp26 } from "firebase/firestore";
|
|
16621
16517
|
import {
|
|
16622
16518
|
doc as doc32,
|
|
16623
16519
|
getDoc as getDoc33,
|
|
@@ -16642,7 +16538,7 @@ import {
|
|
|
16642
16538
|
where as where22,
|
|
16643
16539
|
orderBy as orderBy8,
|
|
16644
16540
|
Timestamp as Timestamp23,
|
|
16645
|
-
serverTimestamp as
|
|
16541
|
+
serverTimestamp as serverTimestamp21
|
|
16646
16542
|
} from "firebase/firestore";
|
|
16647
16543
|
|
|
16648
16544
|
// src/services/calendar/utils/docs.utils.ts
|
|
@@ -16691,8 +16587,8 @@ async function createClinicCalendarEventUtil(db, clinicId, eventData, generateId
|
|
|
16691
16587
|
const newEvent = {
|
|
16692
16588
|
id: eventId,
|
|
16693
16589
|
...eventData,
|
|
16694
|
-
createdAt:
|
|
16695
|
-
updatedAt:
|
|
16590
|
+
createdAt: serverTimestamp21(),
|
|
16591
|
+
updatedAt: serverTimestamp21()
|
|
16696
16592
|
};
|
|
16697
16593
|
await setDoc17(eventRef, newEvent);
|
|
16698
16594
|
return {
|
|
@@ -16705,7 +16601,7 @@ async function updateClinicCalendarEventUtil(db, clinicId, eventId, updateData)
|
|
|
16705
16601
|
const eventRef = getClinicCalendarEventDocRef(db, clinicId, eventId);
|
|
16706
16602
|
const updates = {
|
|
16707
16603
|
...updateData,
|
|
16708
|
-
updatedAt:
|
|
16604
|
+
updatedAt: serverTimestamp21()
|
|
16709
16605
|
};
|
|
16710
16606
|
await updateDoc22(eventRef, updates);
|
|
16711
16607
|
const updatedDoc = await getDoc28(eventRef);
|
|
@@ -16746,7 +16642,7 @@ import {
|
|
|
16746
16642
|
where as where23,
|
|
16747
16643
|
orderBy as orderBy9,
|
|
16748
16644
|
Timestamp as Timestamp24,
|
|
16749
|
-
serverTimestamp as
|
|
16645
|
+
serverTimestamp as serverTimestamp22
|
|
16750
16646
|
} from "firebase/firestore";
|
|
16751
16647
|
async function createPatientCalendarEventUtil(db, patientId, eventData, generateId2) {
|
|
16752
16648
|
const eventId = generateId2();
|
|
@@ -16754,8 +16650,8 @@ async function createPatientCalendarEventUtil(db, patientId, eventData, generate
|
|
|
16754
16650
|
const newEvent = {
|
|
16755
16651
|
id: eventId,
|
|
16756
16652
|
...eventData,
|
|
16757
|
-
createdAt:
|
|
16758
|
-
updatedAt:
|
|
16653
|
+
createdAt: serverTimestamp22(),
|
|
16654
|
+
updatedAt: serverTimestamp22()
|
|
16759
16655
|
};
|
|
16760
16656
|
await setDoc18(eventRef, newEvent);
|
|
16761
16657
|
return {
|
|
@@ -16768,7 +16664,7 @@ async function updatePatientCalendarEventUtil(db, patientId, eventId, updateData
|
|
|
16768
16664
|
const eventRef = getPatientCalendarEventDocRef(db, patientId, eventId);
|
|
16769
16665
|
const updates = {
|
|
16770
16666
|
...updateData,
|
|
16771
|
-
updatedAt:
|
|
16667
|
+
updatedAt: serverTimestamp22()
|
|
16772
16668
|
};
|
|
16773
16669
|
await updateDoc23(eventRef, updates);
|
|
16774
16670
|
const updatedDoc = await getDoc29(eventRef);
|
|
@@ -16790,7 +16686,7 @@ import {
|
|
|
16790
16686
|
where as where24,
|
|
16791
16687
|
orderBy as orderBy10,
|
|
16792
16688
|
Timestamp as Timestamp25,
|
|
16793
|
-
serverTimestamp as
|
|
16689
|
+
serverTimestamp as serverTimestamp23
|
|
16794
16690
|
} from "firebase/firestore";
|
|
16795
16691
|
async function createPractitionerCalendarEventUtil(db, practitionerId, eventData, generateId2) {
|
|
16796
16692
|
const eventId = generateId2();
|
|
@@ -16802,8 +16698,8 @@ async function createPractitionerCalendarEventUtil(db, practitionerId, eventData
|
|
|
16802
16698
|
const newEvent = {
|
|
16803
16699
|
id: eventId,
|
|
16804
16700
|
...eventData,
|
|
16805
|
-
createdAt:
|
|
16806
|
-
updatedAt:
|
|
16701
|
+
createdAt: serverTimestamp23(),
|
|
16702
|
+
updatedAt: serverTimestamp23()
|
|
16807
16703
|
};
|
|
16808
16704
|
await setDoc19(eventRef, newEvent);
|
|
16809
16705
|
return {
|
|
@@ -16820,7 +16716,7 @@ async function updatePractitionerCalendarEventUtil(db, practitionerId, eventId,
|
|
|
16820
16716
|
);
|
|
16821
16717
|
const updates = {
|
|
16822
16718
|
...updateData,
|
|
16823
|
-
updatedAt:
|
|
16719
|
+
updatedAt: serverTimestamp23()
|
|
16824
16720
|
};
|
|
16825
16721
|
await updateDoc24(eventRef, updates);
|
|
16826
16722
|
const updatedDoc = await getDoc30(eventRef);
|
|
@@ -16893,7 +16789,7 @@ import {
|
|
|
16893
16789
|
where as where25,
|
|
16894
16790
|
orderBy as orderBy11,
|
|
16895
16791
|
Timestamp as Timestamp26,
|
|
16896
|
-
serverTimestamp as
|
|
16792
|
+
serverTimestamp as serverTimestamp24
|
|
16897
16793
|
} from "firebase/firestore";
|
|
16898
16794
|
async function searchCalendarEventsUtil(db, params) {
|
|
16899
16795
|
const { searchLocation, entityId, ...filters } = params;
|
|
@@ -16998,7 +16894,7 @@ import {
|
|
|
16998
16894
|
query as query26,
|
|
16999
16895
|
orderBy as orderBy12,
|
|
17000
16896
|
Timestamp as Timestamp27,
|
|
17001
|
-
serverTimestamp as
|
|
16897
|
+
serverTimestamp as serverTimestamp25
|
|
17002
16898
|
} from "firebase/firestore";
|
|
17003
16899
|
async function createPractitionerSyncedCalendarUtil(db, practitionerId, calendarData, generateId2) {
|
|
17004
16900
|
const calendarId = generateId2();
|
|
@@ -17010,8 +16906,8 @@ async function createPractitionerSyncedCalendarUtil(db, practitionerId, calendar
|
|
|
17010
16906
|
const newCalendar = {
|
|
17011
16907
|
id: calendarId,
|
|
17012
16908
|
...calendarData,
|
|
17013
|
-
createdAt:
|
|
17014
|
-
updatedAt:
|
|
16909
|
+
createdAt: serverTimestamp25(),
|
|
16910
|
+
updatedAt: serverTimestamp25()
|
|
17015
16911
|
};
|
|
17016
16912
|
await setDoc21(calendarRef, newCalendar);
|
|
17017
16913
|
return {
|
|
@@ -17026,8 +16922,8 @@ async function createPatientSyncedCalendarUtil(db, patientId, calendarData, gene
|
|
|
17026
16922
|
const newCalendar = {
|
|
17027
16923
|
id: calendarId,
|
|
17028
16924
|
...calendarData,
|
|
17029
|
-
createdAt:
|
|
17030
|
-
updatedAt:
|
|
16925
|
+
createdAt: serverTimestamp25(),
|
|
16926
|
+
updatedAt: serverTimestamp25()
|
|
17031
16927
|
};
|
|
17032
16928
|
await setDoc21(calendarRef, newCalendar);
|
|
17033
16929
|
return {
|
|
@@ -17042,8 +16938,8 @@ async function createClinicSyncedCalendarUtil(db, clinicId, calendarData, genera
|
|
|
17042
16938
|
const newCalendar = {
|
|
17043
16939
|
id: calendarId,
|
|
17044
16940
|
...calendarData,
|
|
17045
|
-
createdAt:
|
|
17046
|
-
updatedAt:
|
|
16941
|
+
createdAt: serverTimestamp25(),
|
|
16942
|
+
updatedAt: serverTimestamp25()
|
|
17047
16943
|
};
|
|
17048
16944
|
await setDoc21(calendarRef, newCalendar);
|
|
17049
16945
|
return {
|
|
@@ -17115,7 +17011,7 @@ async function updatePractitionerSyncedCalendarUtil(db, practitionerId, calendar
|
|
|
17115
17011
|
);
|
|
17116
17012
|
const updates = {
|
|
17117
17013
|
...updateData,
|
|
17118
|
-
updatedAt:
|
|
17014
|
+
updatedAt: serverTimestamp25()
|
|
17119
17015
|
};
|
|
17120
17016
|
await updateDoc26(calendarRef, updates);
|
|
17121
17017
|
const updatedDoc = await getDoc32(calendarRef);
|
|
@@ -17128,7 +17024,7 @@ async function updatePatientSyncedCalendarUtil(db, patientId, calendarId, update
|
|
|
17128
17024
|
const calendarRef = getPatientSyncedCalendarDocRef(db, patientId, calendarId);
|
|
17129
17025
|
const updates = {
|
|
17130
17026
|
...updateData,
|
|
17131
|
-
updatedAt:
|
|
17027
|
+
updatedAt: serverTimestamp25()
|
|
17132
17028
|
};
|
|
17133
17029
|
await updateDoc26(calendarRef, updates);
|
|
17134
17030
|
const updatedDoc = await getDoc32(calendarRef);
|
|
@@ -17141,7 +17037,7 @@ async function updateClinicSyncedCalendarUtil(db, clinicId, calendarId, updateDa
|
|
|
17141
17037
|
const calendarRef = getClinicSyncedCalendarDocRef(db, clinicId, calendarId);
|
|
17142
17038
|
const updates = {
|
|
17143
17039
|
...updateData,
|
|
17144
|
-
updatedAt:
|
|
17040
|
+
updatedAt: serverTimestamp25()
|
|
17145
17041
|
};
|
|
17146
17042
|
await updateDoc26(calendarRef, updates);
|
|
17147
17043
|
const updatedDoc = await getDoc32(calendarRef);
|
|
@@ -18363,8 +18259,8 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
18363
18259
|
const newEvent = {
|
|
18364
18260
|
id: eventId,
|
|
18365
18261
|
...eventData,
|
|
18366
|
-
createdAt:
|
|
18367
|
-
updatedAt:
|
|
18262
|
+
createdAt: serverTimestamp26(),
|
|
18263
|
+
updatedAt: serverTimestamp26()
|
|
18368
18264
|
};
|
|
18369
18265
|
await setDoc22(eventRef, newEvent);
|
|
18370
18266
|
return {
|
|
@@ -18580,7 +18476,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
18580
18476
|
end: Timestamp29.fromDate(endTime)
|
|
18581
18477
|
},
|
|
18582
18478
|
description: externalEvent.description || "",
|
|
18583
|
-
updatedAt:
|
|
18479
|
+
updatedAt: serverTimestamp26()
|
|
18584
18480
|
});
|
|
18585
18481
|
console.log(`Updated local event ${eventId} from external event`);
|
|
18586
18482
|
} catch (error) {
|
|
@@ -18607,7 +18503,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
18607
18503
|
);
|
|
18608
18504
|
await updateDoc27(eventRef, {
|
|
18609
18505
|
status,
|
|
18610
|
-
updatedAt:
|
|
18506
|
+
updatedAt: serverTimestamp26()
|
|
18611
18507
|
});
|
|
18612
18508
|
console.log(`Updated event ${eventId} status to ${status}`);
|
|
18613
18509
|
} catch (error) {
|
|
@@ -19008,7 +18904,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
19008
18904
|
}
|
|
19009
18905
|
await updateDoc27(eventRef, {
|
|
19010
18906
|
syncedCalendarEventId: syncIds,
|
|
19011
|
-
updatedAt:
|
|
18907
|
+
updatedAt: serverTimestamp26()
|
|
19012
18908
|
});
|
|
19013
18909
|
console.log(
|
|
19014
18910
|
`Updated event ${eventId} with sync ID ${syncEvent.eventId}`
|
|
@@ -19231,7 +19127,7 @@ var CalendarServiceV2 = class extends BaseService {
|
|
|
19231
19127
|
};
|
|
19232
19128
|
|
|
19233
19129
|
// src/services/calendar/calendar.v3.service.ts
|
|
19234
|
-
import { Timestamp as Timestamp30, serverTimestamp as
|
|
19130
|
+
import { Timestamp as Timestamp30, serverTimestamp as serverTimestamp27 } from "firebase/firestore";
|
|
19235
19131
|
import { doc as doc33, getDoc as getDoc34, setDoc as setDoc23, updateDoc as updateDoc28, deleteDoc as deleteDoc15 } from "firebase/firestore";
|
|
19236
19132
|
var CalendarServiceV3 = class extends BaseService {
|
|
19237
19133
|
/**
|
|
@@ -19266,8 +19162,8 @@ var CalendarServiceV3 = class extends BaseService {
|
|
|
19266
19162
|
status: "confirmed" /* CONFIRMED */,
|
|
19267
19163
|
// Blocking events are always confirmed
|
|
19268
19164
|
syncStatus: "internal" /* INTERNAL */,
|
|
19269
|
-
createdAt:
|
|
19270
|
-
updatedAt:
|
|
19165
|
+
createdAt: serverTimestamp27(),
|
|
19166
|
+
updatedAt: serverTimestamp27()
|
|
19271
19167
|
};
|
|
19272
19168
|
if (params.entityType === "practitioner") {
|
|
19273
19169
|
eventData.practitionerProfileId = params.entityId;
|
|
@@ -19297,7 +19193,7 @@ var CalendarServiceV3 = class extends BaseService {
|
|
|
19297
19193
|
throw new Error(`Blocking event with ID ${params.eventId} not found`);
|
|
19298
19194
|
}
|
|
19299
19195
|
const updateData = {
|
|
19300
|
-
updatedAt:
|
|
19196
|
+
updatedAt: serverTimestamp27()
|
|
19301
19197
|
};
|
|
19302
19198
|
if (params.eventName !== void 0) {
|
|
19303
19199
|
updateData.eventName = params.eventName;
|
|
@@ -19544,7 +19440,7 @@ import {
|
|
|
19544
19440
|
setDoc as setDoc24,
|
|
19545
19441
|
deleteDoc as deleteDoc16,
|
|
19546
19442
|
Timestamp as Timestamp31,
|
|
19547
|
-
serverTimestamp as
|
|
19443
|
+
serverTimestamp as serverTimestamp28,
|
|
19548
19444
|
orderBy as orderBy13,
|
|
19549
19445
|
limit as limit12
|
|
19550
19446
|
} from "firebase/firestore";
|
|
@@ -19706,7 +19602,7 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
19706
19602
|
const updateData = {
|
|
19707
19603
|
status: "accepted" /* ACCEPTED */,
|
|
19708
19604
|
acceptedAt: Timestamp31.now(),
|
|
19709
|
-
updatedAt:
|
|
19605
|
+
updatedAt: serverTimestamp28()
|
|
19710
19606
|
};
|
|
19711
19607
|
const docRef = doc34(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
19712
19608
|
await updateDoc29(docRef, updateData);
|
|
@@ -19738,7 +19634,7 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
19738
19634
|
status: "rejected" /* REJECTED */,
|
|
19739
19635
|
rejectionReason: rejectionReason || null,
|
|
19740
19636
|
rejectedAt: Timestamp31.now(),
|
|
19741
|
-
updatedAt:
|
|
19637
|
+
updatedAt: serverTimestamp28()
|
|
19742
19638
|
};
|
|
19743
19639
|
const docRef = doc34(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
19744
19640
|
await updateDoc29(docRef, updateData);
|
|
@@ -19770,7 +19666,7 @@ var PractitionerInviteService = class extends BaseService {
|
|
|
19770
19666
|
status: "cancelled" /* CANCELLED */,
|
|
19771
19667
|
cancelReason: cancelReason || null,
|
|
19772
19668
|
cancelledAt: Timestamp31.now(),
|
|
19773
|
-
updatedAt:
|
|
19669
|
+
updatedAt: serverTimestamp28()
|
|
19774
19670
|
};
|
|
19775
19671
|
const docRef = doc34(this.db, PRACTITIONER_INVITES_COLLECTION, inviteId);
|
|
19776
19672
|
await updateDoc29(docRef, updateData);
|
|
@@ -21044,7 +20940,7 @@ import {
|
|
|
21044
20940
|
updateDoc as updateDoc34,
|
|
21045
20941
|
setDoc as setDoc27,
|
|
21046
20942
|
deleteDoc as deleteDoc19,
|
|
21047
|
-
serverTimestamp as
|
|
20943
|
+
serverTimestamp as serverTimestamp31,
|
|
21048
20944
|
writeBatch as writeBatch6,
|
|
21049
20945
|
orderBy as orderBy18,
|
|
21050
20946
|
limit as limit16,
|
|
@@ -21530,8 +21426,8 @@ var ProcedureService = class extends BaseService {
|
|
|
21530
21426
|
const procedureRef = doc39(this.db, PROCEDURES_COLLECTION, procedureId);
|
|
21531
21427
|
await setDoc27(procedureRef, {
|
|
21532
21428
|
...newProcedure,
|
|
21533
|
-
createdAt:
|
|
21534
|
-
updatedAt:
|
|
21429
|
+
createdAt: serverTimestamp31(),
|
|
21430
|
+
updatedAt: serverTimestamp31()
|
|
21535
21431
|
});
|
|
21536
21432
|
const savedDoc = await getDoc40(procedureRef);
|
|
21537
21433
|
return savedDoc.data();
|
|
@@ -21658,8 +21554,8 @@ var ProcedureService = class extends BaseService {
|
|
|
21658
21554
|
const procedureRef = doc39(this.db, PROCEDURES_COLLECTION, newProcedureId);
|
|
21659
21555
|
await setDoc27(procedureRef, {
|
|
21660
21556
|
...newProcedure,
|
|
21661
|
-
createdAt:
|
|
21662
|
-
updatedAt:
|
|
21557
|
+
createdAt: serverTimestamp31(),
|
|
21558
|
+
updatedAt: serverTimestamp31()
|
|
21663
21559
|
});
|
|
21664
21560
|
const savedDoc = await getDoc40(procedureRef);
|
|
21665
21561
|
return savedDoc.data();
|
|
@@ -21760,8 +21656,8 @@ var ProcedureService = class extends BaseService {
|
|
|
21760
21656
|
const procedureRef = doc39(this.db, PROCEDURES_COLLECTION, newProcedureId);
|
|
21761
21657
|
batch.set(procedureRef, {
|
|
21762
21658
|
...newProcedure,
|
|
21763
|
-
createdAt:
|
|
21764
|
-
updatedAt:
|
|
21659
|
+
createdAt: serverTimestamp31(),
|
|
21660
|
+
updatedAt: serverTimestamp31()
|
|
21765
21661
|
});
|
|
21766
21662
|
}
|
|
21767
21663
|
await batch.commit();
|
|
@@ -21965,8 +21861,8 @@ var ProcedureService = class extends BaseService {
|
|
|
21965
21861
|
console.log("\u{1F525}\u{1F525}\u{1F525} NO UNDEFINED FIELDS - Proceeding with batch.set");
|
|
21966
21862
|
batch.set(procedureRef, {
|
|
21967
21863
|
...newProcedure,
|
|
21968
|
-
createdAt:
|
|
21969
|
-
updatedAt:
|
|
21864
|
+
createdAt: serverTimestamp31(),
|
|
21865
|
+
updatedAt: serverTimestamp31()
|
|
21970
21866
|
});
|
|
21971
21867
|
}
|
|
21972
21868
|
await batch.commit();
|
|
@@ -22200,7 +22096,7 @@ var ProcedureService = class extends BaseService {
|
|
|
22200
22096
|
}
|
|
22201
22097
|
await updateDoc34(procedureRef, {
|
|
22202
22098
|
...updatedProcedureData,
|
|
22203
|
-
updatedAt:
|
|
22099
|
+
updatedAt: serverTimestamp31()
|
|
22204
22100
|
});
|
|
22205
22101
|
const updatedSnapshot = await getDoc40(procedureRef);
|
|
22206
22102
|
return updatedSnapshot.data();
|
|
@@ -22218,7 +22114,7 @@ var ProcedureService = class extends BaseService {
|
|
|
22218
22114
|
}
|
|
22219
22115
|
await updateDoc34(procedureRef, {
|
|
22220
22116
|
isActive: false,
|
|
22221
|
-
updatedAt:
|
|
22117
|
+
updatedAt: serverTimestamp31()
|
|
22222
22118
|
});
|
|
22223
22119
|
}
|
|
22224
22120
|
/**
|
|
@@ -22895,8 +22791,8 @@ var ProcedureService = class extends BaseService {
|
|
|
22895
22791
|
const procedureRef = doc39(this.db, PROCEDURES_COLLECTION, procedureId);
|
|
22896
22792
|
await setDoc27(procedureRef, {
|
|
22897
22793
|
...newProcedure,
|
|
22898
|
-
createdAt:
|
|
22899
|
-
updatedAt:
|
|
22794
|
+
createdAt: serverTimestamp31(),
|
|
22795
|
+
updatedAt: serverTimestamp31()
|
|
22900
22796
|
});
|
|
22901
22797
|
const savedDoc = await getDoc40(procedureRef);
|
|
22902
22798
|
return savedDoc.data();
|
|
@@ -22979,7 +22875,7 @@ import {
|
|
|
22979
22875
|
where as where34,
|
|
22980
22876
|
setDoc as setDoc28,
|
|
22981
22877
|
deleteDoc as deleteDoc20,
|
|
22982
|
-
serverTimestamp as
|
|
22878
|
+
serverTimestamp as serverTimestamp32
|
|
22983
22879
|
} from "firebase/firestore";
|
|
22984
22880
|
import { z as z27 } from "zod";
|
|
22985
22881
|
var ReviewService = class extends BaseService {
|
|
@@ -23133,8 +23029,8 @@ var ReviewService = class extends BaseService {
|
|
|
23133
23029
|
reviewSchema.parse(review);
|
|
23134
23030
|
const firestoreData = {
|
|
23135
23031
|
...review,
|
|
23136
|
-
createdAt:
|
|
23137
|
-
updatedAt:
|
|
23032
|
+
createdAt: serverTimestamp32(),
|
|
23033
|
+
updatedAt: serverTimestamp32()
|
|
23138
23034
|
};
|
|
23139
23035
|
Object.keys(firestoreData).forEach((key) => {
|
|
23140
23036
|
if (firestoreData[key] === void 0) {
|