diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-07-08 11:23:40 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-07-08 11:23:40 +0000 |
| commit | b84621f9b2b7161a5ad4f0b194264e9df3e65dbf (patch) | |
| tree | ce5ec30b3d1e5104a3a2d942c71973779436783b /lib/users | |
| parent | 97936ddf280c56a4f122dedcb8dc389d0d2e63a2 (diff) | |
(대표님) 20250708 미반영분 커밋
Diffstat (limited to 'lib/users')
| -rw-r--r-- | lib/users/service.ts | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/users/service.ts b/lib/users/service.ts index 9671abfb..e32d450e 100644 --- a/lib/users/service.ts +++ b/lib/users/service.ts @@ -4,7 +4,7 @@ import { Otp } from '@/types/user'; import { getAllUsers, createUser, getUserById, updateUser, deleteUser, getUserByEmail, createOtp,getOtpByEmailAndToken, updateOtp, findOtpByEmail ,getOtpByEmailAndCode, findAllRoles, getRoleAssignedUsers} from './repository'; import logger from '@/lib/logger'; -import { Role, userRoles, users, userView, type User } from '@/db/schema/users'; +import { Role, roles, userRoles, users, userView, type User } from '@/db/schema/users'; import { saveDocument } from '../storage'; import { GetSimpleUsersSchema, GetUsersSchema } from '../admin-users/validations'; import { revalidatePath, revalidateTag, unstable_cache, unstable_noStore } from 'next/cache'; @@ -748,4 +748,22 @@ export async function getPendingUsers() { data: [] } } -}
\ No newline at end of file +} + +// ✅ Role 정보 조회 함수 추가 +export async function getUserRoles(userId: number): Promise<string[]> { + try { + const userWithRoles = await db + .select({ + roleName: roles.name, + }) + .from(userRoles) + .innerJoin(roles, eq(userRoles.roleId, roles.id)) + .where(eq(userRoles.userId, userId)) + + return userWithRoles.map(r => r.roleName) + } catch (error) { + console.error('Error fetching user roles:', error) + return [] + } +} |
