From 35ad6fd173e9f937f86a00d07ed4c08ae41326cc Mon Sep 17 00:00:00 2001 From: 0-Zz-ang Date: Mon, 25 Aug 2025 14:10:48 +0900 Subject: compliance 조건부 질문 관련사항 수정 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/compliance/services.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'lib/compliance/services.ts') diff --git a/lib/compliance/services.ts b/lib/compliance/services.ts index 03fae071..de67598b 100644 --- a/lib/compliance/services.ts +++ b/lib/compliance/services.ts @@ -174,6 +174,12 @@ export async function getComplianceSurveyTemplates(input: { // 특정 템플릿 조회 export async function getComplianceSurveyTemplate(templateId: number) { try { + // templateId 유효성 검사 추가 + if (!templateId || isNaN(templateId) || templateId <= 0) { + console.error(`Invalid templateId: ${templateId}`); + return null; + } + const [template] = await db .select() .from(complianceSurveyTemplates) @@ -214,6 +220,12 @@ export async function updateComplianceSurveyTemplate(templateId: number, data: { // 템플릿의 질문들 조회 export async function getComplianceQuestions(templateId: number) { try { + // templateId 유효성 검사 추가 + if (!templateId || isNaN(templateId) || templateId <= 0) { + console.error(`Invalid templateId: ${templateId}`); + return []; + } + const questions = await db .select() .from(complianceQuestions) @@ -481,6 +493,12 @@ export async function deleteComplianceQuestionOption(optionId: number) { // 템플릿의 응답들 조회 export async function getComplianceResponses(templateId: number) { try { + // templateId 유효성 검사 추가 + if (!templateId || isNaN(templateId) || templateId <= 0) { + console.error(`Invalid templateId: ${templateId}`); + return []; + } + const responses = await db .select() .from(complianceResponses) @@ -497,6 +515,12 @@ export async function getComplianceResponses(templateId: number) { // 템플릿의 응답들과 답변들을 함께 조회 (페이지네이션 포함) export async function getComplianceResponsesWithPagination(templateId: number) { try { + // templateId 유효성 검사 추가 + if (!templateId || isNaN(templateId) || templateId <= 0) { + console.error(`Invalid templateId: ${templateId}`); + return { data: [], pageCount: 0 }; + } + const responses = await db .select({ id: complianceResponses.id, @@ -544,6 +568,17 @@ export async function getComplianceResponsesWithPagination(templateId: number) { // 템플릿별 응답 통계 조회 export async function getComplianceResponseStats(templateId: number) { try { + // templateId 유효성 검사 추가 + if (!templateId || isNaN(templateId) || templateId <= 0) { + console.error(`Invalid templateId: ${templateId}`); + return { + inProgress: 0, + completed: 0, + reviewed: 0, + total: 0 + }; + } + const responses = await db .select({ status: complianceResponses.status, -- cgit v1.2.3