@primocaredentgroup/convex-campaigns-component 0.3.0 → 0.3.2
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.
|
@@ -40,7 +40,12 @@ async function queryUserByEmailWithFallback(ctx: any, email: string) {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
const users = await ctx.db.query("users").collect();
|
|
43
|
-
return
|
|
43
|
+
return (
|
|
44
|
+
users.find(
|
|
45
|
+
(u: any) =>
|
|
46
|
+
u?.isActive && u?.email?.toLowerCase() === email?.toLowerCase(),
|
|
47
|
+
) ?? null
|
|
48
|
+
);
|
|
44
49
|
}
|
|
45
50
|
|
|
46
51
|
export const resolveRolesForIdentity = internalQuery({
|
|
@@ -70,10 +75,18 @@ export const resolveRolesForIdentity = internalQuery({
|
|
|
70
75
|
const directRole = normalizeRole(user.role);
|
|
71
76
|
if (directRole) roles.add(directRole);
|
|
72
77
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
78
|
+
let userClinicRoles: Array<{ isActive?: boolean; roleId: string }>;
|
|
79
|
+
try {
|
|
80
|
+
userClinicRoles = await ctx.db
|
|
81
|
+
.query("user_clinic_roles")
|
|
82
|
+
.withIndex("by_user", (q) => q.eq("userId", user._id))
|
|
83
|
+
.collect();
|
|
84
|
+
} catch (error) {
|
|
85
|
+
if (!isIndexError(error)) throw error;
|
|
86
|
+
userClinicRoles = (
|
|
87
|
+
await ctx.db.query("user_clinic_roles").collect()
|
|
88
|
+
).filter((r: any) => r.userId === user._id);
|
|
89
|
+
}
|
|
77
90
|
|
|
78
91
|
for (const userClinicRole of userClinicRoles) {
|
|
79
92
|
if (!userClinicRole.isActive) continue;
|
|
@@ -56,7 +56,12 @@ async function queryUserByEmailWithFallback(ctx: AnyCtx, email: string) {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
const users = await ctx.db.query("users").collect();
|
|
59
|
-
return
|
|
59
|
+
return (
|
|
60
|
+
users.find(
|
|
61
|
+
(u: any) =>
|
|
62
|
+
u?.isActive && u?.email?.toLowerCase() === email?.toLowerCase(),
|
|
63
|
+
) ?? null
|
|
64
|
+
);
|
|
60
65
|
}
|
|
61
66
|
|
|
62
67
|
async function resolveCurrentUserWithDb(ctx: AnyCtx) {
|
|
@@ -86,10 +91,19 @@ async function getUserRoleCodes(ctx: AnyCtx, userId: Id<"users">): Promise<Set<s
|
|
|
86
91
|
roles.add(normalizeRole(user.role));
|
|
87
92
|
}
|
|
88
93
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
94
|
+
let userClinicRoles: any[] = [];
|
|
95
|
+
try {
|
|
96
|
+
userClinicRoles = await ctx.db
|
|
97
|
+
.query("user_clinic_roles")
|
|
98
|
+
.withIndex("by_user", (q: any) => q.eq("userId", userId))
|
|
99
|
+
.collect();
|
|
100
|
+
} catch (error) {
|
|
101
|
+
if (!isIndexError(error)) throw error;
|
|
102
|
+
userClinicRoles = (await ctx.db.query("user_clinic_roles").collect()).filter(
|
|
103
|
+
(r: any) => r.userId === userId,
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
93
107
|
for (const userClinicRole of userClinicRoles) {
|
|
94
108
|
if (!userClinicRole.isActive) continue;
|
|
95
109
|
const roleDoc = await ctx.db.get(userClinicRole.roleId);
|