feat: Phase 2.1 Stage 1 complete - Basic CRUD converted (6/46)
Stage 1 완료: 기본 CRUD Raw Query 전환 ✅ 전환 완료 (6개): 1. createScreen() - 화면 생성 (중복확인 + INSERT) 2. getScreensByCompany() - 목록 조회 (페이징 + 동적 WHERE) 3. getScreenById() - ID로 조회 4. updateScreen() - 화면 수정 (권한확인 + UPDATE) 5. deleteScreen() - 소프트 삭제 (트랜잭션) 6. getScreenByCode() - 코드로 조회 📊 진행률: 6/46 (13%) 🎯 다음: Stage 1 나머지 조회 함수 (getScreens, getAllScreens) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
95c9811c3b
commit
13c1bc48de
|
|
@ -195,17 +195,17 @@ export class ScreenManagementService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 화면 정의 조회 (활성 화면만)
|
* 화면 정의 조회 (활성 화면만) (✅ Raw Query 전환 완료)
|
||||||
*/
|
*/
|
||||||
async getScreenById(screenId: number): Promise<ScreenDefinition | null> {
|
async getScreenById(screenId: number): Promise<ScreenDefinition | null> {
|
||||||
const screen = await prisma.screen_definitions.findFirst({
|
const screens = await query<any>(
|
||||||
where: {
|
`SELECT * FROM screen_definitions
|
||||||
screen_id: screenId,
|
WHERE screen_id = $1 AND is_active != 'D'
|
||||||
is_active: { not: "D" }, // 삭제된 화면 제외
|
LIMIT 1`,
|
||||||
},
|
[screenId]
|
||||||
});
|
);
|
||||||
|
|
||||||
return screen ? this.mapToScreenDefinition(screen) : null;
|
return screens.length > 0 ? this.mapToScreenDefinition(screens[0]) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -233,22 +233,25 @@ export class ScreenManagementService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 화면 정의 수정
|
* 화면 정의 수정 (✅ Raw Query 전환 완료)
|
||||||
*/
|
*/
|
||||||
async updateScreen(
|
async updateScreen(
|
||||||
screenId: number,
|
screenId: number,
|
||||||
updateData: UpdateScreenRequest,
|
updateData: UpdateScreenRequest,
|
||||||
userCompanyCode: string
|
userCompanyCode: string
|
||||||
): Promise<ScreenDefinition> {
|
): Promise<ScreenDefinition> {
|
||||||
// 권한 확인
|
// 권한 확인 (Raw Query)
|
||||||
const existingScreen = await prisma.screen_definitions.findUnique({
|
const existingResult = await query<{ company_code: string | null }>(
|
||||||
where: { screen_id: screenId },
|
`SELECT company_code FROM screen_definitions WHERE screen_id = $1 LIMIT 1`,
|
||||||
});
|
[screenId]
|
||||||
|
);
|
||||||
|
|
||||||
if (!existingScreen) {
|
if (existingResult.length === 0) {
|
||||||
throw new Error("화면을 찾을 수 없습니다.");
|
throw new Error("화면을 찾을 수 없습니다.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const existingScreen = existingResult[0];
|
||||||
|
|
||||||
if (
|
if (
|
||||||
userCompanyCode !== "*" &&
|
userCompanyCode !== "*" &&
|
||||||
existingScreen.company_code !== userCompanyCode
|
existingScreen.company_code !== userCompanyCode
|
||||||
|
|
@ -256,16 +259,25 @@ export class ScreenManagementService {
|
||||||
throw new Error("이 화면을 수정할 권한이 없습니다.");
|
throw new Error("이 화면을 수정할 권한이 없습니다.");
|
||||||
}
|
}
|
||||||
|
|
||||||
const screen = await prisma.screen_definitions.update({
|
// 화면 업데이트 (Raw Query)
|
||||||
where: { screen_id: screenId },
|
const [screen] = await query<any>(
|
||||||
data: {
|
`UPDATE screen_definitions
|
||||||
screen_name: updateData.screenName,
|
SET screen_name = $1,
|
||||||
description: updateData.description,
|
description = $2,
|
||||||
is_active: updateData.isActive ? "Y" : "N",
|
is_active = $3,
|
||||||
updated_by: updateData.updatedBy,
|
updated_by = $4,
|
||||||
updated_date: new Date(),
|
updated_date = $5
|
||||||
},
|
WHERE screen_id = $6
|
||||||
});
|
RETURNING *`,
|
||||||
|
[
|
||||||
|
updateData.screenName,
|
||||||
|
updateData.description || null,
|
||||||
|
updateData.isActive ? "Y" : "N",
|
||||||
|
updateData.updatedBy,
|
||||||
|
new Date(),
|
||||||
|
screenId,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
return this.mapToScreenDefinition(screen);
|
return this.mapToScreenDefinition(screen);
|
||||||
}
|
}
|
||||||
|
|
@ -496,7 +508,7 @@ export class ScreenManagementService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 화면 정의 삭제 (휴지통으로 이동 - 소프트 삭제)
|
* 화면 정의 삭제 (휴지통으로 이동 - 소프트 삭제) (✅ Raw Query 전환 완료)
|
||||||
*/
|
*/
|
||||||
async deleteScreen(
|
async deleteScreen(
|
||||||
screenId: number,
|
screenId: number,
|
||||||
|
|
@ -505,15 +517,18 @@ export class ScreenManagementService {
|
||||||
deleteReason?: string,
|
deleteReason?: string,
|
||||||
force: boolean = false
|
force: boolean = false
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
// 권한 확인
|
// 권한 확인 (Raw Query)
|
||||||
const existingScreen = await prisma.screen_definitions.findUnique({
|
const existingResult = await query<{ company_code: string | null; is_active: string }>(
|
||||||
where: { screen_id: screenId },
|
`SELECT company_code, is_active FROM screen_definitions WHERE screen_id = $1 LIMIT 1`,
|
||||||
});
|
[screenId]
|
||||||
|
);
|
||||||
|
|
||||||
if (!existingScreen) {
|
if (existingResult.length === 0) {
|
||||||
throw new Error("화면을 찾을 수 없습니다.");
|
throw new Error("화면을 찾을 수 없습니다.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const existingScreen = existingResult[0];
|
||||||
|
|
||||||
if (
|
if (
|
||||||
userCompanyCode !== "*" &&
|
userCompanyCode !== "*" &&
|
||||||
existingScreen.company_code !== userCompanyCode
|
existingScreen.company_code !== userCompanyCode
|
||||||
|
|
@ -540,31 +555,28 @@ export class ScreenManagementService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 트랜잭션으로 화면 삭제와 메뉴 할당 정리를 함께 처리
|
// 트랜잭션으로 화면 삭제와 메뉴 할당 정리를 함께 처리 (Raw Query)
|
||||||
await prisma.$transaction(async (tx) => {
|
await transaction(async (client) => {
|
||||||
// 소프트 삭제 (휴지통으로 이동)
|
// 소프트 삭제 (휴지통으로 이동)
|
||||||
await tx.screen_definitions.update({
|
await client.query(
|
||||||
where: { screen_id: screenId },
|
`UPDATE screen_definitions
|
||||||
data: {
|
SET is_active = 'D',
|
||||||
is_active: "D",
|
deleted_date = $1,
|
||||||
deleted_date: new Date(),
|
deleted_by = $2,
|
||||||
deleted_by: deletedBy,
|
delete_reason = $3,
|
||||||
delete_reason: deleteReason,
|
updated_date = $4,
|
||||||
updated_date: new Date(),
|
updated_by = $5
|
||||||
updated_by: deletedBy,
|
WHERE screen_id = $6`,
|
||||||
},
|
[new Date(), deletedBy, deleteReason || null, new Date(), deletedBy, screenId]
|
||||||
});
|
);
|
||||||
|
|
||||||
// 메뉴 할당도 비활성화
|
// 메뉴 할당도 비활성화
|
||||||
await tx.screen_menu_assignments.updateMany({
|
await client.query(
|
||||||
where: {
|
`UPDATE screen_menu_assignments
|
||||||
screen_id: screenId,
|
SET is_active = 'N'
|
||||||
is_active: "Y",
|
WHERE screen_id = $1 AND is_active = 'Y'`,
|
||||||
},
|
[screenId]
|
||||||
data: {
|
);
|
||||||
is_active: "N",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue