기능구현중
This commit is contained in:
62
server/api/employee/create.post.ts
Normal file
62
server/api/employee/create.post.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import { insertReturning, queryOne } from '../../utils/db'
|
||||
import { getClientIp } from '../../utils/ip'
|
||||
import { getCurrentUserEmail } from '../../utils/user'
|
||||
|
||||
interface CreateEmployeeBody {
|
||||
employeeName: string
|
||||
employeeEmail: string
|
||||
employeePhone?: string
|
||||
employeePosition?: string
|
||||
company?: string
|
||||
joinDate?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 직원 등록
|
||||
* POST /api/employee/create
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody<CreateEmployeeBody>(event)
|
||||
const clientIp = getClientIp(event)
|
||||
const userEmail = await getCurrentUserEmail(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_name, employee_email, employee_phone,
|
||||
employee_position, company, join_date,
|
||||
created_ip, created_email, updated_ip, updated_email
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $7, $8)
|
||||
RETURNING *
|
||||
`, [
|
||||
body.employeeName,
|
||||
body.employeeEmail.toLowerCase(),
|
||||
body.employeePhone || null,
|
||||
body.employeePosition || null,
|
||||
body.company || '(주)터보소프트',
|
||||
body.joinDate || null,
|
||||
clientIp,
|
||||
userEmail
|
||||
])
|
||||
|
||||
return {
|
||||
success: true,
|
||||
employee: {
|
||||
employeeId: employee.employee_id,
|
||||
employeeName: employee.employee_name,
|
||||
employeeEmail: employee.employee_email
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user