Files
weeklyreport/backend/api/business-report/[id]/detail.get.ts

81 lines
2.4 KiB
TypeScript

import { query, queryOne } from '../../../utils/db'
/**
* 사업 주간보고 상세 조회
* GET /api/business-report/[id]/detail
*/
export default defineEventHandler(async (event) => {
const businessReportId = Number(getRouterParam(event, 'id'))
const report = await queryOne(`
SELECT
br.*,
b.business_name,
e.employee_name as created_by_name
FROM wr_business_weekly_report br
JOIN wr_business b ON br.business_id = b.business_id
LEFT JOIN wr_employee_info e ON br.created_by = e.employee_id
WHERE br.business_report_id = $1
`, [businessReportId])
if (!report) {
throw createError({ statusCode: 404, message: '보고서를 찾을 수 없습니다.' })
}
// 소속 프로젝트 목록
const projects = await query(`
SELECT project_id, project_name FROM wr_project_info WHERE business_id = $1
`, [report.business_id])
const projectIds = projects.map((p: any) => p.project_id)
// 해당 주차 실적 목록
const tasks = await query(`
SELECT
t.task_id,
t.task_description,
t.task_type,
t.task_hours,
p.project_id,
p.project_name,
e.employee_id,
e.employee_name
FROM wr_weekly_report_task t
JOIN wr_weekly_report r ON t.report_id = r.report_id
JOIN wr_project_info p ON t.project_id = p.project_id
JOIN wr_employee_info e ON r.author_id = e.employee_id
WHERE t.project_id = ANY($1)
AND r.report_year = $2
AND r.report_week = $3
ORDER BY p.project_name, e.employee_name
`, [projectIds, report.report_year, report.report_week])
return {
report: {
businessReportId: report.business_report_id,
businessId: report.business_id,
businessName: report.business_name,
reportYear: report.report_year,
reportWeek: report.report_week,
weekStartDate: report.week_start_date,
weekEndDate: report.week_end_date,
aiSummary: report.ai_summary,
manualSummary: report.manual_summary,
status: report.status,
createdByName: report.created_by_name,
createdAt: report.created_at,
updatedAt: report.updated_at
},
tasks: tasks.map((t: any) => ({
taskId: t.task_id,
taskDescription: t.task_description,
taskType: t.task_type,
taskHours: t.task_hours,
projectId: t.project_id,
projectName: t.project_name,
employeeId: t.employee_id,
employeeName: t.employee_name
}))
}
})