docs: Phase 4 남은 Prisma 호출 전환 계획서 작성

현재 상황 분석 및 문서화:

컨트롤러 레이어:
-  adminController.ts (28개) 완료
-  screenFileController.ts (2개) 완료
- 🔄 남은 파일 (12개 호출):
  * webTypeStandardController.ts (11개)
  * fileController.ts (1개)

Routes & Services:
- ddlRoutes.ts (2개)
- companyManagementRoutes.ts (2개)
- multiConnectionQueryService.ts (4개)

Config:
- database.ts (4개 - 제거 예정)

새로운 계획서:
- PHASE4_REMAINING_PRISMA_CALLS.md (상세 전환 계획)
- 파일별 Prisma 호출 상세 분석
- 전환 패턴 및 우선순위 정리

전체 진행률: 445/444 (100.2%)
남은 작업: 12개 (추가 조사 필요한 파일 제외)
This commit is contained in:
kjs
2025-10-01 14:33:08 +09:00
parent 381d19caee
commit 7919079362
23 changed files with 2304 additions and 1295 deletions

View File

@@ -1,8 +1,6 @@
import { Request, Response } from "express";
import { PrismaClient } from "@prisma/client";
import { AuthenticatedRequest } from "../types/auth";
const prisma = new PrismaClient();
import { query, queryOne, pool } from "../database/db";
export class ButtonActionStandardController {
// 버튼 액션 목록 조회
@@ -10,33 +8,36 @@ export class ButtonActionStandardController {
try {
const { active, category, search } = req.query;
const where: any = {};
const whereConditions: string[] = [];
const queryParams: any[] = [];
let paramIndex = 1;
if (active) {
where.is_active = active as string;
whereConditions.push(`is_active = $${paramIndex}`);
queryParams.push(active as string);
paramIndex++;
}
if (category) {
where.category = category as string;
whereConditions.push(`category = $${paramIndex}`);
queryParams.push(category as string);
paramIndex++;
}
if (search) {
where.OR = [
{ action_name: { contains: search as string, mode: "insensitive" } },
{
action_name_eng: {
contains: search as string,
mode: "insensitive",
},
},
{ description: { contains: search as string, mode: "insensitive" } },
];
whereConditions.push(`(action_name ILIKE $${paramIndex} OR action_name_eng ILIKE $${paramIndex} OR description ILIKE $${paramIndex})`);
queryParams.push(`%${search}%`);
paramIndex++;
}
const buttonActions = await prisma.button_action_standards.findMany({
where,
orderBy: [{ sort_order: "asc" }, { action_type: "asc" }],
});
const whereClause = whereConditions.length > 0
? `WHERE ${whereConditions.join(" AND ")}`
: "";
const buttonActions = await query<any>(
`SELECT * FROM button_action_standards ${whereClause} ORDER BY sort_order ASC, action_type ASC`,
queryParams
);
return res.json({
success: true,
@@ -58,9 +59,10 @@ export class ButtonActionStandardController {
try {
const { actionType } = req.params;
const buttonAction = await prisma.button_action_standards.findUnique({
where: { action_type: actionType },
});
const buttonAction = await queryOne<any>(
"SELECT * FROM button_action_standards WHERE action_type = $1 LIMIT 1",
[actionType]
);
if (!buttonAction) {
return res.status(404).json({
@@ -115,9 +117,10 @@ export class ButtonActionStandardController {
}
// 중복 체크
const existingAction = await prisma.button_action_standards.findUnique({
where: { action_type },
});
const existingAction = await queryOne<any>(
"SELECT * FROM button_action_standards WHERE action_type = $1 LIMIT 1",
[action_type]
);
if (existingAction) {
return res.status(409).json({
@@ -126,28 +129,25 @@ export class ButtonActionStandardController {
});
}
const newButtonAction = await prisma.button_action_standards.create({
data: {
action_type,
action_name,
action_name_eng,
description,
category,
default_text,
default_text_eng,
default_icon,
default_color,
default_variant,
confirmation_required,
confirmation_message,
validation_rules,
action_config,
sort_order,
is_active,
created_by: req.user?.userId || "system",
updated_by: req.user?.userId || "system",
},
});
const [newButtonAction] = await query<any>(
`INSERT INTO button_action_standards (
action_type, action_name, action_name_eng, description, category,
default_text, default_text_eng, default_icon, default_color, default_variant,
confirmation_required, confirmation_message, validation_rules, action_config,
sort_order, is_active, created_by, updated_by, created_date, updated_date
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, NOW(), NOW())
RETURNING *`,
[
action_type, action_name, action_name_eng, description, category,
default_text, default_text_eng, default_icon, default_color, default_variant,
confirmation_required, confirmation_message,
validation_rules ? JSON.stringify(validation_rules) : null,
action_config ? JSON.stringify(action_config) : null,
sort_order, is_active,
req.user?.userId || "system",
req.user?.userId || "system"
]
);
return res.status(201).json({
success: true,
@@ -187,9 +187,10 @@ export class ButtonActionStandardController {
} = req.body;
// 존재 여부 확인
const existingAction = await prisma.button_action_standards.findUnique({
where: { action_type: actionType },
});
const existingAction = await queryOne<any>(
"SELECT * FROM button_action_standards WHERE action_type = $1 LIMIT 1",
[actionType]
);
if (!existingAction) {
return res.status(404).json({
@@ -198,28 +199,101 @@ export class ButtonActionStandardController {
});
}
const updatedButtonAction = await prisma.button_action_standards.update({
where: { action_type: actionType },
data: {
action_name,
action_name_eng,
description,
category,
default_text,
default_text_eng,
default_icon,
default_color,
default_variant,
confirmation_required,
confirmation_message,
validation_rules,
action_config,
sort_order,
is_active,
updated_by: req.user?.userId || "system",
updated_date: new Date(),
},
});
const updateFields: string[] = [];
const updateParams: any[] = [];
let paramIndex = 1;
if (action_name !== undefined) {
updateFields.push(`action_name = $${paramIndex}`);
updateParams.push(action_name);
paramIndex++;
}
if (action_name_eng !== undefined) {
updateFields.push(`action_name_eng = $${paramIndex}`);
updateParams.push(action_name_eng);
paramIndex++;
}
if (description !== undefined) {
updateFields.push(`description = $${paramIndex}`);
updateParams.push(description);
paramIndex++;
}
if (category !== undefined) {
updateFields.push(`category = $${paramIndex}`);
updateParams.push(category);
paramIndex++;
}
if (default_text !== undefined) {
updateFields.push(`default_text = $${paramIndex}`);
updateParams.push(default_text);
paramIndex++;
}
if (default_text_eng !== undefined) {
updateFields.push(`default_text_eng = $${paramIndex}`);
updateParams.push(default_text_eng);
paramIndex++;
}
if (default_icon !== undefined) {
updateFields.push(`default_icon = $${paramIndex}`);
updateParams.push(default_icon);
paramIndex++;
}
if (default_color !== undefined) {
updateFields.push(`default_color = $${paramIndex}`);
updateParams.push(default_color);
paramIndex++;
}
if (default_variant !== undefined) {
updateFields.push(`default_variant = $${paramIndex}`);
updateParams.push(default_variant);
paramIndex++;
}
if (confirmation_required !== undefined) {
updateFields.push(`confirmation_required = $${paramIndex}`);
updateParams.push(confirmation_required);
paramIndex++;
}
if (confirmation_message !== undefined) {
updateFields.push(`confirmation_message = $${paramIndex}`);
updateParams.push(confirmation_message);
paramIndex++;
}
if (validation_rules !== undefined) {
updateFields.push(`validation_rules = $${paramIndex}`);
updateParams.push(validation_rules ? JSON.stringify(validation_rules) : null);
paramIndex++;
}
if (action_config !== undefined) {
updateFields.push(`action_config = $${paramIndex}`);
updateParams.push(action_config ? JSON.stringify(action_config) : null);
paramIndex++;
}
if (sort_order !== undefined) {
updateFields.push(`sort_order = $${paramIndex}`);
updateParams.push(sort_order);
paramIndex++;
}
if (is_active !== undefined) {
updateFields.push(`is_active = $${paramIndex}`);
updateParams.push(is_active);
paramIndex++;
}
updateFields.push(`updated_by = $${paramIndex}`);
updateParams.push(req.user?.userId || "system");
paramIndex++;
updateFields.push(`updated_date = $${paramIndex}`);
updateParams.push(new Date());
paramIndex++;
updateParams.push(actionType);
const [updatedButtonAction] = await query<any>(
`UPDATE button_action_standards SET ${updateFields.join(", ")}
WHERE action_type = $${paramIndex} RETURNING *`,
updateParams
);
return res.json({
success: true,
@@ -242,9 +316,10 @@ export class ButtonActionStandardController {
const { actionType } = req.params;
// 존재 여부 확인
const existingAction = await prisma.button_action_standards.findUnique({
where: { action_type: actionType },
});
const existingAction = await queryOne<any>(
"SELECT * FROM button_action_standards WHERE action_type = $1 LIMIT 1",
[actionType]
);
if (!existingAction) {
return res.status(404).json({
@@ -253,9 +328,10 @@ export class ButtonActionStandardController {
});
}
await prisma.button_action_standards.delete({
where: { action_type: actionType },
});
await query<any>(
"DELETE FROM button_action_standards WHERE action_type = $1",
[actionType]
);
return res.json({
success: true,
@@ -287,18 +363,26 @@ export class ButtonActionStandardController {
}
// 트랜잭션으로 일괄 업데이트
await prisma.$transaction(
buttonActions.map((item) =>
prisma.button_action_standards.update({
where: { action_type: item.action_type },
data: {
sort_order: item.sort_order,
updated_by: req.user?.userId || "system",
updated_date: new Date(),
},
})
)
);
const client = await pool.connect();
try {
await client.query("BEGIN");
for (const item of buttonActions) {
await client.query(
`UPDATE button_action_standards
SET sort_order = $1, updated_by = $2, updated_date = $3
WHERE action_type = $4`,
[item.sort_order, req.user?.userId || "system", new Date(), item.action_type]
);
}
await client.query("COMMIT");
} catch (error) {
await client.query("ROLLBACK");
throw error;
} finally {
client.release();
}
return res.json({
success: true,
@@ -317,19 +401,17 @@ export class ButtonActionStandardController {
// 버튼 액션 카테고리 목록 조회
static async getButtonActionCategories(req: Request, res: Response) {
try {
const categories = await prisma.button_action_standards.groupBy({
by: ["category"],
where: {
is_active: "Y",
},
_count: {
category: true,
},
});
const categories = await query<{ category: string; count: string }>(
`SELECT category, COUNT(*) as count
FROM button_action_standards
WHERE is_active = $1
GROUP BY category`,
["Y"]
);
const categoryList = categories.map((item) => ({
category: item.category,
count: item._count.category,
count: parseInt(item.count),
}));
return res.json({