Files
cbsnexora/src/app/clients/clients.service.ts
T
Anwesh NayakandGitHub 63925a37c3 feat(client): POST client address && fix(client): fixed sorting and pagination in view clients (#115)
* feat(client): POST client address && fix(client): fixed sorting and pagination in view clients
2018-07-11 06:01:03 +05:30

186 lines
5.4 KiB
TypeScript

import { Injectable } from '@angular/core';
import { Http, Headers, Response, RequestOptions, URLSearchParams } from '@angular/http';
/* import { HttpHeaders, HttpClient } from '@angular/common/http';
*/
import { Observable } from 'rxjs';
import { of } from 'rxjs';
import { map } from 'rxjs/operators';
@Injectable()
export class ClientsService {
constructor(private http: Http) {} // tslint:disable-line
createAuthorizationHeader(headers: Headers) { // tslint:disable-line
const username = 'mifos';
const password = 'password';
headers.append('Authorization', 'Basic ' + btoa(username + ':' + password));
headers.append('Content-Type', 'application/json');
headers.append('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
headers.append('Access-Control-Allow-Origin', '*');
}
getClients() {
const headers = new Headers(); // tslint:disable-line
this.createAuthorizationHeader(headers);
return this.http.get
('https://demo.openmf.org/fineract-provider/api/v1/clients?tenantIdentifier=default&pretty=true',
{headers: headers})
.pipe(
map(
(response: Response) => { // tslint:disable-line
response = response.json();
return response['pageItems'];
}
)
);
}
getClientId(clientId: number) {
const headers = new Headers(); // tslint:disable-line
this.createAuthorizationHeader(headers);
return this.http.get
('https://demo.openmf.org/fineract-provider/api/v1/clients/' + clientId
+ '?tenantIdentifier=default&pretty=true',
{headers: headers})
.pipe(
map(
(response: Response) => { // tslint:disable-line
response = response.json();
return response;
}
)
);
}
getClientAccounts(clientId: number) {
const headers = new Headers(); // tslint:disable-line
this.createAuthorizationHeader(headers);
return this.http.get
('https://demo.openmf.org/fineract-provider/api/v1/clients/' + clientId
+ '/accounts' + '?tenantIdentifier=default&pretty=true',
{headers: headers})
.pipe(
map(
(response: Response) => { // tslint:disable-line
response = response.json();
return response;
}
)
);
}
getClientCharges(clientId: number) {
const headers = new Headers(); // tslint:disable-line
this.createAuthorizationHeader(headers);
return this.http.get
('https://demo.openmf.org/fineract-provider/api/v1/clients/' + clientId
+ '/charges' + '?tenantIdentifier=default&pretty=true',
{headers: headers})
.pipe(
map(
(response: Response) => { // tslint:disable-line
response = response.json();
return response;
}
)
);
}
getClientAddress (clientId: number) {
const headers = new Headers(); // tslint:disable-line
this.createAuthorizationHeader(headers);
return this.http.get
('https://demo.openmf.org/fineract-provider/api/v1/client/' + clientId
+ '/addresses' + '?tenantIdentifier=default&pretty=true',
{headers: headers})
.pipe(
map(
(response: Response) => { // tslint:disable-line
response = response.json();
return response;
}
)
);
}
getClientNote (clientId: number) {
const headers = new Headers(); // tslint:disable-line
this.createAuthorizationHeader(headers);
return this.http.get
('https://demo.openmf.org/fineract-provider/api/v1/clients/' + clientId
+ '/notes' + '?tenantIdentifier=default&pretty=true',
{headers: headers})
.pipe(
map(
(response: Response) => { // tslint:disable-line
response = response.json();
return response;
}
)
);
}
postClientNote (clientId: number, notes: any) {
const headers = new Headers(); // tslint:disable-line
this.createAuthorizationHeader(headers);
const body = JSON.stringify(notes);
return this.http.post
('https://demo.openmf.org/fineract-provider/api/v1/clients/' + clientId
+ '/notes' + '?tenantIdentifier=default&pretty=true', notes ,
{headers: headers})
.pipe(
map(
(response: Response) => { // tslint:disable-line
response.json();
}
)
);
}
getClientAddressTemplate() {
const headers = new Headers(); // tslint:disable-line
this.createAuthorizationHeader(headers);
return this.http.get
('https://demo.openmf.org/fineract-provider/api/v1/client/'
+ 'addresses/template?tenantIdentifier=default',
{headers: headers})
.pipe(
map(
(response: Response) => { // tslint:disable-line
response = response.json();
return response;
}
)
);
}
postClientAddress (clientId: number, body: any, type: any) {
const headers = new Headers(); // tslint:disable-line
const params = new URLSearchParams(); // tslint:disable-line
params.set('type', type);
this.createAuthorizationHeader(headers);
body = JSON.stringify(body);
const options = new RequestOptions({ // tslint:disable-line
headers: headers,
params: params,
});
return this.http.post
('https://demo.openmf.org/fineract-provider/api/v1/client/' + clientId
+ '/addresses?' + '&tenantIdentifier=default&pretty=true', body ,
options)
.pipe(
map(
(response: Response) => { // tslint:disable-line
response.json();
}
)
);
}
}