추가
This commit is contained in:
56
backend/api/report/weekly/[id]/update.put.ts
Normal file
56
backend/api/report/weekly/[id]/update.put.ts
Normal 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 }
|
||||
})
|
||||
Reference in New Issue
Block a user