추가
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { query } from '../../../utils/db'
|
||||
|
||||
/**
|
||||
* 내 주간보고 목록
|
||||
* 주간보고 목록 조회
|
||||
* GET /api/report/weekly/list
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
@@ -11,50 +11,45 @@ export default defineEventHandler(async (event) => {
|
||||
}
|
||||
|
||||
const queryParams = getQuery(event)
|
||||
const year = queryParams.year ? parseInt(queryParams.year as string) : null
|
||||
const projectId = queryParams.projectId ? parseInt(queryParams.projectId as string) : null
|
||||
const limit = parseInt(queryParams.limit as string) || 20
|
||||
|
||||
let sql = `
|
||||
SELECT r.*, p.project_name, p.project_code
|
||||
FROM wr_weekly_report_detail r
|
||||
JOIN wr_project_info p ON r.project_id = p.project_id
|
||||
const reports = await query<any>(`
|
||||
SELECT
|
||||
r.report_id,
|
||||
r.author_id,
|
||||
e.employee_name as author_name,
|
||||
r.report_year,
|
||||
r.report_week,
|
||||
r.week_start_date,
|
||||
r.week_end_date,
|
||||
r.issue_description,
|
||||
r.vacation_description,
|
||||
r.report_status,
|
||||
r.submitted_at,
|
||||
r.created_at,
|
||||
(SELECT COUNT(*) FROM wr_weekly_report_project WHERE report_id = r.report_id) as project_count
|
||||
FROM wr_weekly_report r
|
||||
JOIN wr_employee_info e ON r.author_id = e.employee_id
|
||||
WHERE r.author_id = $1
|
||||
`
|
||||
const params: any[] = [parseInt(userId)]
|
||||
let paramIndex = 2
|
||||
|
||||
if (year) {
|
||||
sql += ` AND r.report_year = $${paramIndex++}`
|
||||
params.push(year)
|
||||
}
|
||||
if (projectId) {
|
||||
sql += ` AND r.project_id = $${paramIndex++}`
|
||||
params.push(projectId)
|
||||
}
|
||||
|
||||
sql += ' ORDER BY r.report_year DESC, r.report_week DESC'
|
||||
|
||||
const reports = await query(sql, params)
|
||||
ORDER BY r.report_year DESC, r.report_week DESC
|
||||
LIMIT $2
|
||||
`, [userId, limit])
|
||||
|
||||
return {
|
||||
reports: reports.map((r: any) => ({
|
||||
reportId: r.report_id,
|
||||
projectId: r.project_id,
|
||||
projectName: r.project_name,
|
||||
projectCode: r.project_code,
|
||||
authorId: r.author_id,
|
||||
authorName: r.author_name,
|
||||
reportYear: r.report_year,
|
||||
reportWeek: r.report_week,
|
||||
weekStartDate: r.week_start_date,
|
||||
weekEndDate: r.week_end_date,
|
||||
workDescription: r.work_description,
|
||||
planDescription: r.plan_description,
|
||||
issueDescription: r.issue_description,
|
||||
remarkDescription: r.remark_description,
|
||||
workHours: r.work_hours,
|
||||
vacationDescription: r.vacation_description,
|
||||
reportStatus: r.report_status,
|
||||
submittedAt: r.submitted_at,
|
||||
createdAt: r.created_at,
|
||||
updatedAt: r.updated_at
|
||||
projectCount: parseInt(r.project_count)
|
||||
}))
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user