This commit is contained in:
2026-01-04 17:24:47 +09:00
parent d1db71de61
commit a87c11597a
59 changed files with 15057 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
import { 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.*, p.project_name, p.project_code, e.employee_name as author_name
FROM wr_weekly_report_detail r
JOIN wr_project_info p ON r.project_id = p.project_id
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: '보고서를 찾을 수 없습니다.' })
}
return {
reportId: report.report_id,
projectId: report.project_id,
projectName: report.project_name,
projectCode: report.project_code,
authorId: report.author_id,
authorName: report.author_name,
reportYear: report.report_year,
reportWeek: report.report_week,
weekStartDate: report.week_start_date,
weekEndDate: report.week_end_date,
workDescription: report.work_description,
planDescription: report.plan_description,
issueDescription: report.issue_description,
remarkDescription: report.remark_description,
workHours: report.work_hours,
reportStatus: report.report_status,
submittedAt: report.submitted_at,
createdAt: report.created_at,
updatedAt: report.updated_at
}
})

View File

@@ -0,0 +1,37 @@
import { execute, queryOne } from '../../../../utils/db'
/**
* 주간보고 제출
* POST /api/report/weekly/[id]/submit
*/
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 * FROM wr_weekly_report_detail WHERE report_id = $1
`, [reportId])
if (!report) {
throw createError({ statusCode: 404, message: '보고서를 찾을 수 없습니다.' })
}
if (report.author_id !== parseInt(userId)) {
throw createError({ statusCode: 403, message: '본인의 보고서만 제출할 수 있습니다.' })
}
await execute(`
UPDATE wr_weekly_report_detail SET
report_status = 'SUBMITTED',
submitted_at = NOW(),
updated_at = NOW()
WHERE report_id = $1
`, [reportId])
return { success: true }
})

View File

@@ -0,0 +1,56 @@
import { execute, queryOne } from '../../../../utils/db'
interface UpdateReportBody {
workDescription?: string
planDescription?: string
issueDescription?: string
remarkDescription?: string
workHours?: number
}
/**
* 주간보고 수정
* PUT /api/report/weekly/[id]/update
*/
export default defineEventHandler(async (event) => {
const userId = getCookie(event, 'user_id')
if (!userId) {
throw createError({ statusCode: 401, message: '로그인이 필요합니다.' })
}
const reportId = getRouterParam(event, 'id')
const body = await readBody<UpdateReportBody>(event)
// 보고서 조회 및 권한 확인
const report = await queryOne<any>(`
SELECT * FROM wr_weekly_report_detail WHERE report_id = $1
`, [reportId])
if (!report) {
throw createError({ statusCode: 404, message: '보고서를 찾을 수 없습니다.' })
}
if (report.author_id !== parseInt(userId)) {
throw createError({ statusCode: 403, message: '본인의 보고서만 수정할 수 있습니다.' })
}
await execute(`
UPDATE wr_weekly_report_detail SET
work_description = $1,
plan_description = $2,
issue_description = $3,
remark_description = $4,
work_hours = $5,
updated_at = NOW()
WHERE report_id = $6
`, [
body.workDescription ?? report.work_description,
body.planDescription ?? report.plan_description,
body.issueDescription ?? report.issue_description,
body.remarkDescription ?? report.remark_description,
body.workHours ?? report.work_hours,
reportId
])
return { success: true }
})