각 회사별 데이터 분리
This commit is contained in:
@@ -6,27 +6,39 @@ import { Router, Request, Response } from "express";
|
||||
import { query, queryOne } from "../../database/db";
|
||||
import { logger } from "../../utils/logger";
|
||||
import { NodeFlowExecutionService } from "../../services/nodeFlowExecutionService";
|
||||
import { AuthenticatedRequest } from "../../types/auth";
|
||||
|
||||
const router = Router();
|
||||
|
||||
/**
|
||||
* 플로우 목록 조회
|
||||
*/
|
||||
router.get("/", async (req: Request, res: Response) => {
|
||||
router.get("/", async (req: AuthenticatedRequest, res: Response) => {
|
||||
try {
|
||||
const flows = await query(
|
||||
`
|
||||
const userCompanyCode = req.user?.companyCode;
|
||||
|
||||
let sqlQuery = `
|
||||
SELECT
|
||||
flow_id as "flowId",
|
||||
flow_name as "flowName",
|
||||
flow_description as "flowDescription",
|
||||
company_code as "companyCode",
|
||||
created_at as "createdAt",
|
||||
updated_at as "updatedAt"
|
||||
FROM node_flows
|
||||
ORDER BY updated_at DESC
|
||||
`,
|
||||
[]
|
||||
);
|
||||
`;
|
||||
|
||||
const params: any[] = [];
|
||||
|
||||
// 슈퍼 관리자가 아니면 회사별 필터링
|
||||
if (userCompanyCode && userCompanyCode !== "*") {
|
||||
sqlQuery += ` WHERE company_code = $1`;
|
||||
params.push(userCompanyCode);
|
||||
}
|
||||
|
||||
sqlQuery += ` ORDER BY updated_at DESC`;
|
||||
|
||||
const flows = await query(sqlQuery, params);
|
||||
|
||||
return res.json({
|
||||
success: true,
|
||||
@@ -86,9 +98,10 @@ router.get("/:flowId", async (req: Request, res: Response) => {
|
||||
/**
|
||||
* 플로우 저장 (신규)
|
||||
*/
|
||||
router.post("/", async (req: Request, res: Response) => {
|
||||
router.post("/", async (req: AuthenticatedRequest, res: Response) => {
|
||||
try {
|
||||
const { flowName, flowDescription, flowData } = req.body;
|
||||
const userCompanyCode = req.user?.companyCode || "*";
|
||||
|
||||
if (!flowName || !flowData) {
|
||||
return res.status(400).json({
|
||||
@@ -99,14 +112,16 @@ router.post("/", async (req: Request, res: Response) => {
|
||||
|
||||
const result = await queryOne(
|
||||
`
|
||||
INSERT INTO node_flows (flow_name, flow_description, flow_data)
|
||||
VALUES ($1, $2, $3)
|
||||
INSERT INTO node_flows (flow_name, flow_description, flow_data, company_code)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
RETURNING flow_id as "flowId"
|
||||
`,
|
||||
[flowName, flowDescription || "", flowData]
|
||||
[flowName, flowDescription || "", flowData, userCompanyCode]
|
||||
);
|
||||
|
||||
logger.info(`플로우 저장 성공: ${result.flowId}`);
|
||||
logger.info(
|
||||
`플로우 저장 성공: ${result.flowId} (회사: ${userCompanyCode})`
|
||||
);
|
||||
|
||||
return res.json({
|
||||
success: true,
|
||||
|
||||
Reference in New Issue
Block a user