diff options
Diffstat (limited to 'lib/users/service.ts')
| -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 [] + } +} |
