추가
This commit is contained in:
65
backend/api/report/summary/[id]/detail.get.ts
Normal file
65
backend/api/report/summary/[id]/detail.get.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import { queryOne, query } from '../../../../utils/db'
|
||||
|
||||
/**
|
||||
* 취합 보고서 상세 (개별 보고서 포함)
|
||||
* GET /api/report/summary/[id]/detail
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
const summaryId = getRouterParam(event, 'id')
|
||||
|
||||
// 취합 보고서 조회
|
||||
const summary = await queryOne<any>(`
|
||||
SELECT s.*, p.project_name, p.project_code,
|
||||
e.employee_name as reviewer_name
|
||||
FROM wr_aggregated_report_summary s
|
||||
JOIN wr_project_info p ON s.project_id = p.project_id
|
||||
LEFT JOIN wr_employee_info e ON s.reviewer_id = e.employee_id
|
||||
WHERE s.summary_id = $1
|
||||
`, [summaryId])
|
||||
|
||||
if (!summary) {
|
||||
throw createError({ statusCode: 404, message: '취합 보고서를 찾을 수 없습니다.' })
|
||||
}
|
||||
|
||||
// 개별 보고서 목록
|
||||
const reports = await query(`
|
||||
SELECT r.*, e.employee_name as author_name, e.employee_position
|
||||
FROM wr_weekly_report_detail r
|
||||
JOIN wr_employee_info e ON r.author_id = e.employee_id
|
||||
WHERE r.project_id = $1 AND r.report_year = $2 AND r.report_week = $3
|
||||
ORDER BY e.employee_name
|
||||
`, [summary.project_id, summary.report_year, summary.report_week])
|
||||
|
||||
return {
|
||||
summary: {
|
||||
summaryId: summary.summary_id,
|
||||
projectId: summary.project_id,
|
||||
projectName: summary.project_name,
|
||||
projectCode: summary.project_code,
|
||||
reportYear: summary.report_year,
|
||||
reportWeek: summary.report_week,
|
||||
weekStartDate: summary.week_start_date,
|
||||
weekEndDate: summary.week_end_date,
|
||||
memberCount: summary.member_count,
|
||||
totalWorkHours: summary.total_work_hours,
|
||||
reviewerId: summary.reviewer_id,
|
||||
reviewerName: summary.reviewer_name,
|
||||
reviewerComment: summary.reviewer_comment,
|
||||
reviewedAt: summary.reviewed_at,
|
||||
summaryStatus: summary.summary_status
|
||||
},
|
||||
reports: reports.map((r: any) => ({
|
||||
reportId: r.report_id,
|
||||
authorId: r.author_id,
|
||||
authorName: r.author_name,
|
||||
authorPosition: r.employee_position,
|
||||
workDescription: r.work_description,
|
||||
planDescription: r.plan_description,
|
||||
issueDescription: r.issue_description,
|
||||
remarkDescription: r.remark_description,
|
||||
workHours: r.work_hours,
|
||||
reportStatus: r.report_status,
|
||||
submittedAt: r.submitted_at
|
||||
}))
|
||||
}
|
||||
})
|
||||
39
backend/api/report/summary/[id]/review.put.ts
Normal file
39
backend/api/report/summary/[id]/review.put.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { execute, queryOne } from '../../../../utils/db'
|
||||
|
||||
interface ReviewBody {
|
||||
reviewerComment?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* PM 검토/코멘트 작성
|
||||
* PUT /api/report/summary/[id]/review
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
const userId = getCookie(event, 'user_id')
|
||||
if (!userId) {
|
||||
throw createError({ statusCode: 401, message: '로그인이 필요합니다.' })
|
||||
}
|
||||
|
||||
const summaryId = getRouterParam(event, 'id')
|
||||
const body = await readBody<ReviewBody>(event)
|
||||
|
||||
const summary = await queryOne<any>(`
|
||||
SELECT * FROM wr_aggregated_report_summary WHERE summary_id = $1
|
||||
`, [summaryId])
|
||||
|
||||
if (!summary) {
|
||||
throw createError({ statusCode: 404, message: '취합 보고서를 찾을 수 없습니다.' })
|
||||
}
|
||||
|
||||
await execute(`
|
||||
UPDATE wr_aggregated_report_summary SET
|
||||
reviewer_id = $1,
|
||||
reviewer_comment = $2,
|
||||
reviewed_at = NOW(),
|
||||
summary_status = 'REVIEWED',
|
||||
updated_at = NOW()
|
||||
WHERE summary_id = $3
|
||||
`, [parseInt(userId), body.reviewerComment || null, summaryId])
|
||||
|
||||
return { success: true }
|
||||
})
|
||||
54
backend/api/report/summary/list.get.ts
Normal file
54
backend/api/report/summary/list.get.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { query } from '../../../utils/db'
|
||||
|
||||
/**
|
||||
* 취합 보고서 목록
|
||||
* GET /api/report/summary/list
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
const queryParams = getQuery(event)
|
||||
const projectId = queryParams.projectId ? parseInt(queryParams.projectId as string) : null
|
||||
const year = queryParams.year ? parseInt(queryParams.year as string) : null
|
||||
|
||||
let sql = `
|
||||
SELECT s.*, p.project_name, p.project_code,
|
||||
e.employee_name as reviewer_name
|
||||
FROM wr_aggregated_report_summary s
|
||||
JOIN wr_project_info p ON s.project_id = p.project_id
|
||||
LEFT JOIN wr_employee_info e ON s.reviewer_id = e.employee_id
|
||||
WHERE 1=1
|
||||
`
|
||||
const params: any[] = []
|
||||
let paramIndex = 1
|
||||
|
||||
if (projectId) {
|
||||
sql += ` AND s.project_id = $${paramIndex++}`
|
||||
params.push(projectId)
|
||||
}
|
||||
if (year) {
|
||||
sql += ` AND s.report_year = $${paramIndex++}`
|
||||
params.push(year)
|
||||
}
|
||||
|
||||
sql += ' ORDER BY s.report_year DESC, s.report_week DESC, p.project_name'
|
||||
|
||||
const summaries = await query(sql, params)
|
||||
|
||||
return summaries.map((s: any) => ({
|
||||
summaryId: s.summary_id,
|
||||
projectId: s.project_id,
|
||||
projectName: s.project_name,
|
||||
projectCode: s.project_code,
|
||||
reportYear: s.report_year,
|
||||
reportWeek: s.report_week,
|
||||
weekStartDate: s.week_start_date,
|
||||
weekEndDate: s.week_end_date,
|
||||
memberCount: s.member_count,
|
||||
totalWorkHours: s.total_work_hours,
|
||||
reviewerId: s.reviewer_id,
|
||||
reviewerName: s.reviewer_name,
|
||||
reviewerComment: s.reviewer_comment,
|
||||
reviewedAt: s.reviewed_at,
|
||||
summaryStatus: s.summary_status,
|
||||
aggregatedAt: s.aggregated_at
|
||||
}))
|
||||
})
|
||||
48
backend/api/report/weekly/[id]/detail.get.ts
Normal file
48
backend/api/report/weekly/[id]/detail.get.ts
Normal 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
|
||||
}
|
||||
})
|
||||
37
backend/api/report/weekly/[id]/submit.post.ts
Normal file
37
backend/api/report/weekly/[id]/submit.post.ts
Normal 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 }
|
||||
})
|
||||
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 }
|
||||
})
|
||||
75
backend/api/report/weekly/create.post.ts
Normal file
75
backend/api/report/weekly/create.post.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import { insertReturning, queryOne } from '../../../utils/db'
|
||||
import { getWeekInfo } from '../../../utils/week-calc'
|
||||
|
||||
interface CreateReportBody {
|
||||
projectId: number
|
||||
reportYear?: number
|
||||
reportWeek?: number
|
||||
workDescription?: string
|
||||
planDescription?: string
|
||||
issueDescription?: string
|
||||
remarkDescription?: string
|
||||
workHours?: number
|
||||
}
|
||||
|
||||
/**
|
||||
* 주간보고 작성
|
||||
* POST /api/report/weekly/create
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
const userId = getCookie(event, 'user_id')
|
||||
if (!userId) {
|
||||
throw createError({ statusCode: 401, message: '로그인이 필요합니다.' })
|
||||
}
|
||||
|
||||
const body = await readBody<CreateReportBody>(event)
|
||||
|
||||
if (!body.projectId) {
|
||||
throw createError({ statusCode: 400, message: '프로젝트를 선택해주세요.' })
|
||||
}
|
||||
|
||||
// 주차 정보 (기본값: 이번 주)
|
||||
const weekInfo = getWeekInfo()
|
||||
const year = body.reportYear || weekInfo.year
|
||||
const week = body.reportWeek || weekInfo.week
|
||||
|
||||
// 중복 체크
|
||||
const existing = await queryOne(`
|
||||
SELECT report_id FROM wr_weekly_report_detail
|
||||
WHERE project_id = $1 AND author_id = $2 AND report_year = $3 AND report_week = $4
|
||||
`, [body.projectId, parseInt(userId), year, week])
|
||||
|
||||
if (existing) {
|
||||
throw createError({ statusCode: 409, message: '이미 해당 주차 보고서가 존재합니다.' })
|
||||
}
|
||||
|
||||
// 주차 날짜 계산
|
||||
const dates = getWeekInfo(new Date(year, 0, 4 + (week - 1) * 7))
|
||||
|
||||
const report = await insertReturning(`
|
||||
INSERT INTO wr_weekly_report_detail (
|
||||
project_id, author_id, report_year, report_week,
|
||||
week_start_date, week_end_date,
|
||||
work_description, plan_description, issue_description, remark_description,
|
||||
work_hours, report_status
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, 'DRAFT')
|
||||
RETURNING *
|
||||
`, [
|
||||
body.projectId,
|
||||
parseInt(userId),
|
||||
year,
|
||||
week,
|
||||
dates.startDateStr,
|
||||
dates.endDateStr,
|
||||
body.workDescription || null,
|
||||
body.planDescription || null,
|
||||
body.issueDescription || null,
|
||||
body.remarkDescription || null,
|
||||
body.workHours || null
|
||||
])
|
||||
|
||||
return {
|
||||
success: true,
|
||||
reportId: report.report_id
|
||||
}
|
||||
})
|
||||
46
backend/api/report/weekly/current-week.get.ts
Normal file
46
backend/api/report/weekly/current-week.get.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { query } from '../../../utils/db'
|
||||
import { getWeekInfo, formatWeekString } from '../../../utils/week-calc'
|
||||
|
||||
/**
|
||||
* 이번 주 보고서 현황 조회
|
||||
* GET /api/report/weekly/current-week
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
const userId = getCookie(event, 'user_id')
|
||||
if (!userId) {
|
||||
throw createError({ statusCode: 401, message: '로그인이 필요합니다.' })
|
||||
}
|
||||
|
||||
const weekInfo = getWeekInfo()
|
||||
|
||||
// 이번 주 내 보고서 목록
|
||||
const reports = await query(`
|
||||
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
|
||||
WHERE r.author_id = $1 AND r.report_year = $2 AND r.report_week = $3
|
||||
ORDER BY p.project_name
|
||||
`, [parseInt(userId), weekInfo.year, weekInfo.week])
|
||||
|
||||
return {
|
||||
weekInfo: {
|
||||
year: weekInfo.year,
|
||||
week: weekInfo.week,
|
||||
weekString: formatWeekString(weekInfo.year, weekInfo.week),
|
||||
startDate: weekInfo.startDateStr,
|
||||
endDate: weekInfo.endDateStr
|
||||
},
|
||||
reports: reports.map((r: any) => ({
|
||||
reportId: r.report_id,
|
||||
projectId: r.project_id,
|
||||
projectName: r.project_name,
|
||||
projectCode: r.project_code,
|
||||
reportStatus: r.report_status,
|
||||
workDescription: r.work_description,
|
||||
planDescription: r.plan_description,
|
||||
issueDescription: r.issue_description,
|
||||
workHours: r.work_hours,
|
||||
updatedAt: r.updated_at
|
||||
}))
|
||||
}
|
||||
})
|
||||
60
backend/api/report/weekly/list.get.ts
Normal file
60
backend/api/report/weekly/list.get.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { query } from '../../../utils/db'
|
||||
|
||||
/**
|
||||
* 내 주간보고 목록
|
||||
* GET /api/report/weekly/list
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
const userId = getCookie(event, 'user_id')
|
||||
if (!userId) {
|
||||
throw createError({ statusCode: 401, message: '로그인이 필요합니다.' })
|
||||
}
|
||||
|
||||
const queryParams = getQuery(event)
|
||||
const year = queryParams.year ? parseInt(queryParams.year as string) : null
|
||||
const projectId = queryParams.projectId ? parseInt(queryParams.projectId as string) : null
|
||||
|
||||
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
|
||||
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)
|
||||
|
||||
return {
|
||||
reports: reports.map((r: any) => ({
|
||||
reportId: r.report_id,
|
||||
projectId: r.project_id,
|
||||
projectName: r.project_name,
|
||||
projectCode: r.project_code,
|
||||
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,
|
||||
reportStatus: r.report_status,
|
||||
submittedAt: r.submitted_at,
|
||||
createdAt: r.created_at,
|
||||
updatedAt: r.updated_at
|
||||
}))
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user