1ㅊㅏ완료
This commit is contained in:
@@ -14,8 +14,6 @@ export default defineEventHandler(async (event) => {
|
||||
SELECT
|
||||
s.report_year,
|
||||
s.report_week,
|
||||
MIN(s.week_start_date) as week_start_date,
|
||||
MAX(s.week_end_date) as week_end_date,
|
||||
COUNT(DISTINCT s.project_id) as project_count,
|
||||
SUM(s.member_count) as total_members,
|
||||
SUM(COALESCE(s.total_work_hours, 0)) as total_work_hours,
|
||||
@@ -29,16 +27,50 @@ export default defineEventHandler(async (event) => {
|
||||
`, [year])
|
||||
|
||||
return {
|
||||
weeks: rows.map((r: any) => ({
|
||||
reportYear: r.report_year,
|
||||
reportWeek: r.report_week,
|
||||
weekStartDate: r.week_start_date,
|
||||
weekEndDate: r.week_end_date,
|
||||
projectCount: parseInt(r.project_count),
|
||||
totalMembers: parseInt(r.total_members),
|
||||
totalWorkHours: parseFloat(r.total_work_hours) || 0,
|
||||
latestAggregatedAt: r.latest_aggregated_at,
|
||||
projects: r.project_names || []
|
||||
}))
|
||||
weeks: rows.map((r: any) => {
|
||||
const { monday, sunday } = getWeekDates(r.report_year, r.report_week)
|
||||
return {
|
||||
reportYear: r.report_year,
|
||||
reportWeek: r.report_week,
|
||||
weekStartDate: monday,
|
||||
weekEndDate: sunday,
|
||||
projectCount: parseInt(r.project_count),
|
||||
totalMembers: parseInt(r.total_members),
|
||||
totalWorkHours: parseFloat(r.total_work_hours) || 0,
|
||||
latestAggregatedAt: r.latest_aggregated_at,
|
||||
projects: r.project_names || []
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
// ISO 8601 주차 기준 월요일~일요일 계산
|
||||
function getWeekDates(year: number, week: number): { monday: string, sunday: string } {
|
||||
// 해당 연도의 1월 4일이 속한 주가 1주차 (ISO 8601)
|
||||
const jan4 = new Date(year, 0, 4)
|
||||
const jan4DayOfWeek = jan4.getDay() || 7 // 일요일=7
|
||||
|
||||
// 1주차의 월요일
|
||||
const week1Monday = new Date(jan4)
|
||||
week1Monday.setDate(jan4.getDate() - jan4DayOfWeek + 1)
|
||||
|
||||
// 요청된 주차의 월요일
|
||||
const monday = new Date(week1Monday)
|
||||
monday.setDate(week1Monday.getDate() + (week - 1) * 7)
|
||||
|
||||
// 일요일
|
||||
const sunday = new Date(monday)
|
||||
sunday.setDate(monday.getDate() + 6)
|
||||
|
||||
return {
|
||||
monday: formatDate(monday),
|
||||
sunday: formatDate(sunday)
|
||||
}
|
||||
}
|
||||
|
||||
function formatDate(date: Date): string {
|
||||
const y = date.getFullYear()
|
||||
const m = String(date.getMonth() + 1).padStart(2, '0')
|
||||
const d = String(date.getDate()).padStart(2, '0')
|
||||
return `${y}-${m}-${d}`
|
||||
}
|
||||
|
||||
@@ -71,6 +71,12 @@ export default defineEventHandler(async (event) => {
|
||||
params.push(q.year)
|
||||
}
|
||||
|
||||
// 주차 필터 (단일)
|
||||
if (q.week) {
|
||||
conditions.push(`r.report_week = $${paramIndex++}`)
|
||||
params.push(q.week)
|
||||
}
|
||||
|
||||
// 주차 범위 필터
|
||||
if (q.weekFrom) {
|
||||
conditions.push(`r.report_week >= $${paramIndex++}`)
|
||||
|
||||
Reference in New Issue
Block a user