테이블 연결 생성방식 수정
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
import { PrismaClient, Prisma } from "@prisma/client";
|
||||
import { logger } from "../utils/logger";
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
@@ -6,13 +6,13 @@ const prisma = new PrismaClient();
|
||||
// 타입 정의
|
||||
interface CreateDataflowDiagramData {
|
||||
diagram_name: string;
|
||||
relationships: any; // JSON 데이터
|
||||
node_positions?: any; // JSON 데이터 (노드 위치 정보)
|
||||
relationships: Record<string, unknown>; // JSON 데이터
|
||||
node_positions?: Record<string, unknown> | null; // JSON 데이터 (노드 위치 정보)
|
||||
|
||||
// 조건부 연결 관련 필드
|
||||
control?: any; // JSON 데이터 (조건 설정)
|
||||
category?: any; // JSON 데이터 (연결 종류)
|
||||
plan?: any; // JSON 데이터 (실행 계획)
|
||||
control?: Record<string, unknown> | null; // JSON 데이터 (조건 설정)
|
||||
category?: string; // 연결 종류 ("simple-key", "data-save", "external-call")
|
||||
plan?: Record<string, unknown> | null; // JSON 데이터 (실행 계획)
|
||||
|
||||
company_code: string;
|
||||
created_by: string;
|
||||
@@ -21,13 +21,13 @@ interface CreateDataflowDiagramData {
|
||||
|
||||
interface UpdateDataflowDiagramData {
|
||||
diagram_name?: string;
|
||||
relationships?: any; // JSON 데이터
|
||||
node_positions?: any; // JSON 데이터 (노드 위치 정보)
|
||||
relationships?: Record<string, unknown>; // JSON 데이터
|
||||
node_positions?: Record<string, unknown> | null; // JSON 데이터 (노드 위치 정보)
|
||||
|
||||
// 조건부 연결 관련 필드
|
||||
control?: any; // JSON 데이터 (조건 설정)
|
||||
category?: any; // JSON 데이터 (연결 종류)
|
||||
plan?: any; // JSON 데이터 (실행 계획)
|
||||
control?: Record<string, unknown> | null; // JSON 데이터 (조건 설정)
|
||||
category?: string; // 연결 종류 ("simple-key", "data-save", "external-call")
|
||||
plan?: Record<string, unknown> | null; // JSON 데이터 (실행 계획)
|
||||
|
||||
updated_by: string;
|
||||
}
|
||||
@@ -45,7 +45,13 @@ export const getDataflowDiagrams = async (
|
||||
const offset = (page - 1) * size;
|
||||
|
||||
// 검색 조건 구성
|
||||
const whereClause: any = {};
|
||||
const whereClause: {
|
||||
company_code?: string;
|
||||
diagram_name?: {
|
||||
contains: string;
|
||||
mode: "insensitive";
|
||||
};
|
||||
} = {};
|
||||
|
||||
// company_code가 '*'가 아닌 경우에만 필터링
|
||||
if (companyCode !== "*") {
|
||||
@@ -99,7 +105,10 @@ export const getDataflowDiagramById = async (
|
||||
companyCode: string
|
||||
) => {
|
||||
try {
|
||||
const whereClause: any = {
|
||||
const whereClause: {
|
||||
diagram_id: number;
|
||||
company_code?: string;
|
||||
} = {
|
||||
diagram_id: diagramId,
|
||||
};
|
||||
|
||||
@@ -129,8 +138,11 @@ export const createDataflowDiagram = async (
|
||||
const newDiagram = await prisma.dataflow_diagrams.create({
|
||||
data: {
|
||||
diagram_name: data.diagram_name,
|
||||
relationships: data.relationships,
|
||||
node_positions: data.node_positions || null,
|
||||
relationships: data.relationships as Prisma.InputJsonValue,
|
||||
node_positions: data.node_positions as
|
||||
| Prisma.InputJsonValue
|
||||
| undefined,
|
||||
category: data.category || undefined,
|
||||
company_code: data.company_code,
|
||||
created_by: data.created_by,
|
||||
updated_by: data.updated_by,
|
||||
@@ -153,8 +165,15 @@ export const updateDataflowDiagram = async (
|
||||
companyCode: string
|
||||
) => {
|
||||
try {
|
||||
logger.info(
|
||||
`관계도 수정 서비스 시작 - ID: ${diagramId}, Company: ${companyCode}`
|
||||
);
|
||||
|
||||
// 먼저 해당 관계도가 존재하는지 확인
|
||||
const whereClause: any = {
|
||||
const whereClause: {
|
||||
diagram_id: number;
|
||||
company_code?: string;
|
||||
} = {
|
||||
diagram_id: diagramId,
|
||||
};
|
||||
|
||||
@@ -167,7 +186,15 @@ export const updateDataflowDiagram = async (
|
||||
where: whereClause,
|
||||
});
|
||||
|
||||
logger.info(
|
||||
`기존 관계도 조회 결과:`,
|
||||
existingDiagram ? `ID ${existingDiagram.diagram_id} 발견` : "관계도 없음"
|
||||
);
|
||||
|
||||
if (!existingDiagram) {
|
||||
logger.warn(
|
||||
`관계도 ID ${diagramId}를 찾을 수 없음 - Company: ${companyCode}`
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -178,10 +205,15 @@ export const updateDataflowDiagram = async (
|
||||
},
|
||||
data: {
|
||||
...(data.diagram_name && { diagram_name: data.diagram_name }),
|
||||
...(data.relationships && { relationships: data.relationships }),
|
||||
...(data.node_positions !== undefined && {
|
||||
node_positions: data.node_positions,
|
||||
...(data.relationships && {
|
||||
relationships: data.relationships as Prisma.InputJsonValue,
|
||||
}),
|
||||
...(data.node_positions !== undefined && {
|
||||
node_positions: data.node_positions
|
||||
? (data.node_positions as Prisma.InputJsonValue)
|
||||
: Prisma.JsonNull,
|
||||
}),
|
||||
...(data.category !== undefined && { category: data.category }),
|
||||
updated_by: data.updated_by,
|
||||
updated_at: new Date(),
|
||||
},
|
||||
@@ -203,7 +235,10 @@ export const deleteDataflowDiagram = async (
|
||||
) => {
|
||||
try {
|
||||
// 먼저 해당 관계도가 존재하는지 확인
|
||||
const whereClause: any = {
|
||||
const whereClause: {
|
||||
diagram_id: number;
|
||||
company_code?: string;
|
||||
} = {
|
||||
diagram_id: diagramId,
|
||||
};
|
||||
|
||||
@@ -245,7 +280,10 @@ export const copyDataflowDiagram = async (
|
||||
) => {
|
||||
try {
|
||||
// 원본 관계도 조회
|
||||
const whereClause: any = {
|
||||
const whereClause: {
|
||||
diagram_id: number;
|
||||
company_code?: string;
|
||||
} = {
|
||||
diagram_id: diagramId,
|
||||
};
|
||||
|
||||
@@ -274,7 +312,12 @@ export const copyDataflowDiagram = async (
|
||||
: originalDiagram.diagram_name;
|
||||
|
||||
// 같은 패턴의 이름들을 찾아서 가장 큰 번호 찾기
|
||||
const copyWhereClause: any = {
|
||||
const copyWhereClause: {
|
||||
diagram_name: {
|
||||
startsWith: string;
|
||||
};
|
||||
company_code?: string;
|
||||
} = {
|
||||
diagram_name: {
|
||||
startsWith: baseName,
|
||||
},
|
||||
@@ -310,7 +353,11 @@ export const copyDataflowDiagram = async (
|
||||
const copiedDiagram = await prisma.dataflow_diagrams.create({
|
||||
data: {
|
||||
diagram_name: copyName,
|
||||
relationships: originalDiagram.relationships as any,
|
||||
relationships: originalDiagram.relationships as Prisma.InputJsonValue,
|
||||
node_positions: originalDiagram.node_positions
|
||||
? (originalDiagram.node_positions as Prisma.InputJsonValue)
|
||||
: Prisma.JsonNull,
|
||||
category: originalDiagram.category || undefined,
|
||||
company_code: companyCode,
|
||||
created_by: userId,
|
||||
updated_by: userId,
|
||||
|
||||
Reference in New Issue
Block a user