fix: buttonActionStandardController pool 사용을 transaction 함수로 변경

문제:
- pool이 null일 수 있다는 TypeScript 에러 발생
- pool.connect()를 직접 사용하는 것은 안전하지 않음

해결:
- pool import를 transaction으로 변경
- 수동 트랜잭션 관리 코드를 transaction 함수로 교체
- BEGIN/COMMIT/ROLLBACK 자동 처리
- 파라미터 개수 최적화 (updated_date를 NOW()로 변경)

장점:
- 타입 안전성 향상
- 에러 처리 자동화
- 코드 간소화
This commit is contained in:
kjs 2025-10-01 14:38:14 +09:00
parent fcf887ae76
commit 97f4d11870
1 changed files with 6 additions and 16 deletions

View File

@ -1,6 +1,6 @@
import { Request, Response } from "express";
import { AuthenticatedRequest } from "../types/auth";
import { query, queryOne, pool } from "../database/db";
import { query, queryOne, transaction } from "../database/db";
export class ButtonActionStandardController {
// 버튼 액션 목록 조회
@ -363,26 +363,16 @@ export class ButtonActionStandardController {
}
// 트랜잭션으로 일괄 업데이트
const client = await pool.connect();
try {
await client.query("BEGIN");
await transaction(async (client) => {
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]
SET sort_order = $1, updated_by = $2, updated_date = NOW()
WHERE action_type = $3`,
[item.sort_order, req.user?.userId || "system", item.action_type]
);
}
await client.query("COMMIT");
} catch (error) {
await client.query("ROLLBACK");
throw error;
} finally {
client.release();
}
});
return res.json({
success: true,