import {HttpClient} from '@angular/common/http'; import {AuthService} from './auth.service'; import {Observable} from 'rxjs'; import {LoanModel} from '../models/loan.model'; import {Injectable} from '@angular/core'; import {RewardModel} from '../models/reward.model'; import {ClonerService} from './clone.service'; import {PayInModel} from '../models/pay-in.model'; @Injectable() export class LoanSingleService { constructor(private http: HttpClient, private auth: AuthService, private dcs: ClonerService ){ } getLoan(loanId: string): Observable { return this.http.get(this.auth.getUrl('loan/' + loanId)); } public updateBasicInfo(loan: LoanModel): Observable{ return this.http.post(this.auth.getUrl('loan/basic/' + loan.Id), loan.cloneForJson()); } public photoUrl(peopleId: string): string{ const url = this.auth.getUrl('avatar/') + peopleId; return 'url("' + url + '")'; } public saveReward(reward: RewardModel, isNew: boolean ): Observable { return this.http.post(this.auth.getUrl('reward/'), reward); } public removeReward(reward: RewardModel): void { this.http.delete(this.auth.getUrl('reward/' + reward.Id)).subscribe( resp => { console.log(resp); } ); } public savePayIn(payIn: PayInModel, isNew: boolean): Observable { return this.http.post(this.auth.getUrl('payIn/'), payIn); } public removePayIn(id: number): void { this.http.delete(this.auth.getUrl('payIn/' + id)).subscribe( resp => { console.log(resp); } ); } // delete means more than remove, it removes relevant data too public deleteLoan(id: string): Observable { return this.http.delete(this.auth.getUrl('loan/' + id)); } }