Skip to content
Snippets Groups Projects
Commit 455247ec authored by David Stäheli's avatar David Stäheli
Browse files

update account service

parent ac188f36
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ import { catchError, map } from 'rxjs/operators';
import { ResourceBase } from '@app/core';
import { TransactionList, Transaction } from '../models/transaction';
import { TransactionQuery } from '../models/transaction-query';
import { Account } from '../models/account';
@Injectable()
export class TransactionResourceService extends ResourceBase {
......@@ -14,9 +15,24 @@ export class TransactionResourceService extends ResourceBase {
super(http);
}
public getAccounts(): Observable<any> {
public getAccountById(id: string): Observable<Account | null> {
return this.get(`/accounts/${id}`).pipe(
map((data: Account) => {
if (data) {
return data;
}
return null;
}),
catchError((error: any) =>
// TODO Send to Err service
of(null)
)
);
}
public getAccounts(): Observable<Account | null> {
return this.get('/accounts').pipe(
map((data: any) => {
map((data: Account) => {
if (data) {
return data;
}
......
import { TestBed } from '@angular/core/testing';
import { AccountsService } from './accounts.service';
describe('AccountsService', () => {
let service: AccountsService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(AccountsService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
import { Injectable } from '@angular/core';
import { TransactionResourceService } from '../resources/transaction-resource.service';
import { Observable } from 'rxjs';
import { Account } from '../models/account';
@Injectable()
export class AccountsService {
constructor(private transactionService: TransactionResourceService) { }
getOwn(): Observable<Account | null>{
return this.transactionService.getAccounts();
}
getAccount(id: string): Observable<Account | null>{
return this.transactionService.getAccountById(id);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment