const { PrismaClient } = require("@prisma/client"); const prisma = new PrismaClient(); async function testTemplateCreation() { console.log("πŸ§ͺ ν…œν”Œλ¦Ώ 생성 ν…ŒμŠ€νŠΈ μ‹œμž‘..."); try { // 1. ν…Œμ΄λΈ” 쑴재 μ—¬λΆ€ 확인 console.log("1. ν…œν”Œλ¦Ώ ν…Œμ΄λΈ” 쑴재 μ—¬λΆ€ 확인 쀑..."); try { const count = await prisma.template_standards.count(); console.log(`βœ… template_standards ν…Œμ΄λΈ” 발견 (ν˜„μž¬ ${count}개 λ ˆμ½”λ“œ)`); } catch (error) { if (error.code === "P2021") { console.log("❌ template_standards ν…Œμ΄λΈ”μ΄ μ‘΄μž¬ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€."); console.log("πŸ‘‰ λ°μ΄ν„°λ² μ΄μŠ€ λ§ˆμ΄κ·Έλ ˆμ΄μ…˜μ΄ ν•„μš”ν•©λ‹ˆλ‹€."); return; } throw error; } // 2. μƒ˜ν”Œ ν…œν”Œλ¦Ώ 생성 ν…ŒμŠ€νŠΈ console.log("2. μƒ˜ν”Œ ν…œν”Œλ¦Ώ 생성 쀑..."); const sampleTemplate = { template_code: "test-button-" + Date.now(), template_name: "ν…ŒμŠ€νŠΈ λ²„νŠΌ", template_name_eng: "Test Button", description: "ν…ŒμŠ€νŠΈμš© λ²„νŠΌ ν…œν”Œλ¦Ώ", category: "button", icon_name: "mouse-pointer", default_size: { width: 80, height: 36, }, layout_config: { components: [ { type: "widget", widgetType: "button", label: "ν…ŒμŠ€νŠΈ λ²„νŠΌ", position: { x: 0, y: 0 }, size: { width: 80, height: 36 }, style: { backgroundColor: "#3b82f6", color: "#ffffff", border: "none", borderRadius: "6px", }, }, ], }, sort_order: 999, is_active: "Y", is_public: "Y", company_code: "*", created_by: "test", updated_by: "test", }; const created = await prisma.template_standards.create({ data: sampleTemplate, }); console.log("βœ… μƒ˜ν”Œ ν…œν”Œλ¦Ώ 생성 성곡:", created.template_code); // 3. μƒμ„±λœ ν…œν”Œλ¦Ώ 쑰회 ν…ŒμŠ€νŠΈ console.log("3. ν…œν”Œλ¦Ώ 쑰회 ν…ŒμŠ€νŠΈ 쀑..."); const retrieved = await prisma.template_standards.findUnique({ where: { template_code: created.template_code }, }); if (retrieved) { console.log("βœ… ν…œν”Œλ¦Ώ 쑰회 성곡:", retrieved.template_name); console.log( "πŸ“„ Layout Config:", JSON.stringify(retrieved.layout_config, null, 2) ); } // 4. μΉ΄ν…Œκ³ λ¦¬ λͺ©λ‘ 쑰회 ν…ŒμŠ€νŠΈ console.log("4. μΉ΄ν…Œκ³ λ¦¬ λͺ©λ‘ 쑰회 ν…ŒμŠ€νŠΈ 쀑..."); const categories = await prisma.template_standards.findMany({ where: { is_active: "Y" }, select: { category: true }, distinct: ["category"], }); console.log( "βœ… 발견된 μΉ΄ν…Œκ³ λ¦¬:", categories.map((c) => c.category) ); // 5. ν…ŒμŠ€νŠΈ 데이터 정리 console.log("5. ν…ŒμŠ€νŠΈ 데이터 정리 쀑..."); await prisma.template_standards.delete({ where: { template_code: created.template_code }, }); console.log("βœ… ν…ŒμŠ€νŠΈ 데이터 정리 μ™„λ£Œ"); console.log("πŸŽ‰ λͺ¨λ“  ν…ŒμŠ€νŠΈ 톡과!"); } catch (error) { console.error("❌ ν…ŒμŠ€νŠΈ μ‹€νŒ¨:", error); console.error("πŸ“‹ 상세 정보:", { message: error.message, code: error.code, stack: error.stack?.split("\n").slice(0, 5), }); } finally { await prisma.$disconnect(); } } // 슀크립트 μ‹€ν–‰ testTemplateCreation();