This commit is contained in:
2026-01-04 20:58:47 +09:00
parent a87c11597a
commit 0660ed3973
37 changed files with 1723 additions and 885 deletions

View File

@@ -1,5 +1,7 @@
import { execute, queryOne, insertReturning } from '../../../utils/db'
import { formatDate } from '../../../utils/week-calc'
import { getClientIp } from '../../../utils/ip'
import { getCurrentUserEmail } from '../../../utils/user'
interface AssignManagerBody {
employeeId: number
@@ -15,6 +17,8 @@ interface AssignManagerBody {
export default defineEventHandler(async (event) => {
const projectId = getRouterParam(event, 'id')
const body = await readBody<AssignManagerBody>(event)
const clientIp = getClientIp(event)
const userEmail = await getCurrentUserEmail(event)
if (!body.employeeId || !body.roleType) {
throw createError({ statusCode: 400, message: '담당자와 역할을 선택해주세요.' })
@@ -31,17 +35,21 @@ export default defineEventHandler(async (event) => {
await execute(`
UPDATE wr_project_manager_history SET
end_date = $1,
change_reason = COALESCE(change_reason || ' / ', '') || '신규 담당자 지정으로 종료'
WHERE project_id = $2 AND role_type = $3 AND end_date IS NULL
`, [startDate, projectId, body.roleType])
change_reason = COALESCE(change_reason || ' / ', '') || '신규 담당자 지정으로 종료',
updated_at = NOW(),
updated_ip = $2,
updated_email = $3
WHERE project_id = $4 AND role_type = $5 AND end_date IS NULL
`, [startDate, clientIp, userEmail, projectId, body.roleType])
// 신규 담당자 등록
const history = await insertReturning(`
INSERT INTO wr_project_manager_history (
project_id, employee_id, role_type, start_date, change_reason
) VALUES ($1, $2, $3, $4, $5)
project_id, employee_id, role_type, start_date, change_reason,
created_ip, created_email, updated_ip, updated_email
) VALUES ($1, $2, $3, $4, $5, $6, $7, $6, $7)
RETURNING *
`, [projectId, body.employeeId, body.roleType, startDate, body.changeReason || null])
`, [projectId, body.employeeId, body.roleType, startDate, body.changeReason || null, clientIp, userEmail])
return {
success: true,