-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-maintenance.ps1
More file actions
68 lines (56 loc) · 2.4 KB
/
Copy pathrun-maintenance.ps1
File metadata and controls
68 lines (56 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# PowerShell Script to Auto-Close Fully Funded Applications
# This script calls the maintenance endpoint to fix existing data
Write-Host "=====================================" -ForegroundColor Cyan
Write-Host "Auto-Close Fully Funded Applications" -ForegroundColor Cyan
Write-Host "=====================================" -ForegroundColor Cyan
Write-Host ""
# Configuration
$baseUrl = "http://localhost:4000"
$loginEmail = Read-Host "Enter your Trust email"
$loginPassword = Read-Host "Enter your Trust password" -AsSecureString
$loginPasswordPlain = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($loginPassword))
Write-Host ""
Write-Host "Step 1: Logging in..." -ForegroundColor Yellow
# Login to get token
$loginBody = @{
email = $loginEmail
password = $loginPasswordPlain
} | ConvertTo-Json
try {
$loginResponse = Invoke-RestMethod -Uri "$baseUrl/api/auth/login" `
-Method Post `
-Body $loginBody `
-ContentType "application/json"
$token = $loginResponse.token
Write-Host "✅ Login successful!" -ForegroundColor Green
Write-Host ""
} catch {
Write-Host "❌ Login failed: $($_.Exception.Message)" -ForegroundColor Red
exit 1
}
# Call maintenance endpoint
Write-Host "Step 2: Running maintenance to auto-close applications..." -ForegroundColor Yellow
try {
$headers = @{
"Authorization" = "Bearer $token"
}
$maintenanceResponse = Invoke-RestMethod -Uri "$baseUrl/api/trusts/maintenance/auto-close-applications" `
-Method Get `
-Headers $headers
Write-Host "✅ Maintenance completed!" -ForegroundColor Green
Write-Host ""
Write-Host "Results:" -ForegroundColor Cyan
Write-Host " - Applications closed: $($maintenanceResponse.closedApplications)" -ForegroundColor White
Write-Host " - Updated to partially approved: $($maintenanceResponse.updatedToPartiallyApproved)" -ForegroundColor White
Write-Host ""
Write-Host "✅ Done! Refresh your trust dashboard to see the changes." -ForegroundColor Green
} catch {
Write-Host "❌ Maintenance failed: $($_.Exception.Message)" -ForegroundColor Red
Write-Host ""
Write-Host "Error Details:" -ForegroundColor Yellow
Write-Host $_.Exception.Response -ForegroundColor Red
exit 1
}
Write-Host ""
Write-Host "Press any key to exit..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")