추가
This commit is contained in:
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