@valentine-efagene/qshelter-common 2.0.5 → 2.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/generated/client/browser.d.ts +5 -0
- package/dist/generated/client/client.d.ts +5 -0
- package/dist/generated/client/internal/class.d.ts +11 -0
- package/dist/generated/client/internal/class.js +2 -2
- package/dist/generated/client/internal/prismaNamespace.d.ts +84 -3
- package/dist/generated/client/internal/prismaNamespace.js +15 -3
- package/dist/generated/client/internal/prismaNamespaceBrowser.d.ts +16 -2
- package/dist/generated/client/internal/prismaNamespaceBrowser.js +15 -3
- package/dist/generated/client/models/Role.d.ts +68 -74
- package/dist/generated/client/models/User.d.ts +366 -265
- package/dist/generated/client/models/UserRole.d.ts +1080 -0
- package/dist/generated/client/models/UserRole.js +1 -0
- package/dist/generated/client/models.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/prisma/user.d.ts +8 -0
- package/dist/prisma/user.js +17 -0
- package/package.json +1 -1
- package/prisma/schema.prisma +38 -26
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -2,6 +2,7 @@ export type * from './models/User.js';
|
|
|
2
2
|
export type * from './models/Role.js';
|
|
3
3
|
export type * from './models/Permission.js';
|
|
4
4
|
export type * from './models/RolePermission.js';
|
|
5
|
+
export type * from './models/UserRole.js';
|
|
5
6
|
export type * from './models/Tenant.js';
|
|
6
7
|
export type * from './models/RefreshToken.js';
|
|
7
8
|
export type * from './models/PasswordReset.js';
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PrismaClient } from '../generated/client/client';
|
|
2
|
+
/**
|
|
3
|
+
* Fetch a user and return a copy with a flattened `roles` array for quick access.
|
|
4
|
+
* Keeps `userRoles` intact on the returned object under the hood, but returns
|
|
5
|
+
* a top-level `roles` array of Role objects for convenience.
|
|
6
|
+
*/
|
|
7
|
+
export declare function getUserWithRoles(prisma: PrismaClient, userId: string): Promise<any>;
|
|
8
|
+
export type { PrismaClient };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetch a user and return a copy with a flattened `roles` array for quick access.
|
|
3
|
+
* Keeps `userRoles` intact on the returned object under the hood, but returns
|
|
4
|
+
* a top-level `roles` array of Role objects for convenience.
|
|
5
|
+
*/
|
|
6
|
+
export async function getUserWithRoles(prisma, userId) {
|
|
7
|
+
const user = await prisma.user.findUnique({
|
|
8
|
+
where: { id: userId },
|
|
9
|
+
include: { userRoles: { include: { role: true } } },
|
|
10
|
+
});
|
|
11
|
+
if (!user)
|
|
12
|
+
return null;
|
|
13
|
+
const roles = user.userRoles?.map((ur) => ur.role) ?? [];
|
|
14
|
+
// Return a shallow copy of the user with `roles` fused in for quick access.
|
|
15
|
+
const { userRoles, ...rest } = user;
|
|
16
|
+
return { ...rest, roles };
|
|
17
|
+
}
|
package/package.json
CHANGED
package/prisma/schema.prisma
CHANGED
|
@@ -19,30 +19,32 @@ datasource db {
|
|
|
19
19
|
// =============================================================================
|
|
20
20
|
|
|
21
21
|
model User {
|
|
22
|
-
id
|
|
23
|
-
email
|
|
24
|
-
password
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
22
|
+
id String @id @default(cuid())
|
|
23
|
+
email String @unique
|
|
24
|
+
password String?
|
|
25
|
+
phone String? @unique
|
|
26
|
+
firstName String?
|
|
27
|
+
lastName String?
|
|
28
|
+
isActive Boolean @default(true)
|
|
29
|
+
isVerified Boolean @default(false)
|
|
30
|
+
googleId String? @unique
|
|
31
|
+
tenantId String?
|
|
32
|
+
tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: SetNull)
|
|
33
|
+
// Support multiple roles via explicit join table `UserRole`
|
|
34
|
+
userRoles UserRole[]
|
|
35
|
+
walletId String? @unique
|
|
36
|
+
wallet Wallet? @relation(fields: [walletId], references: [id])
|
|
37
|
+
createdAt DateTime @default(now())
|
|
38
|
+
updatedAt DateTime @updatedAt
|
|
39
|
+
emailVerifiedAt DateTime?
|
|
40
|
+
emailVerificationToken String?
|
|
41
|
+
lastLoginAt DateTime?
|
|
42
|
+
refreshTokens RefreshToken[]
|
|
43
|
+
passwordResets PasswordReset[]
|
|
44
|
+
suspensions UserSuspension[]
|
|
45
|
+
emailPreferences EmailPreference[]
|
|
46
|
+
deviceEndpoints DeviceEndpoint[]
|
|
47
|
+
socials Social[]
|
|
46
48
|
|
|
47
49
|
// Relations to other domains
|
|
48
50
|
properties Property[]
|
|
@@ -54,7 +56,6 @@ model User {
|
|
|
54
56
|
|
|
55
57
|
@@index([email])
|
|
56
58
|
@@index([tenantId])
|
|
57
|
-
@@index([roleId])
|
|
58
59
|
@@map("users")
|
|
59
60
|
}
|
|
60
61
|
|
|
@@ -62,7 +63,7 @@ model Role {
|
|
|
62
63
|
id String @id @default(cuid())
|
|
63
64
|
name String @unique
|
|
64
65
|
description String?
|
|
65
|
-
|
|
66
|
+
userRoles UserRole[]
|
|
66
67
|
permissions RolePermission[]
|
|
67
68
|
createdAt DateTime @default(now())
|
|
68
69
|
updatedAt DateTime @updatedAt
|
|
@@ -96,6 +97,17 @@ model RolePermission {
|
|
|
96
97
|
@@map("role_permissions")
|
|
97
98
|
}
|
|
98
99
|
|
|
100
|
+
model UserRole {
|
|
101
|
+
userId String
|
|
102
|
+
roleId String
|
|
103
|
+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
104
|
+
role Role @relation(fields: [roleId], references: [id], onDelete: Cascade)
|
|
105
|
+
createdAt DateTime @default(now())
|
|
106
|
+
|
|
107
|
+
@@id([userId, roleId])
|
|
108
|
+
@@map("user_roles")
|
|
109
|
+
}
|
|
110
|
+
|
|
99
111
|
model Tenant {
|
|
100
112
|
id String @id @default(cuid())
|
|
101
113
|
name String
|