-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
146 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"/api/*": | ||
{ | ||
"target": "https://iot-flasher.thingpulse.com/", | ||
"secure": false, | ||
"logLevel": "debug", | ||
"changeOrigin": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,5 @@ | ||
export interface FirmwareMessage { | ||
heapSize: number; | ||
freeHeap: number; | ||
psramSize: number; | ||
freePsram: number; | ||
buildTime: string; | ||
buildDate: string; | ||
name: string; | ||
value: string; | ||
result: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export interface TestResult { | ||
mac_address: string; | ||
overall_result: 'OK' | 'NOK'; | ||
device_type: string; | ||
[key: string]: any; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { TestResultService } from './test-result.service'; | ||
|
||
describe('TestResultService', () => { | ||
let service: TestResultService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(TestResultService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { HttpClient, HttpHeaders } from '@angular/common/http'; | ||
import { Observable, of } from 'rxjs'; | ||
import { catchError } from 'rxjs/operators'; | ||
import { TestResult } from '../model/test-result'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class TestResultService { | ||
|
||
private apiUrl = '/api/rest.php'; // Update with your actual API endpoint | ||
private apiKey = 'yourkey'; // Replace with your generated API key | ||
|
||
constructor(private http: HttpClient) { } | ||
|
||
sendTestResult(result: TestResult): Observable<any> { | ||
const headers = new HttpHeaders({ | ||
'Content-Type': 'application/json', | ||
'Authorization': `Bearer ${this.apiKey}` | ||
}); | ||
return this.http.post<any>(this.apiUrl, result, { headers: headers }) | ||
.pipe( | ||
catchError(this.handleError<any>('sendTestResult')) | ||
); | ||
} | ||
|
||
private handleError<T>(operation = 'operation', result?: T) { | ||
return (error: any): Observable<T> => { | ||
console.error(error); // Log the error for debugging purposes | ||
// Let the app continue by returning an empty result. | ||
return of(result as T); | ||
}; | ||
} | ||
} |