cic-staff-client/src/app/_services/user.service.ts

117 lines
3.9 KiB
TypeScript
Raw Normal View History

import { Injectable } from '@angular/core';
2020-12-05 07:29:18 +01:00
import {BehaviorSubject, Observable} from 'rxjs';
import {HttpClient, HttpParams} from '@angular/common/http';
import {environment} from '../../environments/environment';
2020-12-05 07:29:18 +01:00
import {first, map} from 'rxjs/operators';
import {} from '../../assets/js/cic-meta/sync';
@Injectable({
providedIn: 'root'
})
export class UserService {
2020-12-05 07:29:18 +01:00
accounts: any = '';
private accountsList = new BehaviorSubject<any>(this.accounts);
accountsSubject = this.accountsList.asObservable();
actions: any = '';
private actionsList = new BehaviorSubject<any>(this.actions);
actionsSubject = this.actionsList.asObservable();
staff: any = '';
private staffList = new BehaviorSubject<any>(this.staff);
staffSubject = this.staffList.asObservable();
constructor(private http: HttpClient) { }
2021-02-08 12:47:07 +01:00
resetPin(phone: string): Observable<any> {
const params = new HttpParams().set('phoneNumber', phone);
return this.http.get(`${environment.cicUssdUrl}/pin`, { params });
}
createAccount(accountType: string, idNumber: string, phoneNumber: string, givenName: string, surname: string, directoryEntry: string,
location: string, gender: string, referrer: string, businessCategory: string): Observable<any> {
console.log(accountType);
return this.http.post(
`${environment.cicUssdUrl}/user`,
{
accountType: accountType,
idNumber: idNumber,
phone: phoneNumber,
givenName: givenName,
surname: surname,
directoryEntry: directoryEntry,
location: location,
gender: gender,
referrer: referrer,
businessCategory: businessCategory
}
);
}
changeAccountInfo(status: string, name: string, phoneNumber: string, type: string, token: string, failedPinAttempts: string, bio: string,
gender: string, businessCategory: string, userLocation: string, location: string, referrer: string): Observable<any> {
console.log(status);
return ;
}
2020-12-05 07:29:18 +01:00
getAccounts(): void {
this.http.get(`${environment.cicCacheUrl}/accounts`).pipe(first()).subscribe(accounts => this.accountsList.next(accounts));
}
2020-12-05 07:29:18 +01:00
getAccountById(id: number): Observable<any> {
return this.http.get(`${environment.cicCacheUrl}/accounts/${id}`);
}
getActions(): void {
this.http.get(`${environment.cicCacheUrl}/actions`).pipe(first()).subscribe(actions => this.actionsList.next(actions));
}
getActionById(id: string): any {
2020-12-05 07:29:18 +01:00
return this.http.get(`${environment.cicCacheUrl}/actions/${id}`);
}
approveAction(id: string): Observable<any> {
return this.http.post(`${environment.cicCacheUrl}/actions/${id}`, { approval: true });
}
revokeAction(id: string): Observable<any> {
return this.http.post(`${environment.cicCacheUrl}/actions/${id}`, { approval: false });
}
getHistoryByUser(id: string): Observable<any> {
return this.http.get(`${environment.cicCacheUrl}/history/${id}`);
}
getStaff(): void {
this.http.get(`${environment.cicCacheUrl}/staff`).pipe(first()).subscribe(staff => this.staffList.next(staff));
}
getStaffById(id: string): Observable<any> {
return this.http.get(`${environment.cicCacheUrl}/staff/${id}`);
}
activateStaff(id: string): Observable<any> {
return this.http.post(`${environment.cicCacheUrl}/staff/${id}`, {status: 'activated'});
}
2020-12-05 07:29:18 +01:00
deactivateStaff(id: string): Observable<any> {
return this.http.post(`${environment.cicCacheUrl}/staff/${id}`, {status: 'deactivated'});
}
2020-12-05 07:29:18 +01:00
changeStaffType(id: string, type: string): Observable<any> {
return this.http.post(`${environment.cicCacheUrl}/staff/${id}`, {accountType: type});
}
getUser(userKey: string): Observable<any> {
const params = new HttpParams().set('userKey', '0970c6e9cdad650ba9006e5a1caf090a13da312792389a147263c98ac78cd037');
return this.http.get(`${environment.cicScriptsUrl}`, { params })
.pipe(map(response => {
return response;
}));
}
changeUserCredentials(): void {
}
}