기능구현중
This commit is contained in:
23
server/api/todo/[id]/complete.put.ts
Normal file
23
server/api/todo/[id]/complete.put.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { execute } from '../../../utils/db'
|
||||
import { requireAuth } from '../../../utils/session'
|
||||
|
||||
/**
|
||||
* TODO 완료 처리
|
||||
* PUT /api/todo/[id]/complete
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
await requireAuth(event)
|
||||
const todoId = parseInt(event.context.params?.id || '0')
|
||||
|
||||
if (!todoId) {
|
||||
throw createError({ statusCode: 400, message: 'TODO ID가 필요합니다.' })
|
||||
}
|
||||
|
||||
await execute(`
|
||||
UPDATE wr_todo
|
||||
SET status = 'COMPLETED', completed_at = NOW(), updated_at = NOW()
|
||||
WHERE todo_id = $1
|
||||
`, [todoId])
|
||||
|
||||
return { success: true, message: '완료 처리되었습니다.' }
|
||||
})
|
||||
18
server/api/todo/[id]/delete.delete.ts
Normal file
18
server/api/todo/[id]/delete.delete.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { execute, queryOne } from '../../../utils/db'
|
||||
|
||||
/**
|
||||
* TODO 삭제
|
||||
* DELETE /api/todo/[id]/delete
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
const todoId = Number(getRouterParam(event, 'id'))
|
||||
|
||||
const existing = await queryOne('SELECT * FROM wr_todo WHERE todo_id = $1', [todoId])
|
||||
if (!existing) {
|
||||
throw createError({ statusCode: 404, message: 'TODO를 찾을 수 없습니다.' })
|
||||
}
|
||||
|
||||
await execute('DELETE FROM wr_todo WHERE todo_id = $1', [todoId])
|
||||
|
||||
return { success: true, message: 'TODO가 삭제되었습니다.' }
|
||||
})
|
||||
53
server/api/todo/[id]/detail.get.ts
Normal file
53
server/api/todo/[id]/detail.get.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { queryOne } from '../../../utils/db'
|
||||
|
||||
/**
|
||||
* TODO 상세 조회
|
||||
* GET /api/todo/[id]/detail
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
const todoId = Number(getRouterParam(event, 'id'))
|
||||
|
||||
const todo = await queryOne(`
|
||||
SELECT
|
||||
t.*,
|
||||
p.project_name,
|
||||
m.meeting_title,
|
||||
a.employee_name as assignee_name,
|
||||
r.employee_name as reporter_name
|
||||
FROM wr_todo t
|
||||
LEFT JOIN wr_project_info p ON t.project_id = p.project_id
|
||||
LEFT JOIN wr_meeting m ON t.meeting_id = m.meeting_id
|
||||
LEFT JOIN wr_employee_info a ON t.assignee_id = a.employee_id
|
||||
LEFT JOIN wr_employee_info r ON t.reporter_id = r.employee_id
|
||||
WHERE t.todo_id = $1
|
||||
`, [todoId])
|
||||
|
||||
if (!todo) {
|
||||
throw createError({ statusCode: 404, message: 'TODO를 찾을 수 없습니다.' })
|
||||
}
|
||||
|
||||
return {
|
||||
todo: {
|
||||
todoId: todo.todo_id,
|
||||
todoTitle: todo.todo_title,
|
||||
todoContent: todo.todo_content,
|
||||
sourceType: todo.source_type,
|
||||
sourceId: todo.source_id,
|
||||
meetingId: todo.meeting_id,
|
||||
meetingTitle: todo.meeting_title,
|
||||
projectId: todo.project_id,
|
||||
projectName: todo.project_name,
|
||||
assigneeId: todo.assignee_id,
|
||||
assigneeName: todo.assignee_name,
|
||||
reporterId: todo.reporter_id,
|
||||
reporterName: todo.reporter_name,
|
||||
dueDate: todo.due_date,
|
||||
status: todo.status,
|
||||
priority: todo.priority,
|
||||
completedAt: todo.completed_at,
|
||||
weeklyReportId: todo.weekly_report_id,
|
||||
createdAt: todo.created_at,
|
||||
updatedAt: todo.updated_at
|
||||
}
|
||||
}
|
||||
})
|
||||
28
server/api/todo/[id]/discard.put.ts
Normal file
28
server/api/todo/[id]/discard.put.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { execute } from '../../../utils/db'
|
||||
import { requireAuth } from '../../../utils/session'
|
||||
|
||||
interface DiscardBody {
|
||||
reason?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 폐기 처리
|
||||
* PUT /api/todo/[id]/discard
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
await requireAuth(event)
|
||||
const todoId = parseInt(event.context.params?.id || '0')
|
||||
const body = await readBody<DiscardBody>(event)
|
||||
|
||||
if (!todoId) {
|
||||
throw createError({ statusCode: 400, message: 'TODO ID가 필요합니다.' })
|
||||
}
|
||||
|
||||
await execute(`
|
||||
UPDATE wr_todo
|
||||
SET status = 'DISCARDED', discard_reason = $1, updated_at = NOW()
|
||||
WHERE todo_id = $2
|
||||
`, [body.reason || null, todoId])
|
||||
|
||||
return { success: true, message: '폐기 처리되었습니다.' }
|
||||
})
|
||||
84
server/api/todo/[id]/update.put.ts
Normal file
84
server/api/todo/[id]/update.put.ts
Normal file
@@ -0,0 +1,84 @@
|
||||
import { execute, queryOne } from '../../../utils/db'
|
||||
|
||||
interface UpdateTodoBody {
|
||||
todoTitle?: string
|
||||
todoContent?: string
|
||||
projectId?: number | null
|
||||
assigneeId?: number | null
|
||||
dueDate?: string | null
|
||||
status?: string
|
||||
priority?: number
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 수정
|
||||
* PUT /api/todo/[id]/update
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
const todoId = Number(getRouterParam(event, 'id'))
|
||||
const body = await readBody<UpdateTodoBody>(event)
|
||||
|
||||
const existing = await queryOne('SELECT * FROM wr_todo WHERE todo_id = $1', [todoId])
|
||||
if (!existing) {
|
||||
throw createError({ statusCode: 404, message: 'TODO를 찾을 수 없습니다.' })
|
||||
}
|
||||
|
||||
const updates: string[] = []
|
||||
const values: any[] = []
|
||||
let paramIndex = 1
|
||||
|
||||
if (body.todoTitle !== undefined) {
|
||||
updates.push(`todo_title = $${paramIndex++}`)
|
||||
values.push(body.todoTitle)
|
||||
}
|
||||
|
||||
if (body.todoContent !== undefined) {
|
||||
updates.push(`todo_content = $${paramIndex++}`)
|
||||
values.push(body.todoContent)
|
||||
}
|
||||
|
||||
if (body.projectId !== undefined) {
|
||||
updates.push(`project_id = $${paramIndex++}`)
|
||||
values.push(body.projectId)
|
||||
}
|
||||
|
||||
if (body.assigneeId !== undefined) {
|
||||
updates.push(`assignee_id = $${paramIndex++}`)
|
||||
values.push(body.assigneeId)
|
||||
}
|
||||
|
||||
if (body.dueDate !== undefined) {
|
||||
updates.push(`due_date = $${paramIndex++}`)
|
||||
values.push(body.dueDate)
|
||||
}
|
||||
|
||||
if (body.status !== undefined) {
|
||||
updates.push(`status = $${paramIndex++}`)
|
||||
values.push(body.status)
|
||||
|
||||
// 완료 상태로 변경 시 완료일시 기록
|
||||
if (body.status === 'COMPLETED') {
|
||||
updates.push(`completed_at = NOW()`)
|
||||
} else if (existing.status === 'COMPLETED') {
|
||||
updates.push(`completed_at = NULL`)
|
||||
}
|
||||
}
|
||||
|
||||
if (body.priority !== undefined) {
|
||||
updates.push(`priority = $${paramIndex++}`)
|
||||
values.push(body.priority)
|
||||
}
|
||||
|
||||
if (updates.length === 0) {
|
||||
return { success: true, message: '변경된 내용이 없습니다.' }
|
||||
}
|
||||
|
||||
updates.push('updated_at = NOW()')
|
||||
values.push(todoId)
|
||||
|
||||
await execute(`
|
||||
UPDATE wr_todo SET ${updates.join(', ')} WHERE todo_id = $${paramIndex}
|
||||
`, values)
|
||||
|
||||
return { success: true }
|
||||
})
|
||||
Reference in New Issue
Block a user