From 3f60f9ca3e5bfc21644c592dcdd7a5d57e525b81 Mon Sep 17 00:00:00 2001 From: kjs Date: Tue, 25 Nov 2025 09:33:36 +0900 Subject: [PATCH] =?UTF-8?q?fix(flow):=20=EC=A0=9C=EC=96=B4=20=EC=8B=A4?= =?UTF-8?q?=ED=96=89=20=EC=8B=9C=20writer=EC=99=80=20company=5Fcode=20?= =?UTF-8?q?=EC=9E=90=EB=8F=99=20=EC=9E=85=EB=A0=A5=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ๐Ÿ› ๋ฌธ์ œ: - ์ œ์–ด(ํ”Œ๋กœ์šฐ) ์‹คํ–‰์œผ๋กœ ๋ฐ์ดํ„ฐ INSERT ์‹œ writer, company_code ์ปฌ๋Ÿผ์ด ๋น„์–ด์žˆ๋Š” ๋ฌธ์ œ - ํ”Œ๋กœ์šฐ ์‹คํ–‰ API์— ์ธ์ฆ์ด ์—†์–ด ์‚ฌ์šฉ์ž ์ •๋ณด๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์—ˆ์Œ โœ… ํ•ด๊ฒฐ: 1. ํ”Œ๋กœ์šฐ ์‹คํ–‰ API์— authenticateToken ๋ฏธ๋“ค์›จ์–ด ์ถ”๊ฐ€ 2. ์‚ฌ์šฉ์ž ์ •๋ณด(userId, userName, companyCode)๋ฅผ contextData์— ํฌํ•จ 3. INSERT ๋…ธ๋“œ ์‹คํ–‰ ์‹œ writer์™€ company_code ์ž๋™ ์ถ”๊ฐ€ - ํ•„๋“œ ๋งคํ•‘์— ์—†๋Š” ๊ฒฝ์šฐ์—๋งŒ ์ž๋™ ์ถ”๊ฐ€ - writer: ํ˜„์žฌ ๋กœ๊ทธ์ธํ•œ ์‚ฌ์šฉ์ž ID - company_code: ํ˜„์žฌ ์‚ฌ์šฉ์ž์˜ ํšŒ์‚ฌ ์ฝ”๋“œ - ์ตœ๊ณ  ๊ด€๋ฆฌ์ž(companyCode = '*')๋Š” ์ œ์™ธ 4. ํ”Œ๋กœ์šฐ ์ œ์–ด ์ž๋™ ๊ฐ์ง€ ๊ฐœ์„  - flowConfig๊ฐ€ ์žˆ์œผ๋ฉด controlMode ์—†์ด๋„ ํ”Œ๋กœ์šฐ ๋ชจ๋“œ๋กœ ์ธ์‹ - ๋ฐ์ดํ„ฐ ๋ฏธ์„ ํƒ ์‹œ ๋ช…ํ™•ํ•œ ์˜ค๋ฅ˜ ๋ฉ”์‹œ์ง€ ํ‘œ์‹œ ๐ŸŽฏ ์˜ํ–ฅ: - ์ž…๊ณ ์ฒ˜๋ฆฌ, ์ถœ๊ณ ์ฒ˜๋ฆฌ ๋“ฑ ์ œ์–ด ๊ธฐ๋ฐ˜ ๋ฐ์ดํ„ฐ ์ƒ์„ฑ ์‹œ ๋ฉ€ํ‹ฐํ…Œ๋„Œ์‹œ ๋ณด์žฅ - ๋ฐ์ดํ„ฐ ์ถ”์ ์„ฑ ํ–ฅ์ƒ (๋ˆ„๊ฐ€ ์ƒ์„ฑํ–ˆ๋Š”์ง€ ์ž๋™ ๊ธฐ๋ก) ๐Ÿ“ ์ˆ˜์ • ํŒŒ์ผ: - frontend/lib/utils/buttonActions.ts - backend-node/src/routes/dataflow/node-flows.ts - backend-node/src/services/nodeFlowExecutionService.ts --- .../src/routes/dataflow/node-flows.ts | 15 ++++++++++-- .../src/services/nodeFlowExecutionService.ts | 24 +++++++++++++++++++ frontend/lib/utils/buttonActions.ts | 10 +++++++- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/backend-node/src/routes/dataflow/node-flows.ts b/backend-node/src/routes/dataflow/node-flows.ts index 7ede970a..f13d65cf 100644 --- a/backend-node/src/routes/dataflow/node-flows.ts +++ b/backend-node/src/routes/dataflow/node-flows.ts @@ -7,6 +7,7 @@ import { query, queryOne } from "../../database/db"; import { logger } from "../../utils/logger"; import { NodeFlowExecutionService } from "../../services/nodeFlowExecutionService"; import { AuthenticatedRequest } from "../../types/auth"; +import { authenticateToken } from "../../middleware/authMiddleware"; const router = Router(); @@ -217,19 +218,29 @@ router.delete("/:flowId", async (req: Request, res: Response) => { * ํ”Œ๋กœ์šฐ ์‹คํ–‰ * POST /api/dataflow/node-flows/:flowId/execute */ -router.post("/:flowId/execute", async (req: Request, res: Response) => { +router.post("/:flowId/execute", authenticateToken, async (req: AuthenticatedRequest, res: Response) => { try { const { flowId } = req.params; const contextData = req.body; logger.info(`๐Ÿš€ ํ”Œ๋กœ์šฐ ์‹คํ–‰ ์š”์ฒญ: flowId=${flowId}`, { contextDataKeys: Object.keys(contextData), + userId: req.user?.userId, + companyCode: req.user?.companyCode, }); + // ์‚ฌ์šฉ์ž ์ •๋ณด๋ฅผ contextData์— ์ถ”๊ฐ€ + const enrichedContextData = { + ...contextData, + userId: req.user?.userId, + userName: req.user?.userName, + companyCode: req.user?.companyCode, + }; + // ํ”Œ๋กœ์šฐ ์‹คํ–‰ const result = await NodeFlowExecutionService.executeFlow( parseInt(flowId, 10), - contextData + enrichedContextData ); return res.json({ diff --git a/backend-node/src/services/nodeFlowExecutionService.ts b/backend-node/src/services/nodeFlowExecutionService.ts index 546b215a..9cdd85f3 100644 --- a/backend-node/src/services/nodeFlowExecutionService.ts +++ b/backend-node/src/services/nodeFlowExecutionService.ts @@ -938,6 +938,30 @@ export class NodeFlowExecutionService { insertedData[mapping.targetField] = value; }); + // ๐Ÿ†• writer์™€ company_code ์ž๋™ ์ถ”๊ฐ€ (ํ•„๋“œ ๋งคํ•‘์— ์—†๋Š” ๊ฒฝ์šฐ) + const hasWriterMapping = fieldMappings.some((m: any) => m.targetField === "writer"); + const hasCompanyCodeMapping = fieldMappings.some((m: any) => m.targetField === "company_code"); + + // ์ปจํ…์ŠคํŠธ์—์„œ ์‚ฌ์šฉ์ž ์ •๋ณด ์ถ”์ถœ + const userId = context.buttonContext?.userId; + const companyCode = context.buttonContext?.companyCode; + + // writer ์ž๋™ ์ถ”๊ฐ€ (๋งคํ•‘์— ์—†๊ณ , ์ปจํ…์ŠคํŠธ์— userId๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ) + if (!hasWriterMapping && userId) { + fields.push("writer"); + values.push(userId); + insertedData.writer = userId; + console.log(` ๐Ÿ”ง ์ž๋™ ์ถ”๊ฐ€: writer = ${userId}`); + } + + // company_code ์ž๋™ ์ถ”๊ฐ€ (๋งคํ•‘์— ์—†๊ณ , ์ปจํ…์ŠคํŠธ์— companyCode๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ) + if (!hasCompanyCodeMapping && companyCode && companyCode !== "*") { + fields.push("company_code"); + values.push(companyCode); + insertedData.company_code = companyCode; + console.log(` ๐Ÿ”ง ์ž๋™ ์ถ”๊ฐ€: company_code = ${companyCode}`); + } + const sql = ` INSERT INTO ${targetTable} (${fields.join(", ")}) VALUES (${fields.map((_, i) => `$${i + 1}`).join(", ")}) diff --git a/frontend/lib/utils/buttonActions.ts b/frontend/lib/utils/buttonActions.ts index 5f825cdc..0d69254b 100644 --- a/frontend/lib/utils/buttonActions.ts +++ b/frontend/lib/utils/buttonActions.ts @@ -1673,7 +1673,11 @@ export class ButtonActionExecutor { }); // ๐Ÿ”ฅ ์ƒˆ๋กœ์šด ๋ฒ„ํŠผ ์•ก์…˜ ์‹คํ–‰ ์‹œ์Šคํ…œ ์‚ฌ์šฉ - if (config.dataflowConfig?.controlMode === "flow" && config.dataflowConfig?.flowConfig) { + // flowConfig๊ฐ€ ์žˆ์œผ๋ฉด controlMode๊ฐ€ ๋ช…์‹œ๋˜์ง€ ์•Š์•„๋„ ํ”Œ๋กœ์šฐ ๋ชจ๋“œ๋กœ ๊ฐ„์ฃผ + const hasFlowConfig = config.dataflowConfig?.flowConfig && config.dataflowConfig.flowConfig.flowId; + const isFlowMode = config.dataflowConfig?.controlMode === "flow" || hasFlowConfig; + + if (isFlowMode && config.dataflowConfig?.flowConfig) { console.log("๐ŸŽฏ ๋…ธ๋“œ ํ”Œ๋กœ์šฐ ์‹คํ–‰:", config.dataflowConfig.flowConfig); const { flowId, executionTiming } = config.dataflowConfig.flowConfig; @@ -1711,6 +1715,8 @@ export class ButtonActionExecutor { }); } else { console.warn("โš ๏ธ flow-selection ๋ชจ๋“œ์ด์ง€๋งŒ ์„ ํƒ๋œ ํ”Œ๋กœ์šฐ ๋ฐ์ดํ„ฐ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค."); + toast.error("ํ”Œ๋กœ์šฐ์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ๋จผ์ € ์„ ํƒํ•ด์ฃผ์„ธ์š”."); + return false; } break; @@ -1723,6 +1729,8 @@ export class ButtonActionExecutor { }); } else { console.warn("โš ๏ธ table-selection ๋ชจ๋“œ์ด์ง€๋งŒ ์„ ํƒ๋œ ํ–‰์ด ์—†์Šต๋‹ˆ๋‹ค."); + toast.error("ํ…Œ์ด๋ธ”์—์„œ ์ฒ˜๋ฆฌํ•  ํ•ญ๋ชฉ์„ ๋จผ์ € ์„ ํƒํ•ด์ฃผ์„ธ์š”."); + return false; } break;