77 lines
2.5 KiB
TypeScript
77 lines
2.5 KiB
TypeScript
import { queryOne, query } from '../../../../utils/db'
|
|
|
|
/**
|
|
* 취합 보고서 상세 (개별 보고서 포함)
|
|
* GET /api/report/summary/[id]/detail
|
|
*/
|
|
export default defineEventHandler(async (event) => {
|
|
const summaryId = getRouterParam(event, 'id')
|
|
|
|
// 취합 보고서 조회
|
|
const summary = await queryOne<any>(`
|
|
SELECT s.*, p.project_name, p.project_code,
|
|
e.employee_name as reviewer_name
|
|
FROM wr_aggregated_report_summary s
|
|
JOIN wr_project_info p ON s.project_id = p.project_id
|
|
LEFT JOIN wr_employee_info e ON s.reviewer_id = e.employee_id
|
|
WHERE s.summary_id = $1
|
|
`, [summaryId])
|
|
|
|
if (!summary) {
|
|
throw createError({ statusCode: 404, message: '취합 보고서를 찾을 수 없습니다.' })
|
|
}
|
|
|
|
// 개별 보고서 목록 (새 구조: 마스터 + 프로젝트별 실적 조인)
|
|
const reports = await query(`
|
|
SELECT
|
|
r.report_id,
|
|
r.author_id,
|
|
e.employee_name as author_name,
|
|
e.employee_position,
|
|
r.issue_description,
|
|
r.vacation_description,
|
|
r.remark_description,
|
|
r.report_status,
|
|
r.submitted_at,
|
|
rp.work_description,
|
|
rp.plan_description
|
|
FROM wr_weekly_report r
|
|
JOIN wr_weekly_report_project rp ON r.report_id = rp.report_id
|
|
JOIN wr_employee_info e ON r.author_id = e.employee_id
|
|
WHERE rp.project_id = $1 AND r.report_year = $2 AND r.report_week = $3
|
|
ORDER BY e.employee_name
|
|
`, [summary.project_id, summary.report_year, summary.report_week])
|
|
|
|
return {
|
|
summary: {
|
|
summaryId: summary.summary_id,
|
|
projectId: summary.project_id,
|
|
projectName: summary.project_name,
|
|
projectCode: summary.project_code,
|
|
reportYear: summary.report_year,
|
|
reportWeek: summary.report_week,
|
|
weekStartDate: summary.week_start_date,
|
|
weekEndDate: summary.week_end_date,
|
|
memberCount: summary.member_count,
|
|
reviewerId: summary.reviewer_id,
|
|
reviewerName: summary.reviewer_name,
|
|
reviewerComment: summary.reviewer_comment,
|
|
reviewedAt: summary.reviewed_at,
|
|
summaryStatus: summary.summary_status
|
|
},
|
|
reports: reports.map((r: any) => ({
|
|
reportId: r.report_id,
|
|
authorId: r.author_id,
|
|
authorName: r.author_name,
|
|
authorPosition: r.employee_position,
|
|
workDescription: r.work_description,
|
|
planDescription: r.plan_description,
|
|
issueDescription: r.issue_description,
|
|
vacationDescription: r.vacation_description,
|
|
remarkDescription: r.remark_description,
|
|
reportStatus: r.report_status,
|
|
submittedAt: r.submitted_at
|
|
}))
|
|
}
|
|
})
|