@valentine-efagene/qshelter-common 2.0.6 → 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/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/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
|
+
}
|