73 lines
2.1 KiB
TypeScript
73 lines
2.1 KiB
TypeScript
import { query, queryOne } from '../../../../utils/db'
|
|
|
|
/**
|
|
* 주간보고 상세 조회
|
|
* GET /api/report/weekly/[id]/detail
|
|
*/
|
|
export default defineEventHandler(async (event) => {
|
|
const userId = getCookie(event, 'user_id')
|
|
if (!userId) {
|
|
throw createError({ statusCode: 401, message: '로그인이 필요합니다.' })
|
|
}
|
|
|
|
const reportId = getRouterParam(event, 'id')
|
|
|
|
// 마스터 조회
|
|
const report = await queryOne<any>(`
|
|
SELECT
|
|
r.*,
|
|
e.employee_name as author_name,
|
|
e.employee_email as author_email
|
|
FROM wr_weekly_report r
|
|
JOIN wr_employee_info e ON r.author_id = e.employee_id
|
|
WHERE r.report_id = $1
|
|
`, [reportId])
|
|
|
|
if (!report) {
|
|
throw createError({ statusCode: 404, message: '보고서를 찾을 수 없습니다.' })
|
|
}
|
|
|
|
// 프로젝트별 실적 조회
|
|
const projects = await query<any>(`
|
|
SELECT
|
|
rp.detail_id,
|
|
rp.project_id,
|
|
p.project_code,
|
|
p.project_name,
|
|
rp.work_description,
|
|
rp.plan_description
|
|
FROM wr_weekly_report_project rp
|
|
JOIN wr_project_info p ON rp.project_id = p.project_id
|
|
WHERE rp.report_id = $1
|
|
ORDER BY rp.detail_id
|
|
`, [reportId])
|
|
|
|
return {
|
|
report: {
|
|
reportId: report.report_id,
|
|
authorId: report.author_id,
|
|
authorName: report.author_name,
|
|
authorEmail: report.author_email,
|
|
reportYear: report.report_year,
|
|
reportWeek: report.report_week,
|
|
weekStartDate: report.week_start_date,
|
|
weekEndDate: report.week_end_date,
|
|
issueDescription: report.issue_description,
|
|
vacationDescription: report.vacation_description,
|
|
remarkDescription: report.remark_description,
|
|
reportStatus: report.report_status,
|
|
submittedAt: report.submitted_at,
|
|
createdAt: report.created_at,
|
|
updatedAt: report.updated_at
|
|
},
|
|
projects: projects.map((p: any) => ({
|
|
detailId: p.detail_id,
|
|
projectId: p.project_id,
|
|
projectCode: p.project_code,
|
|
projectName: p.project_name,
|
|
workDescription: p.work_description,
|
|
planDescription: p.plan_description
|
|
}))
|
|
}
|
|
})
|