추가
This commit is contained in:
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
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user