btc_horse/btc-UI/src/app/service/btc.service.ts

61 lines
1.6 KiB
TypeScript
Executable File

import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { ApplicationHttpRouts } from '../constants/http-routs';
@Injectable({
providedIn: 'root',
})
export class BtcService {
constructor(private http: HttpClient) {}
//user login
public userLogin(employeeId: string, password: string) {
console.log('Login route ' + ApplicationHttpRouts.LOG_IN);
return this.http.get<any>(ApplicationHttpRouts.LOG_IN, {
headers: this.basicAuthCredentialsBuilder(employeeId, password),
withCredentials: true,
observe: 'response',
});
}
// what goes to the backend for auth ... is the same as postman's basic auth
private basicAuthCredentialsBuilder(
employeeOrUserId: string,
password: string
): HttpHeaders {
console.log(`username and password${employeeOrUserId} p = ${password}`);
return new HttpHeaders().set(
'Authorization',
'basic ' + window.btoa(employeeOrUserId + ':' + password)
);
}
public pingLiveStatus() {
return this.http.get<any>(ApplicationHttpRouts.PING, {
withCredentials: true,
observe: 'response',
responseType: 'text' as 'json',
});
}
// Fetch all race events today
public getAllRaceEventsToday() {
return this.http.get<any>(ApplicationHttpRouts.RACE_EVENTS_TODAY, {
withCredentials: true,
observe: 'response',
responseType: 'json',
});
}
public getRaceCard(){
return this.http.get<any>(ApplicationHttpRouts.RACE_CARD, {
withCredentials: true,
observe: 'response',
responseType: 'json',
})
}
}