# 测试修复后的员工API
|
Write-Host "测试员工API修复..." -ForegroundColor Green
|
|
# 测试获取员工列表
|
Write-Host "1. 测试获取员工列表..." -ForegroundColor Yellow
|
$getEmployeesQuery = @{
|
query = "query GetEmployees { employees { id name phone roleCode description status createTime updateTime } }"
|
} | ConvertTo-Json -Compress
|
|
try {
|
$response = Invoke-RestMethod -Uri "http://localhost:8080/api/graphql" -Method POST -Body $getEmployeesQuery -ContentType "application/json"
|
Write-Host "获取员工列表成功" -ForegroundColor Green
|
Write-Host "员工数量: $($response.data.employees.Count)" -ForegroundColor Cyan
|
} catch {
|
Write-Host "获取员工列表失败: $($_.Exception.Message)" -ForegroundColor Red
|
}
|
|
# 测试添加员工
|
Write-Host "`n2. 测试添加员工..." -ForegroundColor Yellow
|
$addEmployeeMutation = @{
|
query = "mutation SaveEmployee(`$input: EmployeeInput!) { saveEmployee(input: `$input) { id name phone roleCode description status } }"
|
variables = @{
|
input = @{
|
name = "测试员工API修复"
|
phone = "13800138000"
|
password = "123456"
|
roleCode = "EMPLOYEE"
|
description = "API修复测试员工"
|
}
|
}
|
} | ConvertTo-Json -Compress -Depth 3
|
|
try {
|
$response = Invoke-RestMethod -Uri "http://localhost:8080/api/graphql" -Method POST -Body $addEmployeeMutation -ContentType "application/json"
|
Write-Host "添加员工成功" -ForegroundColor Green
|
$newEmployeeId = $response.data.saveEmployee.id
|
$newEmployeeName = $response.data.saveEmployee.name
|
Write-Host "新员工ID: $newEmployeeId, 姓名: $newEmployeeName" -ForegroundColor Cyan
|
} catch {
|
Write-Host "添加员工失败: $($_.Exception.Message)" -ForegroundColor Red
|
}
|
|
Write-Host "`n员工API修复测试完成!" -ForegroundColor Green
|