Moved from tslint to eslint as tslint was depreciated.
Added prettier and also prettied all the typescript files using prettier ESLint is using the AirBnB rules which are the most strict to lint the files.
This commit is contained in:
@ -1,31 +1,30 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {catchError} from 'rxjs/operators';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';
|
||||
import {ErrorLoggerService} from './error-logger.service';
|
||||
import {Voucher} from './voucher';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
||||
import { ErrorLoggerService } from './error-logger.service';
|
||||
import { Voucher } from './voucher';
|
||||
|
||||
const httpOptions = {
|
||||
headers: new HttpHeaders({'Content-Type': 'application/json'})
|
||||
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
|
||||
};
|
||||
|
||||
const url = '/api';
|
||||
const serviceName = 'VoucherService';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class VoucherService {
|
||||
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {
|
||||
}
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
|
||||
|
||||
get(id: string, type: string): Observable<Voucher> {
|
||||
const endpoint = type.replace(/ /g, '-').toLowerCase();
|
||||
return <Observable<Voucher>>this.http.get<Voucher>(`${url}/${endpoint}/${id}`)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'Get Voucher'))
|
||||
);
|
||||
return <Observable<Voucher>>(
|
||||
this.http
|
||||
.get<Voucher>(`${url}/${endpoint}/${id}`)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'Get Voucher')))
|
||||
);
|
||||
}
|
||||
|
||||
getOfType(type: string, account?: string): Observable<Voucher> {
|
||||
@ -34,32 +33,36 @@ export class VoucherService {
|
||||
if (account !== undefined && account !== null) {
|
||||
options['params'] = new HttpParams().set('a', account);
|
||||
}
|
||||
return <Observable<Voucher>>this.http.get<Voucher>(`${url}/${endpoint}`, options)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'Get Voucher of Type'))
|
||||
);
|
||||
return <Observable<Voucher>>(
|
||||
this.http
|
||||
.get<Voucher>(`${url}/${endpoint}`, options)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'Get Voucher of Type')))
|
||||
);
|
||||
}
|
||||
|
||||
getIncentive(date: string): Observable<Voucher> {
|
||||
const options = {params: new HttpParams().set('d', date)};
|
||||
return <Observable<Voucher>>this.http.get<Voucher>(`${url}/incentive`, options)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'Get Incentive'))
|
||||
);
|
||||
const options = { params: new HttpParams().set('d', date) };
|
||||
return <Observable<Voucher>>(
|
||||
this.http
|
||||
.get<Voucher>(`${url}/incentive`, options)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'Get Incentive')))
|
||||
);
|
||||
}
|
||||
|
||||
post(id: string): Observable<Voucher> {
|
||||
return <Observable<Voucher>>this.http.post<Voucher>(`${url}/post-voucher/${id}`, {})
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'Post Voucher'))
|
||||
);
|
||||
return <Observable<Voucher>>(
|
||||
this.http
|
||||
.post<Voucher>(`${url}/post-voucher/${id}`, {})
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'Post Voucher')))
|
||||
);
|
||||
}
|
||||
|
||||
delete(id: string): Observable<Voucher> {
|
||||
return <Observable<Voucher>>this.http.delete<Voucher>(`${url}/delete/${id}`, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'Delete Voucher'))
|
||||
);
|
||||
return <Observable<Voucher>>(
|
||||
this.http
|
||||
.delete<Voucher>(`${url}/delete/${id}`, httpOptions)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'Delete Voucher')))
|
||||
);
|
||||
}
|
||||
|
||||
saveOrUpdate(voucher: Voucher): Observable<Voucher> {
|
||||
@ -73,30 +76,36 @@ export class VoucherService {
|
||||
|
||||
save(voucher: Voucher, endpoint: string): Observable<Voucher> {
|
||||
const fd = new FormData();
|
||||
voucher.files.filter(x => !x.id).forEach((file) => {
|
||||
fd.append('i' , this.dataURLtoBlob(file.resized));
|
||||
fd.append('t' , this.dataURLtoBlob(file.thumbnail));
|
||||
});
|
||||
voucher.files = voucher.files.filter(x => x.id);
|
||||
voucher.files
|
||||
.filter((x) => !x.id)
|
||||
.forEach((file) => {
|
||||
fd.append('i', this.dataURLtoBlob(file.resized));
|
||||
fd.append('t', this.dataURLtoBlob(file.thumbnail));
|
||||
});
|
||||
voucher.files = voucher.files.filter((x) => x.id);
|
||||
fd.append('data', JSON.stringify(voucher));
|
||||
return <Observable<Voucher>>this.http.post<Voucher>(`${url}/${endpoint}`, fd)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'Save Voucher'))
|
||||
);
|
||||
return <Observable<Voucher>>(
|
||||
this.http
|
||||
.post<Voucher>(`${url}/${endpoint}`, fd)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'Save Voucher')))
|
||||
);
|
||||
}
|
||||
|
||||
update(voucher: Voucher, endpoint: string): Observable<Voucher> {
|
||||
const fd = new FormData();
|
||||
voucher.files.filter(x => !x.id).forEach((file) => {
|
||||
fd.append('i' , this.dataURLtoBlob(file.resized));
|
||||
fd.append('t' , this.dataURLtoBlob(file.thumbnail));
|
||||
});
|
||||
voucher.files = voucher.files.filter(x => x.id);
|
||||
voucher.files
|
||||
.filter((x) => !x.id)
|
||||
.forEach((file) => {
|
||||
fd.append('i', this.dataURLtoBlob(file.resized));
|
||||
fd.append('t', this.dataURLtoBlob(file.thumbnail));
|
||||
});
|
||||
voucher.files = voucher.files.filter((x) => x.id);
|
||||
fd.append('data', JSON.stringify(voucher));
|
||||
return <Observable<Voucher>>this.http.put<Voucher>(`${url}/${endpoint}/${voucher.id}`, fd)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'Update Voucher'))
|
||||
);
|
||||
return <Observable<Voucher>>(
|
||||
this.http
|
||||
.put<Voucher>(`${url}/${endpoint}/${voucher.id}`, fd)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'Update Voucher')))
|
||||
);
|
||||
}
|
||||
|
||||
dataURLtoBlob(dataURL) {
|
||||
@ -111,6 +120,6 @@ export class VoucherService {
|
||||
for (i = 0; i < byteString.length; i++) {
|
||||
dw.setUint8(i, byteString.charCodeAt(i));
|
||||
}
|
||||
return new Blob([ab], {type: mimeString});
|
||||
return new Blob([ab], { type: mimeString });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user