추가
This commit is contained in:
30
backend/api/employee/[id]/detail.get.ts
Normal file
30
backend/api/employee/[id]/detail.get.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { queryOne } from '../../../utils/db'
|
||||
|
||||
/**
|
||||
* 사원 상세 조회
|
||||
* GET /api/employee/[id]/detail
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
const employeeId = getRouterParam(event, 'id')
|
||||
|
||||
const employee = await queryOne<any>(`
|
||||
SELECT * FROM wr_employee_info WHERE employee_id = $1
|
||||
`, [employeeId])
|
||||
|
||||
if (!employee) {
|
||||
throw createError({ statusCode: 404, message: '사원을 찾을 수 없습니다.' })
|
||||
}
|
||||
|
||||
return {
|
||||
employeeId: employee.employee_id,
|
||||
employeeNumber: employee.employee_number,
|
||||
employeeName: employee.employee_name,
|
||||
employeeEmail: employee.employee_email,
|
||||
employeePhone: employee.employee_phone,
|
||||
employeePosition: employee.employee_position,
|
||||
joinDate: employee.join_date,
|
||||
isActive: employee.is_active,
|
||||
createdAt: employee.created_at,
|
||||
updatedAt: employee.updated_at
|
||||
}
|
||||
})
|
||||
49
backend/api/employee/[id]/update.put.ts
Normal file
49
backend/api/employee/[id]/update.put.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { execute, queryOne } from '../../../utils/db'
|
||||
|
||||
interface UpdateEmployeeBody {
|
||||
employeeNumber?: string
|
||||
employeeName?: string
|
||||
employeePhone?: string
|
||||
employeePosition?: string
|
||||
joinDate?: string
|
||||
isActive?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* 사원 정보 수정
|
||||
* PUT /api/employee/[id]/update
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
const employeeId = getRouterParam(event, 'id')
|
||||
const body = await readBody<UpdateEmployeeBody>(event)
|
||||
|
||||
const existing = await queryOne<any>(`
|
||||
SELECT * FROM wr_employee_info WHERE employee_id = $1
|
||||
`, [employeeId])
|
||||
|
||||
if (!existing) {
|
||||
throw createError({ statusCode: 404, message: '사원을 찾을 수 없습니다.' })
|
||||
}
|
||||
|
||||
await execute(`
|
||||
UPDATE wr_employee_info SET
|
||||
employee_number = $1,
|
||||
employee_name = $2,
|
||||
employee_phone = $3,
|
||||
employee_position = $4,
|
||||
join_date = $5,
|
||||
is_active = $6,
|
||||
updated_at = NOW()
|
||||
WHERE employee_id = $7
|
||||
`, [
|
||||
body.employeeNumber ?? existing.employee_number,
|
||||
body.employeeName ?? existing.employee_name,
|
||||
body.employeePhone ?? existing.employee_phone,
|
||||
body.employeePosition ?? existing.employee_position,
|
||||
body.joinDate ?? existing.join_date,
|
||||
body.isActive ?? existing.is_active,
|
||||
employeeId
|
||||
])
|
||||
|
||||
return { success: true }
|
||||
})
|
||||
55
backend/api/employee/create.post.ts
Normal file
55
backend/api/employee/create.post.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { insertReturning, queryOne } from '../../utils/db'
|
||||
|
||||
interface CreateEmployeeBody {
|
||||
employeeNumber?: string
|
||||
employeeName: string
|
||||
employeeEmail: string
|
||||
employeePhone?: string
|
||||
employeePosition?: string
|
||||
joinDate?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 사원 등록
|
||||
* POST /api/employee/create
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody<CreateEmployeeBody>(event)
|
||||
|
||||
if (!body.employeeName || !body.employeeEmail) {
|
||||
throw createError({ statusCode: 400, message: '이름과 이메일은 필수입니다.' })
|
||||
}
|
||||
|
||||
// 이메일 중복 체크
|
||||
const existing = await queryOne(`
|
||||
SELECT employee_id FROM wr_employee_info WHERE employee_email = $1
|
||||
`, [body.employeeEmail.toLowerCase()])
|
||||
|
||||
if (existing) {
|
||||
throw createError({ statusCode: 409, message: '이미 등록된 이메일입니다.' })
|
||||
}
|
||||
|
||||
const employee = await insertReturning(`
|
||||
INSERT INTO wr_employee_info (
|
||||
employee_number, employee_name, employee_email,
|
||||
employee_phone, employee_position, join_date
|
||||
) VALUES ($1, $2, $3, $4, $5, $6)
|
||||
RETURNING *
|
||||
`, [
|
||||
body.employeeNumber || null,
|
||||
body.employeeName,
|
||||
body.employeeEmail.toLowerCase(),
|
||||
body.employeePhone || null,
|
||||
body.employeePosition || null,
|
||||
body.joinDate || null
|
||||
])
|
||||
|
||||
return {
|
||||
success: true,
|
||||
employee: {
|
||||
employeeId: employee.employee_id,
|
||||
employeeName: employee.employee_name,
|
||||
employeeEmail: employee.employee_email
|
||||
}
|
||||
}
|
||||
})
|
||||
30
backend/api/employee/list.get.ts
Normal file
30
backend/api/employee/list.get.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { query } from '../../utils/db'
|
||||
|
||||
/**
|
||||
* 사원 목록 조회
|
||||
* GET /api/employee/list
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
const queryParams = getQuery(event)
|
||||
const activeOnly = queryParams.activeOnly !== 'false'
|
||||
|
||||
let sql = `
|
||||
SELECT * FROM wr_employee_info
|
||||
${activeOnly ? 'WHERE is_active = true' : ''}
|
||||
ORDER BY employee_name
|
||||
`
|
||||
|
||||
const employees = await query(sql)
|
||||
|
||||
return employees.map((e: any) => ({
|
||||
employeeId: e.employee_id,
|
||||
employeeNumber: e.employee_number,
|
||||
employeeName: e.employee_name,
|
||||
employeeEmail: e.employee_email,
|
||||
employeePhone: e.employee_phone,
|
||||
employeePosition: e.employee_position,
|
||||
joinDate: e.join_date,
|
||||
isActive: e.is_active,
|
||||
createdAt: e.created_at
|
||||
}))
|
||||
})
|
||||
29
backend/api/employee/search.get.ts
Normal file
29
backend/api/employee/search.get.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { query } from '../../utils/db'
|
||||
|
||||
/**
|
||||
* 사원 검색 (이름/이메일)
|
||||
* GET /api/employee/search?q=keyword
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
const queryParams = getQuery(event)
|
||||
const keyword = queryParams.q as string
|
||||
|
||||
if (!keyword || keyword.length < 1) {
|
||||
return []
|
||||
}
|
||||
|
||||
const employees = await query(`
|
||||
SELECT * FROM wr_employee_info
|
||||
WHERE is_active = true
|
||||
AND (employee_name ILIKE $1 OR employee_email ILIKE $1)
|
||||
ORDER BY employee_name
|
||||
LIMIT 20
|
||||
`, [`%${keyword}%`])
|
||||
|
||||
return employees.map((e: any) => ({
|
||||
employeeId: e.employee_id,
|
||||
employeeName: e.employee_name,
|
||||
employeeEmail: e.employee_email,
|
||||
employeePosition: e.employee_position
|
||||
}))
|
||||
})
|
||||
Reference in New Issue
Block a user