diff options
Diffstat (limited to 'lib/compliance/services.ts')
| -rw-r--r-- | lib/compliance/services.ts | 35 |
1 files changed, 35 insertions, 0 deletions
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, |
