사용자 정보 수정 기능 구현

This commit is contained in:
2025-08-27 17:32:41 +09:00
parent e347b52900
commit 00ce90a9f0
3 changed files with 132 additions and 36 deletions

View File

@@ -3,10 +3,13 @@ import { logger } from "../utils/logger";
import { AuthenticatedRequest } from "../types/auth";
import { ApiResponse } from "../types/common";
import { Client } from "pg";
import { PrismaClient } from "@prisma/client";
import config from "../config/environment";
import { AdminService } from "../services/adminService";
import { EncryptUtil } from "../utils/encryptUtil";
const prisma = new PrismaClient();
/**
* 관리자 메뉴 목록 조회
*/
@@ -347,10 +350,9 @@ export const getUserList = async (req: AuthenticatedRequest, res: Response) => {
const countParams = [...queryParams];
// 총 개수 조회를 위해 기존 쿼리를 COUNT로 변환
const countQuery = query.replace(
/SELECT[\s\S]*?FROM/i,
"SELECT COUNT(*) as total FROM"
).replace(/ORDER BY.*$/i, "");
const countQuery = query
.replace(/SELECT[\s\S]*?FROM/i, "SELECT COUNT(*) as total FROM")
.replace(/ORDER BY.*$/i, "");
const countResult = await client.query(countQuery, countParams);
const totalCount = parseInt(countResult.rows[0].total);
@@ -2686,6 +2688,102 @@ export const deleteCompany = async (
* 사용자 비밀번호 초기화 API
* 기존 Java AdminController.resetUserPassword() 포팅
*/
export const updateProfile = async (
req: AuthenticatedRequest,
res: Response
) => {
try {
const userId = req.user?.userId;
if (!userId) {
res.status(401).json({
result: false,
error: {
code: "TOKEN_MISSING",
details: "인증 토큰이 필요합니다.",
},
});
return;
}
const {
userName,
userNameEng,
userNameCn,
email,
tel,
cellPhone,
photo,
locale,
} = req.body;
// 사용자 정보 업데이트
const updateData: any = {};
if (userName !== undefined) updateData.user_name = userName;
if (userNameEng !== undefined) updateData.user_name_eng = userNameEng;
if (userNameCn !== undefined) updateData.user_name_cn = userNameCn;
if (email !== undefined) updateData.email = email;
if (tel !== undefined) updateData.tel = tel;
if (cellPhone !== undefined) updateData.cell_phone = cellPhone;
if (photo !== undefined) updateData.photo = photo;
if (locale !== undefined) updateData.locale = locale;
// 업데이트할 데이터가 없으면 에러
if (Object.keys(updateData).length === 0) {
res.status(400).json({
result: false,
error: {
code: "NO_DATA",
details: "업데이트할 데이터가 없습니다.",
},
});
return;
}
// 데이터베이스 업데이트
await prisma.user_info.update({
where: { user_id: userId },
data: updateData,
});
// 업데이트된 사용자 정보 조회
const updatedUser = await prisma.user_info.findUnique({
where: { user_id: userId },
select: {
user_id: true,
user_name: true,
user_name_eng: true,
user_name_cn: true,
dept_code: true,
dept_name: true,
position_code: true,
position_name: true,
email: true,
tel: true,
cell_phone: true,
user_type: true,
user_type_name: true,
photo: true,
locale: true,
},
});
res.json({
result: true,
message: "프로필이 성공적으로 업데이트되었습니다.",
data: updatedUser,
});
} catch (error) {
console.error("프로필 업데이트 오류:", error);
res.status(500).json({
result: false,
error: {
code: "UPDATE_FAILED",
details: "프로필 업데이트 중 오류가 발생했습니다.",
},
});
}
};
export const resetUserPassword = async (
req: AuthenticatedRequest,
res: Response