@blackcode_sa/metaestetics-api 1.15.17-staging.4 → 1.15.17-staging.5
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.d.mts +3 -1
- package/dist/admin/index.d.ts +3 -1
- package/dist/index.d.mts +15 -1
- package/dist/index.d.ts +15 -1
- package/dist/index.js +102 -116
- package/dist/index.mjs +242 -256
- package/package.json +1 -1
- package/src/services/auth/auth.service.ts +14 -48
- package/src/services/clinic/clinic-group.service.ts +13 -6
- package/src/services/clinic/utils/clinic-group.utils.ts +95 -87
- package/src/types/clinic/index.ts +3 -1
- package/src/validations/clinic.schema.ts +4 -3
package/dist/admin/index.d.mts
CHANGED
|
@@ -1420,6 +1420,7 @@ interface AdminToken {
|
|
|
1420
1420
|
email?: string | null;
|
|
1421
1421
|
status: AdminTokenStatus;
|
|
1422
1422
|
usedByUserRef?: string;
|
|
1423
|
+
clinicGroupId: string;
|
|
1423
1424
|
createdAt: Timestamp;
|
|
1424
1425
|
expiresAt: Timestamp;
|
|
1425
1426
|
}
|
|
@@ -1558,7 +1559,8 @@ interface ClinicGroup {
|
|
|
1558
1559
|
clinicsInfo: ClinicInfo[];
|
|
1559
1560
|
admins: string[];
|
|
1560
1561
|
adminsInfo: AdminInfo[];
|
|
1561
|
-
adminTokens
|
|
1562
|
+
/** @deprecated Tokens now stored in subcollection clinic_groups/{id}/adminTokens */
|
|
1563
|
+
adminTokens?: AdminToken[];
|
|
1562
1564
|
ownerId: string | null;
|
|
1563
1565
|
createdAt: Timestamp;
|
|
1564
1566
|
updatedAt: Timestamp;
|
package/dist/admin/index.d.ts
CHANGED
|
@@ -1420,6 +1420,7 @@ interface AdminToken {
|
|
|
1420
1420
|
email?: string | null;
|
|
1421
1421
|
status: AdminTokenStatus;
|
|
1422
1422
|
usedByUserRef?: string;
|
|
1423
|
+
clinicGroupId: string;
|
|
1423
1424
|
createdAt: Timestamp;
|
|
1424
1425
|
expiresAt: Timestamp;
|
|
1425
1426
|
}
|
|
@@ -1558,7 +1559,8 @@ interface ClinicGroup {
|
|
|
1558
1559
|
clinicsInfo: ClinicInfo[];
|
|
1559
1560
|
admins: string[];
|
|
1560
1561
|
adminsInfo: AdminInfo[];
|
|
1561
|
-
adminTokens
|
|
1562
|
+
/** @deprecated Tokens now stored in subcollection clinic_groups/{id}/adminTokens */
|
|
1563
|
+
adminTokens?: AdminToken[];
|
|
1562
1564
|
ownerId: string | null;
|
|
1563
1565
|
createdAt: Timestamp;
|
|
1564
1566
|
updatedAt: Timestamp;
|
package/dist/index.d.mts
CHANGED
|
@@ -5865,6 +5865,7 @@ interface AdminToken {
|
|
|
5865
5865
|
email?: string | null;
|
|
5866
5866
|
status: AdminTokenStatus;
|
|
5867
5867
|
usedByUserRef?: string;
|
|
5868
|
+
clinicGroupId: string;
|
|
5868
5869
|
createdAt: Timestamp;
|
|
5869
5870
|
expiresAt: Timestamp;
|
|
5870
5871
|
}
|
|
@@ -6003,7 +6004,8 @@ interface ClinicGroup {
|
|
|
6003
6004
|
clinicsInfo: ClinicInfo[];
|
|
6004
6005
|
admins: string[];
|
|
6005
6006
|
adminsInfo: AdminInfo[];
|
|
6006
|
-
adminTokens
|
|
6007
|
+
/** @deprecated Tokens now stored in subcollection clinic_groups/{id}/adminTokens */
|
|
6008
|
+
adminTokens?: AdminToken[];
|
|
6007
6009
|
ownerId: string | null;
|
|
6008
6010
|
createdAt: Timestamp;
|
|
6009
6011
|
updatedAt: Timestamp;
|
|
@@ -7305,6 +7307,18 @@ declare class ClinicGroupService extends BaseService {
|
|
|
7305
7307
|
* Dohvata aktivne admin tokene
|
|
7306
7308
|
*/
|
|
7307
7309
|
getActiveAdminTokens(groupId: string, adminId: string): Promise<AdminToken[]>;
|
|
7310
|
+
/**
|
|
7311
|
+
* Gets ALL admin tokens for a clinic group (all statuses)
|
|
7312
|
+
*/
|
|
7313
|
+
getAllAdminTokens(groupId: string, adminId: string): Promise<AdminToken[]>;
|
|
7314
|
+
/**
|
|
7315
|
+
* Finds an admin token by its value across all clinic groups.
|
|
7316
|
+
* Uses a collection group query for O(1) lookup.
|
|
7317
|
+
*/
|
|
7318
|
+
findAdminTokenByValue(tokenValue: string): Promise<{
|
|
7319
|
+
token: AdminToken;
|
|
7320
|
+
clinicGroupId: string;
|
|
7321
|
+
} | null>;
|
|
7308
7322
|
/**
|
|
7309
7323
|
* Updates the onboarding status for a clinic group
|
|
7310
7324
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -5865,6 +5865,7 @@ interface AdminToken {
|
|
|
5865
5865
|
email?: string | null;
|
|
5866
5866
|
status: AdminTokenStatus;
|
|
5867
5867
|
usedByUserRef?: string;
|
|
5868
|
+
clinicGroupId: string;
|
|
5868
5869
|
createdAt: Timestamp;
|
|
5869
5870
|
expiresAt: Timestamp;
|
|
5870
5871
|
}
|
|
@@ -6003,7 +6004,8 @@ interface ClinicGroup {
|
|
|
6003
6004
|
clinicsInfo: ClinicInfo[];
|
|
6004
6005
|
admins: string[];
|
|
6005
6006
|
adminsInfo: AdminInfo[];
|
|
6006
|
-
adminTokens
|
|
6007
|
+
/** @deprecated Tokens now stored in subcollection clinic_groups/{id}/adminTokens */
|
|
6008
|
+
adminTokens?: AdminToken[];
|
|
6007
6009
|
ownerId: string | null;
|
|
6008
6010
|
createdAt: Timestamp;
|
|
6009
6011
|
updatedAt: Timestamp;
|
|
@@ -7305,6 +7307,18 @@ declare class ClinicGroupService extends BaseService {
|
|
|
7305
7307
|
* Dohvata aktivne admin tokene
|
|
7306
7308
|
*/
|
|
7307
7309
|
getActiveAdminTokens(groupId: string, adminId: string): Promise<AdminToken[]>;
|
|
7310
|
+
/**
|
|
7311
|
+
* Gets ALL admin tokens for a clinic group (all statuses)
|
|
7312
|
+
*/
|
|
7313
|
+
getAllAdminTokens(groupId: string, adminId: string): Promise<AdminToken[]>;
|
|
7314
|
+
/**
|
|
7315
|
+
* Finds an admin token by its value across all clinic groups.
|
|
7316
|
+
* Uses a collection group query for O(1) lookup.
|
|
7317
|
+
*/
|
|
7318
|
+
findAdminTokenByValue(tokenValue: string): Promise<{
|
|
7319
|
+
token: AdminToken;
|
|
7320
|
+
clinicGroupId: string;
|
|
7321
|
+
} | null>;
|
|
7308
7322
|
/**
|
|
7309
7323
|
* Updates the onboarding status for a clinic group
|
|
7310
7324
|
*
|
package/dist/index.js
CHANGED
|
@@ -667,11 +667,11 @@ var StaffInviteStatus = /* @__PURE__ */ ((StaffInviteStatus2) => {
|
|
|
667
667
|
var CLINIC_GROUPS_COLLECTION = "clinic_groups";
|
|
668
668
|
var CLINIC_ADMINS_COLLECTION = "clinic_admins";
|
|
669
669
|
var CLINICS_COLLECTION = "clinics";
|
|
670
|
-
var AdminTokenStatus = /* @__PURE__ */ ((
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
return
|
|
670
|
+
var AdminTokenStatus = /* @__PURE__ */ ((AdminTokenStatus3) => {
|
|
671
|
+
AdminTokenStatus3["ACTIVE"] = "active";
|
|
672
|
+
AdminTokenStatus3["USED"] = "used";
|
|
673
|
+
AdminTokenStatus3["EXPIRED"] = "expired";
|
|
674
|
+
return AdminTokenStatus3;
|
|
675
675
|
})(AdminTokenStatus || {});
|
|
676
676
|
var SubscriptionModel = /* @__PURE__ */ ((SubscriptionModel2) => {
|
|
677
677
|
SubscriptionModel2["NO_SUBSCRIPTION"] = "no_subscription";
|
|
@@ -2189,7 +2189,7 @@ var AnalyticsService = class extends BaseService {
|
|
|
2189
2189
|
* @param limit - Number of top procedures to return
|
|
2190
2190
|
* @returns Array of procedure popularity metrics
|
|
2191
2191
|
*/
|
|
2192
|
-
async getProcedurePopularity(dateRange,
|
|
2192
|
+
async getProcedurePopularity(dateRange, limit23 = 10) {
|
|
2193
2193
|
const appointments = await this.fetchAppointments(void 0, dateRange);
|
|
2194
2194
|
const completed = getCompletedAppointments(appointments);
|
|
2195
2195
|
const procedureMap = /* @__PURE__ */ new Map();
|
|
@@ -2218,7 +2218,7 @@ var AnalyticsService = class extends BaseService {
|
|
|
2218
2218
|
completedCount: data.count,
|
|
2219
2219
|
rank: 0
|
|
2220
2220
|
// Will be set after sorting
|
|
2221
|
-
})).sort((a, b) => b.appointmentCount - a.appointmentCount).slice(0,
|
|
2221
|
+
})).sort((a, b) => b.appointmentCount - a.appointmentCount).slice(0, limit23).map((item, index) => ({ ...item, rank: index + 1 }));
|
|
2222
2222
|
}
|
|
2223
2223
|
/**
|
|
2224
2224
|
* Get procedure profitability metrics
|
|
@@ -2227,7 +2227,7 @@ var AnalyticsService = class extends BaseService {
|
|
|
2227
2227
|
* @param limit - Number of top procedures to return
|
|
2228
2228
|
* @returns Array of procedure profitability metrics
|
|
2229
2229
|
*/
|
|
2230
|
-
async getProcedureProfitability(dateRange,
|
|
2230
|
+
async getProcedureProfitability(dateRange, limit23 = 10) {
|
|
2231
2231
|
const appointments = await this.fetchAppointments(void 0, dateRange);
|
|
2232
2232
|
const completed = getCompletedAppointments(appointments);
|
|
2233
2233
|
const procedureMap = /* @__PURE__ */ new Map();
|
|
@@ -2261,7 +2261,7 @@ var AnalyticsService = class extends BaseService {
|
|
|
2261
2261
|
appointmentCount: data.count,
|
|
2262
2262
|
rank: 0
|
|
2263
2263
|
// Will be set after sorting
|
|
2264
|
-
})).sort((a, b) => b.totalRevenue - a.totalRevenue).slice(0,
|
|
2264
|
+
})).sort((a, b) => b.totalRevenue - a.totalRevenue).slice(0, limit23).map((item, index) => ({ ...item, rank: index + 1 }));
|
|
2265
2265
|
}
|
|
2266
2266
|
// ==========================================
|
|
2267
2267
|
// Time Efficiency Analytics
|
|
@@ -5727,10 +5727,9 @@ var adminTokenSchema = import_zod9.z.object({
|
|
|
5727
5727
|
email: import_zod9.z.string().email().optional().nullable(),
|
|
5728
5728
|
status: import_zod9.z.nativeEnum(AdminTokenStatus),
|
|
5729
5729
|
usedByUserRef: import_zod9.z.string().optional(),
|
|
5730
|
+
clinicGroupId: import_zod9.z.string(),
|
|
5730
5731
|
createdAt: import_zod9.z.instanceof(Date).or(import_zod9.z.instanceof(import_firestore9.Timestamp)),
|
|
5731
|
-
// Timestamp
|
|
5732
5732
|
expiresAt: import_zod9.z.instanceof(Date).or(import_zod9.z.instanceof(import_firestore9.Timestamp))
|
|
5733
|
-
// Timestamp
|
|
5734
5733
|
});
|
|
5735
5734
|
var stripeTransactionDataSchema = import_zod9.z.object({
|
|
5736
5735
|
sessionId: import_zod9.z.string().optional(),
|
|
@@ -5791,7 +5790,7 @@ var clinicGroupSchema = import_zod9.z.object({
|
|
|
5791
5790
|
clinicsInfo: import_zod9.z.array(clinicInfoSchema),
|
|
5792
5791
|
admins: import_zod9.z.array(import_zod9.z.string()),
|
|
5793
5792
|
adminsInfo: import_zod9.z.array(adminInfoSchema),
|
|
5794
|
-
adminTokens: import_zod9.z.array(adminTokenSchema),
|
|
5793
|
+
adminTokens: import_zod9.z.array(adminTokenSchema).optional(),
|
|
5795
5794
|
ownerId: import_zod9.z.string().nullable(),
|
|
5796
5795
|
createdAt: import_zod9.z.instanceof(Date).or(import_zod9.z.instanceof(import_firestore9.Timestamp)),
|
|
5797
5796
|
// Timestamp
|
|
@@ -15730,6 +15729,7 @@ async function createClinicGroup(db, data, ownerId, isDefault = false, clinicAdm
|
|
|
15730
15729
|
admins: [ownerId],
|
|
15731
15730
|
adminsInfo: [],
|
|
15732
15731
|
adminTokens: [],
|
|
15732
|
+
// @deprecated — tokens now in subcollection, kept for backward compat
|
|
15733
15733
|
ownerId,
|
|
15734
15734
|
createdAt: now,
|
|
15735
15735
|
updatedAt: now,
|
|
@@ -15914,6 +15914,10 @@ async function deactivateClinicGroup(db, groupId, app) {
|
|
|
15914
15914
|
app
|
|
15915
15915
|
);
|
|
15916
15916
|
}
|
|
15917
|
+
var ADMIN_TOKENS_SUBCOLLECTION = "adminTokens";
|
|
15918
|
+
function adminTokensRef(db, groupId) {
|
|
15919
|
+
return (0, import_firestore41.collection)(db, CLINIC_GROUPS_COLLECTION, groupId, ADMIN_TOKENS_SUBCOLLECTION);
|
|
15920
|
+
}
|
|
15917
15921
|
async function createAdminToken(db, groupId, creatorAdminId, app, data) {
|
|
15918
15922
|
const group = await getClinicGroup(db, groupId);
|
|
15919
15923
|
if (!group) {
|
|
@@ -15929,68 +15933,60 @@ async function createAdminToken(db, groupId, creatorAdminId, app, data) {
|
|
|
15929
15933
|
now.seconds + expiresInDays * 24 * 60 * 60,
|
|
15930
15934
|
now.nanoseconds
|
|
15931
15935
|
);
|
|
15936
|
+
const tokenRef = (0, import_firestore41.doc)(adminTokensRef(db, groupId));
|
|
15932
15937
|
const token = {
|
|
15933
|
-
id:
|
|
15938
|
+
id: tokenRef.id,
|
|
15934
15939
|
token: generateId(),
|
|
15935
15940
|
status: "active" /* ACTIVE */,
|
|
15936
15941
|
email,
|
|
15942
|
+
clinicGroupId: groupId,
|
|
15937
15943
|
createdAt: now,
|
|
15938
15944
|
expiresAt
|
|
15939
15945
|
};
|
|
15940
|
-
await
|
|
15941
|
-
db,
|
|
15942
|
-
groupId,
|
|
15943
|
-
{
|
|
15944
|
-
adminTokens: [...group.adminTokens, token]
|
|
15945
|
-
},
|
|
15946
|
-
app
|
|
15947
|
-
);
|
|
15946
|
+
await (0, import_firestore41.setDoc)(tokenRef, token);
|
|
15948
15947
|
return token;
|
|
15949
15948
|
}
|
|
15950
|
-
async function verifyAndUseAdminToken(db, groupId,
|
|
15951
|
-
const
|
|
15952
|
-
|
|
15953
|
-
|
|
15954
|
-
|
|
15955
|
-
|
|
15956
|
-
|
|
15949
|
+
async function verifyAndUseAdminToken(db, groupId, tokenValue, userRef, app) {
|
|
15950
|
+
const tokensQuery = (0, import_firestore41.query)(
|
|
15951
|
+
adminTokensRef(db, groupId),
|
|
15952
|
+
(0, import_firestore41.where)("token", "==", tokenValue),
|
|
15953
|
+
(0, import_firestore41.limit)(1)
|
|
15954
|
+
);
|
|
15955
|
+
const snapshot = await (0, import_firestore41.getDocs)(tokensQuery);
|
|
15956
|
+
if (snapshot.empty) {
|
|
15957
15957
|
throw new Error("Admin token not found");
|
|
15958
15958
|
}
|
|
15959
|
+
const tokenDoc = snapshot.docs[0];
|
|
15960
|
+
const adminToken = tokenDoc.data();
|
|
15959
15961
|
if (adminToken.status !== "active" /* ACTIVE */) {
|
|
15960
15962
|
throw new Error("Admin token is not active");
|
|
15961
15963
|
}
|
|
15962
15964
|
const now = import_firestore41.Timestamp.now();
|
|
15963
15965
|
if (adminToken.expiresAt.seconds < now.seconds) {
|
|
15964
|
-
|
|
15965
|
-
(t) => t.id === adminToken.id ? { ...t, status: "expired" /* EXPIRED */ } : t
|
|
15966
|
-
);
|
|
15967
|
-
await updateClinicGroup(
|
|
15968
|
-
db,
|
|
15969
|
-
groupId,
|
|
15970
|
-
{
|
|
15971
|
-
adminTokens: updatedTokens2
|
|
15972
|
-
},
|
|
15973
|
-
app
|
|
15974
|
-
);
|
|
15966
|
+
await (0, import_firestore41.updateDoc)(tokenDoc.ref, { status: "expired" /* EXPIRED */ });
|
|
15975
15967
|
throw new Error("Admin token has expired");
|
|
15976
15968
|
}
|
|
15977
|
-
|
|
15978
|
-
|
|
15979
|
-
|
|
15980
|
-
|
|
15981
|
-
usedByUserRef: userRef
|
|
15982
|
-
} : t
|
|
15983
|
-
);
|
|
15984
|
-
await updateClinicGroup(
|
|
15985
|
-
db,
|
|
15986
|
-
groupId,
|
|
15987
|
-
{
|
|
15988
|
-
adminTokens: updatedTokens
|
|
15989
|
-
},
|
|
15990
|
-
app
|
|
15991
|
-
);
|
|
15969
|
+
await (0, import_firestore41.updateDoc)(tokenDoc.ref, {
|
|
15970
|
+
status: "used" /* USED */,
|
|
15971
|
+
usedByUserRef: userRef
|
|
15972
|
+
});
|
|
15992
15973
|
return true;
|
|
15993
15974
|
}
|
|
15975
|
+
async function findAdminTokenByValue(db, tokenValue) {
|
|
15976
|
+
const tokensQuery = (0, import_firestore41.query)(
|
|
15977
|
+
(0, import_firestore41.collectionGroup)(db, ADMIN_TOKENS_SUBCOLLECTION),
|
|
15978
|
+
(0, import_firestore41.where)("token", "==", tokenValue),
|
|
15979
|
+
(0, import_firestore41.where)("status", "==", "active" /* ACTIVE */),
|
|
15980
|
+
(0, import_firestore41.limit)(1)
|
|
15981
|
+
);
|
|
15982
|
+
const snapshot = await (0, import_firestore41.getDocs)(tokensQuery);
|
|
15983
|
+
if (snapshot.empty) return null;
|
|
15984
|
+
const tokenData = snapshot.docs[0].data();
|
|
15985
|
+
return {
|
|
15986
|
+
token: tokenData,
|
|
15987
|
+
clinicGroupId: tokenData.clinicGroupId
|
|
15988
|
+
};
|
|
15989
|
+
}
|
|
15994
15990
|
async function deleteAdminToken(db, groupId, tokenId, adminId, app) {
|
|
15995
15991
|
const group = await getClinicGroup(db, groupId);
|
|
15996
15992
|
if (!group) {
|
|
@@ -15999,15 +15995,7 @@ async function deleteAdminToken(db, groupId, tokenId, adminId, app) {
|
|
|
15999
15995
|
if (!group.admins.includes(adminId)) {
|
|
16000
15996
|
throw new Error("Admin does not belong to this clinic group");
|
|
16001
15997
|
}
|
|
16002
|
-
|
|
16003
|
-
await updateClinicGroup(
|
|
16004
|
-
db,
|
|
16005
|
-
groupId,
|
|
16006
|
-
{
|
|
16007
|
-
adminTokens: updatedTokens
|
|
16008
|
-
},
|
|
16009
|
-
app
|
|
16010
|
-
);
|
|
15998
|
+
await (0, import_firestore41.deleteDoc)((0, import_firestore41.doc)(adminTokensRef(db, groupId), tokenId));
|
|
16011
15999
|
}
|
|
16012
16000
|
async function getActiveAdminTokens(db, groupId, adminId, app) {
|
|
16013
16001
|
const group = await getClinicGroup(db, groupId);
|
|
@@ -16017,7 +16005,23 @@ async function getActiveAdminTokens(db, groupId, adminId, app) {
|
|
|
16017
16005
|
if (!group.admins.includes(adminId)) {
|
|
16018
16006
|
throw new Error("Admin does not belong to this clinic group");
|
|
16019
16007
|
}
|
|
16020
|
-
|
|
16008
|
+
const tokensQuery = (0, import_firestore41.query)(
|
|
16009
|
+
adminTokensRef(db, groupId),
|
|
16010
|
+
(0, import_firestore41.where)("status", "==", "active" /* ACTIVE */)
|
|
16011
|
+
);
|
|
16012
|
+
const snapshot = await (0, import_firestore41.getDocs)(tokensQuery);
|
|
16013
|
+
return snapshot.docs.map((d) => d.data());
|
|
16014
|
+
}
|
|
16015
|
+
async function getAllAdminTokens(db, groupId, adminId, app) {
|
|
16016
|
+
const group = await getClinicGroup(db, groupId);
|
|
16017
|
+
if (!group) {
|
|
16018
|
+
throw new Error("Clinic group not found");
|
|
16019
|
+
}
|
|
16020
|
+
if (!group.admins.includes(adminId)) {
|
|
16021
|
+
throw new Error("Admin does not belong to this clinic group");
|
|
16022
|
+
}
|
|
16023
|
+
const snapshot = await (0, import_firestore41.getDocs)(adminTokensRef(db, groupId));
|
|
16024
|
+
return snapshot.docs.map((d) => d.data());
|
|
16021
16025
|
}
|
|
16022
16026
|
|
|
16023
16027
|
// src/services/clinic/clinic-group.service.ts
|
|
@@ -16147,11 +16151,19 @@ var ClinicGroupService = class extends BaseService {
|
|
|
16147
16151
|
async getActiveAdminTokens(groupId, adminId) {
|
|
16148
16152
|
return getActiveAdminTokens(this.db, groupId, adminId, this.app);
|
|
16149
16153
|
}
|
|
16150
|
-
|
|
16151
|
-
|
|
16152
|
-
|
|
16153
|
-
|
|
16154
|
-
|
|
16154
|
+
/**
|
|
16155
|
+
* Gets ALL admin tokens for a clinic group (all statuses)
|
|
16156
|
+
*/
|
|
16157
|
+
async getAllAdminTokens(groupId, adminId) {
|
|
16158
|
+
return getAllAdminTokens(this.db, groupId, adminId, this.app);
|
|
16159
|
+
}
|
|
16160
|
+
/**
|
|
16161
|
+
* Finds an admin token by its value across all clinic groups.
|
|
16162
|
+
* Uses a collection group query for O(1) lookup.
|
|
16163
|
+
*/
|
|
16164
|
+
async findAdminTokenByValue(tokenValue) {
|
|
16165
|
+
return findAdminTokenByValue(this.db, tokenValue);
|
|
16166
|
+
}
|
|
16155
16167
|
/**
|
|
16156
16168
|
* Updates the onboarding status for a clinic group
|
|
16157
16169
|
*
|
|
@@ -17805,46 +17817,20 @@ var AuthService = class extends BaseService {
|
|
|
17805
17817
|
console.log("[AUTH] Invite token provided", {
|
|
17806
17818
|
token: data.inviteToken
|
|
17807
17819
|
});
|
|
17808
|
-
console.log("[AUTH] Searching for token
|
|
17809
|
-
const
|
|
17810
|
-
|
|
17811
|
-
|
|
17812
|
-
let foundGroup = null;
|
|
17813
|
-
let foundToken = null;
|
|
17814
|
-
console.log("[AUTH] Found", querySnapshot.size, "clinic groups to check");
|
|
17815
|
-
for (const docSnapshot of querySnapshot.docs) {
|
|
17816
|
-
const group = docSnapshot.data();
|
|
17817
|
-
console.log("[AUTH] Checking group", {
|
|
17818
|
-
groupId: group.id,
|
|
17819
|
-
groupName: group.name
|
|
17820
|
-
});
|
|
17821
|
-
const token = group.adminTokens.find((t) => {
|
|
17822
|
-
const isMatch = t.token === data.inviteToken && t.status === "active" /* ACTIVE */ && new Date(t.expiresAt.toDate()) > /* @__PURE__ */ new Date();
|
|
17823
|
-
console.log("[AUTH] Checking token", {
|
|
17824
|
-
tokenId: t.id,
|
|
17825
|
-
tokenMatch: t.token === data.inviteToken,
|
|
17826
|
-
tokenStatus: t.status,
|
|
17827
|
-
tokenActive: t.status === "active" /* ACTIVE */,
|
|
17828
|
-
tokenExpiry: new Date(t.expiresAt.toDate()),
|
|
17829
|
-
tokenExpired: new Date(t.expiresAt.toDate()) <= /* @__PURE__ */ new Date(),
|
|
17830
|
-
isMatch
|
|
17831
|
-
});
|
|
17832
|
-
return isMatch;
|
|
17833
|
-
});
|
|
17834
|
-
if (token) {
|
|
17835
|
-
foundGroup = group;
|
|
17836
|
-
foundToken = token;
|
|
17837
|
-
console.log("[AUTH] Found matching token in group", {
|
|
17838
|
-
groupId: group.id,
|
|
17839
|
-
tokenId: token.id
|
|
17840
|
-
});
|
|
17841
|
-
break;
|
|
17842
|
-
}
|
|
17843
|
-
}
|
|
17844
|
-
if (!foundGroup || !foundToken) {
|
|
17845
|
-
console.error("[AUTH] No valid token found in any clinic group");
|
|
17820
|
+
console.log("[AUTH] Searching for token via collection group query");
|
|
17821
|
+
const tokenResult = await clinicGroupService.findAdminTokenByValue(data.inviteToken);
|
|
17822
|
+
if (!tokenResult) {
|
|
17823
|
+
console.error("[AUTH] No valid active token found");
|
|
17846
17824
|
throw new Error("Invalid or expired invite token");
|
|
17847
17825
|
}
|
|
17826
|
+
console.log("[AUTH] Found matching token", {
|
|
17827
|
+
tokenId: tokenResult.token.id,
|
|
17828
|
+
clinicGroupId: tokenResult.clinicGroupId
|
|
17829
|
+
});
|
|
17830
|
+
const foundGroup = await clinicGroupService.getClinicGroup(tokenResult.clinicGroupId);
|
|
17831
|
+
if (!foundGroup) {
|
|
17832
|
+
throw new Error("Clinic group not found for token");
|
|
17833
|
+
}
|
|
17848
17834
|
clinicGroup = foundGroup;
|
|
17849
17835
|
console.log("[AUTH] Creating clinic admin");
|
|
17850
17836
|
const createClinicAdminData = {
|
|
@@ -24202,17 +24188,17 @@ var ProcedureService = class extends BaseService {
|
|
|
24202
24188
|
const proceduresCollection = (0, import_firestore64.collection)(this.db, PROCEDURES_COLLECTION);
|
|
24203
24189
|
let proceduresQuery = (0, import_firestore64.query)(proceduresCollection);
|
|
24204
24190
|
if (pagination && pagination > 0) {
|
|
24205
|
-
const { limit:
|
|
24191
|
+
const { limit: limit23, startAfter: startAfter20 } = await import("firebase/firestore");
|
|
24206
24192
|
if (lastDoc) {
|
|
24207
24193
|
proceduresQuery = (0, import_firestore64.query)(
|
|
24208
24194
|
proceduresCollection,
|
|
24209
24195
|
(0, import_firestore64.orderBy)("name"),
|
|
24210
24196
|
// Use imported orderBy
|
|
24211
24197
|
startAfter20(lastDoc),
|
|
24212
|
-
|
|
24198
|
+
limit23(pagination)
|
|
24213
24199
|
);
|
|
24214
24200
|
} else {
|
|
24215
|
-
proceduresQuery = (0, import_firestore64.query)(proceduresCollection, (0, import_firestore64.orderBy)("name"),
|
|
24201
|
+
proceduresQuery = (0, import_firestore64.query)(proceduresCollection, (0, import_firestore64.orderBy)("name"), limit23(pagination));
|
|
24216
24202
|
}
|
|
24217
24203
|
} else {
|
|
24218
24204
|
proceduresQuery = (0, import_firestore64.query)(proceduresCollection, (0, import_firestore64.orderBy)("name"));
|
|
@@ -28252,9 +28238,9 @@ var ConstantsService = class extends BaseService {
|
|
|
28252
28238
|
*/
|
|
28253
28239
|
async getAllBenefits(options) {
|
|
28254
28240
|
const allBenefits = await this.getAllBenefitsForFilter();
|
|
28255
|
-
const { page, limit:
|
|
28256
|
-
const startIndex = page *
|
|
28257
|
-
const endIndex = startIndex +
|
|
28241
|
+
const { page, limit: limit23 } = options;
|
|
28242
|
+
const startIndex = page * limit23;
|
|
28243
|
+
const endIndex = startIndex + limit23;
|
|
28258
28244
|
const paginatedBenefits = allBenefits.slice(startIndex, endIndex);
|
|
28259
28245
|
return { benefits: paginatedBenefits, total: allBenefits.length };
|
|
28260
28246
|
}
|
|
@@ -28351,9 +28337,9 @@ var ConstantsService = class extends BaseService {
|
|
|
28351
28337
|
*/
|
|
28352
28338
|
async getAllContraindications(options) {
|
|
28353
28339
|
const allContraindications = await this.getAllContraindicationsForFilter();
|
|
28354
|
-
const { page, limit:
|
|
28355
|
-
const startIndex = page *
|
|
28356
|
-
const endIndex = startIndex +
|
|
28340
|
+
const { page, limit: limit23 } = options;
|
|
28341
|
+
const startIndex = page * limit23;
|
|
28342
|
+
const endIndex = startIndex + limit23;
|
|
28357
28343
|
const paginatedContraindications = allContraindications.slice(
|
|
28358
28344
|
startIndex,
|
|
28359
28345
|
endIndex
|