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:
2020-10-01 20:51:22 +05:30
parent 40e79ff949
commit 1350870f9e
545 changed files with 8455 additions and 7036 deletions

View File

@ -1,11 +1,11 @@
import {inject, TestBed} from '@angular/core/testing';
import { inject, TestBed } from '@angular/core/testing';
import {AccountService} from './account.service';
import { AccountService } from './account.service';
describe('AccountService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [AccountService]
providers: [AccountService],
});
});

View File

@ -1,66 +1,70 @@
import {Injectable} from '@angular/core';
import {Observable} from 'rxjs/internal/Observable';
import {catchError} from 'rxjs/operators';
import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';
import {Account} from './account';
import {ErrorLoggerService} from './error-logger.service';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/internal/Observable';
import { catchError } from 'rxjs/operators';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { Account } from './account';
import { ErrorLoggerService } from './error-logger.service';
const httpOptions = {
headers: new HttpHeaders({'Content-Type': 'application/json'})
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
};
const url = '/api/accounts';
const serviceName = 'AccountService';
@Injectable({providedIn: 'root'})
@Injectable({ providedIn: 'root' })
export class AccountService {
constructor(private http: HttpClient, private log: ErrorLoggerService) {
}
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
get(id: string): Observable<Account> {
const getUrl: string = (id === null) ? `${url}` : `${url}/${id}`;
return <Observable<Account>>this.http.get<Account>(getUrl)
.pipe(
catchError(this.log.handleError(serviceName, `get id=${id}`))
);
const getUrl: string = id === null ? `${url}` : `${url}/${id}`;
return <Observable<Account>>(
this.http
.get<Account>(getUrl)
.pipe(catchError(this.log.handleError(serviceName, `get id=${id}`)))
);
}
list(): Observable<Account[]> {
return <Observable<Account[]>>this.http.get<Account[]>(`${url}/list`)
.pipe(
catchError(this.log.handleError(serviceName, 'list'))
);
return <Observable<Account[]>>(
this.http
.get<Account[]>(`${url}/list`)
.pipe(catchError(this.log.handleError(serviceName, 'list')))
);
}
paymentAutocomplete(query: string): Observable<Account[]> {
const options = {params: new HttpParams().set('q', query).set('t', '1')};
return <Observable<Account[]>>this.http.get<Account[]>(`${url}/query`, options)
.pipe(
catchError(this.log.handleError(serviceName, 'list'))
);
const options = { params: new HttpParams().set('q', query).set('t', '1') };
return <Observable<Account[]>>(
this.http
.get<Account[]>(`${url}/query`, options)
.pipe(catchError(this.log.handleError(serviceName, 'list')))
);
}
receiptAutocomplete(query: string): Observable<Account[]> {
const options = {params: new HttpParams().set('q', query).set('t', '1')};
return <Observable<Account[]>>this.http.get<Account[]>(`${url}/query`, options)
.pipe(
catchError(this.log.handleError(serviceName, 'list'))
);
const options = { params: new HttpParams().set('q', query).set('t', '1') };
return <Observable<Account[]>>(
this.http
.get<Account[]>(`${url}/query`, options)
.pipe(catchError(this.log.handleError(serviceName, 'list')))
);
}
save(account: Account): Observable<Account> {
return <Observable<Account>>this.http.post<Account>(`${url}`, account, httpOptions)
.pipe(
catchError(this.log.handleError(serviceName, 'save'))
);
return <Observable<Account>>(
this.http
.post<Account>(`${url}`, account, httpOptions)
.pipe(catchError(this.log.handleError(serviceName, 'save')))
);
}
update(account: Account): Observable<Account> {
return <Observable<Account>>this.http.put<Account>(`${url}/${account.id}`, account, httpOptions)
.pipe(
catchError(this.log.handleError(serviceName, 'update'))
);
return <Observable<Account>>(
this.http
.put<Account>(`${url}/${account.id}`, account, httpOptions)
.pipe(catchError(this.log.handleError(serviceName, 'update')))
);
}
saveOrUpdate(account: Account): Observable<Account> {
@ -72,25 +76,28 @@ export class AccountService {
}
delete(id: string): Observable<Account> {
return <Observable<Account>>this.http.delete<Account>(`${url}/${id}`, httpOptions)
.pipe(
catchError(this.log.handleError(serviceName, 'delete'))
);
return <Observable<Account>>(
this.http
.delete<Account>(`${url}/${id}`, httpOptions)
.pipe(catchError(this.log.handleError(serviceName, 'delete')))
);
}
autocomplete(query: string): Observable<Account[]> {
const options = {params: new HttpParams().set('q', query)};
return <Observable<Account[]>>this.http.get<Account[]>(`${url}/query`, options)
.pipe(
catchError(this.log.handleError(serviceName, 'autocomplete'))
);
const options = { params: new HttpParams().set('q', query) };
return <Observable<Account[]>>(
this.http
.get<Account[]>(`${url}/query`, options)
.pipe(catchError(this.log.handleError(serviceName, 'autocomplete')))
);
}
balance(id: string, date: string): Observable<any> {
const options = {params: new HttpParams().set('d', date)};
return <Observable<any>>this.http.get<any>(`${url}/${id}/balance`, options)
.pipe(
catchError(this.log.handleError(serviceName, 'balance'))
);
const options = { params: new HttpParams().set('d', date) };
return <Observable<any>>(
this.http
.get<any>(`${url}/${id}/balance`, options)
.pipe(catchError(this.log.handleError(serviceName, 'balance')))
);
}
}

View File

@ -1,5 +1,5 @@
import {AccountType} from './account-type';
import {CostCentre} from './cost-centre';
import { AccountType } from './account-type';
import { CostCentre } from './cost-centre';
export class Account {
id: string;

View File

@ -1,24 +1,23 @@
import {Injectable} from '@angular/core';
import {Observable} from 'rxjs/internal/Observable';
import {catchError} from 'rxjs/operators';
import {HttpClient, HttpParams} from '@angular/common/http';
import {Batch} from './voucher';
import {ErrorLoggerService} from './error-logger.service';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/internal/Observable';
import { catchError } from 'rxjs/operators';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Batch } from './voucher';
import { ErrorLoggerService } from './error-logger.service';
const url = '/api/batch';
const serviceName = 'BatchService';
@Injectable({providedIn: 'root'})
@Injectable({ providedIn: 'root' })
export class BatchService {
constructor(private http: HttpClient, private log: ErrorLoggerService) {
}
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
autocomplete(date: string, term: string): Observable<Batch[]> {
const options = {params: new HttpParams().set('q', term).set('d', date)};
return <Observable<Batch[]>>this.http.get<Batch[]>(url, options)
.pipe(
catchError(this.log.handleError(serviceName, 'autocomplete'))
);
const options = { params: new HttpParams().set('q', term).set('d', date) };
return <Observable<Batch[]>>(
this.http
.get<Batch[]>(url, options)
.pipe(catchError(this.log.handleError(serviceName, 'autocomplete')))
);
}
}

View File

@ -1,4 +1,4 @@
import {CoreModule} from './core.module';
import { CoreModule } from './core.module';
describe('CoreModule', () => {
let coreModule: CoreModule;

View File

@ -1,16 +1,16 @@
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {NavBarComponent} from './nav-bar/nav-bar.component';
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { NavBarComponent } from './nav-bar/nav-bar.component';
import { MatButtonModule } from '@angular/material/button';
import { MatIconModule } from '@angular/material/icon';
import { MatMenuModule } from '@angular/material/menu';
import { MatToolbarModule } from '@angular/material/toolbar';
import {RouterModule} from '@angular/router';
import {HTTP_INTERCEPTORS} from '@angular/common/http';
import {LoadingBarHttpClientModule} from '@ngx-loading-bar/http-client';
import {LoadingBarRouterModule} from '@ngx-loading-bar/router';
import {JwtInterceptor} from './jwt.interceptor';
import {ErrorInterceptor} from './http-auth-interceptor';
import { RouterModule } from '@angular/router';
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { LoadingBarHttpClientModule } from '@ngx-loading-bar/http-client';
import { LoadingBarRouterModule } from '@ngx-loading-bar/router';
import { JwtInterceptor } from './jwt.interceptor';
import { ErrorInterceptor } from './http-auth-interceptor';
@NgModule({
imports: [
@ -21,20 +21,13 @@ import {ErrorInterceptor} from './http-auth-interceptor';
MatIconModule,
MatMenuModule,
MatToolbarModule,
RouterModule
],
declarations: [
NavBarComponent,
],
exports: [
NavBarComponent,
LoadingBarHttpClientModule,
LoadingBarRouterModule
RouterModule,
],
declarations: [NavBarComponent],
exports: [NavBarComponent, LoadingBarHttpClientModule, LoadingBarRouterModule],
providers: [
{provide: HTTP_INTERCEPTORS, useClass: JwtInterceptor, multi: true},
{provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true},
]
{ provide: HTTP_INTERCEPTORS, useClass: JwtInterceptor, multi: true },
{ provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true },
],
})
export class CoreModule {
}
export class CoreModule {}

View File

@ -1,11 +1,11 @@
import {inject, TestBed} from '@angular/core/testing';
import { inject, TestBed } from '@angular/core/testing';
import {ErrorLoggerService} from './error-logger.service';
import { ErrorLoggerService } from './error-logger.service';
describe('ErrorLoggerService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [ErrorLoggerService]
providers: [ErrorLoggerService],
});
});

View File

@ -1,13 +1,12 @@
import {Injectable} from '@angular/core';
import {Observable} from 'rxjs/internal/Observable';
import {throwError} from 'rxjs';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/internal/Observable';
import { throwError } from 'rxjs';
@Injectable({
providedIn: 'root'
providedIn: 'root',
})
export class ErrorLoggerService {
constructor() {
}
constructor() {}
/**
* Handle Http operation that failed.
@ -17,7 +16,6 @@ export class ErrorLoggerService {
*/
public handleError<T>(serviceName = 'error-logger', operation = 'operation', result?: T) {
return (error: any): Observable<T> => {
// TODO: send the error to remote logging infrastructure
console.error(error); // log to console instead

View File

@ -10,42 +10,49 @@ import { ConfirmDialogComponent } from '../shared/confirm-dialog/confirm-dialog.
@Injectable()
export class ErrorInterceptor implements HttpInterceptor {
constructor(private authService: AuthService, private router: Router, private dialog: MatDialog, private toaster: ToasterService) {
}
constructor(
private authService: AuthService,
private router: Router,
private dialog: MatDialog,
private toaster: ToasterService,
) {}
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(request).pipe(catchError(err => {
// We don't want to refresh token for some requests like login or refresh token itself
// So we verify url and we throw an error if it's the case
if (request.url.includes('/refresh') || request.url.includes('/token')) {
// We do another check to see if refresh token failed
// In this case we want to logout user and to redirect it to login page
if (request.url.includes('/refresh')) {
this.authService.logout();
return next.handle(request).pipe(
catchError((err) => {
// We don't want to refresh token for some requests like login or refresh token itself
// So we verify url and we throw an error if it's the case
if (request.url.includes('/refresh') || request.url.includes('/token')) {
// We do another check to see if refresh token failed
// In this case we want to logout user and to redirect it to login page
if (request.url.includes('/refresh')) {
this.authService.logout();
}
return throwError(err);
}
return throwError(err);
}
// If error status is different than 401 we want to skip refresh token
// So we check that and throw the error if it's the case
if (err.status !== 401) {
const error = err.error.message || err.error.detail || err.statusText;
return throwError(error);
}
// auto logout if 401 response returned from api
this.authService.logout();
this.toaster.show('Danger', 'User has been logged out');
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
width: '250px',
data: {
title: 'Logged out!',
content: 'You have been logged out.\nYou can press Cancel to stay on page and login in another tab to resume here, or you can press Ok to navigate to the login page.'
// If error status is different than 401 we want to skip refresh token
// So we check that and throw the error if it's the case
if (err.status !== 401) {
const error = err.error.message || err.error.detail || err.statusText;
return throwError(error);
}
});
dialogRef.afterClosed().subscribe((result: boolean) => {
if (result) {
this.router.navigate(['login']);
}
});
}));
// auto logout if 401 response returned from api
this.authService.logout();
this.toaster.show('Danger', 'User has been logged out');
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
width: '250px',
data: {
title: 'Logged out!',
content:
'You have been logged out.\nYou can press Cancel to stay on page and login in another tab to resume here, or you can press Ok to navigate to the login page.',
},
});
dialogRef.afterClosed().subscribe((result: boolean) => {
if (result) {
this.router.navigate(['login']);
}
});
}),
);
}
}

View File

@ -1,15 +1,14 @@
import {Injectable} from '@angular/core';
import {HttpRequest, HttpHandler, HttpEvent, HttpInterceptor} from '@angular/common/http';
import {Observable} from 'rxjs';
import { Injectable } from '@angular/core';
import { HttpRequest, HttpHandler, HttpEvent, HttpInterceptor } from '@angular/common/http';
import { Observable } from 'rxjs';
import {AuthService} from '../auth/auth.service';
import { AuthService } from '../auth/auth.service';
@Injectable()
export class JwtInterceptor implements HttpInterceptor {
private isRefreshing = false;
constructor(private authService: AuthService) {
}
constructor(private authService: AuthService) {}
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
// add authorization header with jwt token if available
@ -18,18 +17,17 @@ export class JwtInterceptor implements HttpInterceptor {
// console.log("intercepting:\nisRefreshing: ", this.isRefreshing, "\n user: ", this.authService.user,"\n needsRefreshing: ", this.authService.needsRefreshing());
if (!this.isRefreshing && this.authService.user && this.authService.needsRefreshing()) {
this.isRefreshing = true;
this.authService.refreshToken().subscribe( x => this.isRefreshing = false);
this.authService.refreshToken().subscribe((x) => (this.isRefreshing = false));
}
const currentUser = this.authService.user;
if (currentUser?.access_token) {
request = request.clone({
setHeaders: {
Authorization: `Bearer ${currentUser.access_token}`
}
Authorization: `Bearer ${currentUser.access_token}`,
},
});
}
return next.handle(request);
}
}

View File

@ -4,7 +4,7 @@
.sidenav {
width: 200px;
box-shadow: 3px 0 6px rgba(0, 0, 0, .24);
box-shadow: 3px 0 6px rgba(0, 0, 0, 0.24);
}
.fill-remaining-space {

View File

@ -8,9 +8,7 @@
<a mat-menu-item routerLink="/receipt">Receipt</a>
<a mat-menu-item routerLink="/issue">Issue</a>
</mat-menu>
<button mat-button [matMenuTriggerFor]="voucherMenu">
Voucher Entry
</button>
<button mat-button [matMenuTriggerFor]="voucherMenu">Voucher Entry</button>
<mat-menu #reportMenu="matMenu">
<a mat-menu-item routerLink="/ledger">Display Ledger</a>
@ -23,9 +21,7 @@
<a mat-menu-item routerLink="/net-transactions">Net Transactions</a>
<a mat-menu-item routerLink="/unposted">UnPosted Entries</a>
</mat-menu>
<button mat-button [matMenuTriggerFor]="reportMenu">
Reports
</button>
<button mat-button [matMenuTriggerFor]="reportMenu">Reports</button>
<mat-menu #productReportMenu="matMenu">
<a mat-menu-item routerLink="/product-ledger">Product Ledger</a>
@ -35,9 +31,7 @@
<a mat-menu-item routerLink="/closing-stock">Closing Stock</a>
<a mat-menu-item routerLink="/stock-movement">Stock Movement</a>
</mat-menu>
<button mat-button [matMenuTriggerFor]="productReportMenu">
Product Reports
</button>
<button mat-button [matMenuTriggerFor]="productReportMenu">Product Reports</button>
<mat-menu #employeeMenu="matMenu">
<a mat-menu-item routerLink="/employees">Employees</a>
@ -47,9 +41,7 @@
<a mat-menu-item routerLink="/employee-benefits">Employee Benefits (Esi / Pf)</a>
<a mat-menu-item routerLink="/incentive">Incentive</a>
</mat-menu>
<button mat-button [matMenuTriggerFor]="employeeMenu">
Employees
</button>
<button mat-button [matMenuTriggerFor]="employeeMenu">Employees</button>
<mat-menu #masterMenu="matMenu">
<a mat-menu-item routerLink="/accounts">Accounts</a>
@ -57,26 +49,29 @@
<a mat-menu-item routerLink="/products">Products</a>
<a mat-menu-item routerLink="/product-groups">Product Groups</a>
</mat-menu>
<button mat-button [matMenuTriggerFor]="masterMenu">
Masters
</button>
<button mat-button [matMenuTriggerFor]="masterMenu">Masters</button>
<span class="fill-remaining-space"></span>
<mat-menu #userMenu="matMenu">
<a mat-menu-item (click)="logout()">Logout {{(auth.currentUser | async)?.name}}</a>
<a mat-menu-item (click)="logout()">Logout {{ (auth.currentUser | async)?.name }}</a>
<a mat-menu-item routerLink="/users/me">Change Password</a>
<a mat-menu-item routerLink="/users">Users</a>
<a mat-menu-item routerLink="/roles">Roles</a>
<a mat-menu-item routerLink="/clients">Clients</a>
<a mat-menu-item routerLink="/settings">Settings</a>
</mat-menu>
<button mat-button [matMenuTriggerFor]="userMenu" *ngIf="(auth.currentUser | async)?.name as name">
<button
mat-button
[matMenuTriggerFor]="userMenu"
*ngIf="(auth.currentUser | async)?.name as name"
>
<mat-icon>account_box</mat-icon>
{{name}}
{{ name }}
</button>
<a mat-button routerLink="/login" *ngIf="!(auth.currentUser | async)">
<mat-icon>account_box</mat-icon>
Login</a>
Login</a
>
</mat-toolbar>
<div class="toolbar-fix"></div>

View File

@ -1,6 +1,6 @@
import {ComponentFixture, fakeAsync, TestBed} from '@angular/core/testing';
import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
import {NavBarComponent} from './nav-bar.component';
import { NavBarComponent } from './nav-bar.component';
describe('NavBarComponent', () => {
let component: NavBarComponent;
@ -8,9 +8,8 @@ describe('NavBarComponent', () => {
beforeEach(fakeAsync(() => {
TestBed.configureTestingModule({
declarations: [NavBarComponent]
})
.compileComponents();
declarations: [NavBarComponent],
}).compileComponents();
fixture = TestBed.createComponent(NavBarComponent);
component = fixture.componentInstance;

View File

@ -1,19 +1,17 @@
import {Component} from '@angular/core';
import {AuthService} from '../../auth/auth.service';
import {Router} from '@angular/router';
import { Component } from '@angular/core';
import { AuthService } from '../../auth/auth.service';
import { Router } from '@angular/router';
@Component({
selector: 'app-nav-bar',
templateUrl: './nav-bar.component.html',
styleUrls: ['./nav-bar.component.css']
styleUrls: ['./nav-bar.component.css'],
})
export class NavBarComponent {
constructor(private router: Router, public auth: AuthService) {}
constructor(private router: Router, public auth: AuthService) {
logout() {
this.auth.logout();
this.router.navigate(['/']);
}
logout() {
this.auth.logout();
this.router.navigate(['/']);
}
}

View File

@ -1,5 +1,5 @@
import {Account} from './account';
import {ProductGroup} from './product-group';
import { Account } from './account';
import { ProductGroup } from './product-group';
export class Product {
id: string;

View File

@ -1,11 +1,11 @@
import {inject, TestBed} from '@angular/core/testing';
import { inject, TestBed } from '@angular/core/testing';
import {ToasterService} from './toaster.service';
import { ToasterService } from './toaster.service';
describe('ToasterService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [ToasterService]
providers: [ToasterService],
});
});

View File

@ -1,13 +1,11 @@
import {Injectable} from '@angular/core';
import { Injectable } from '@angular/core';
import { MatSnackBar } from '@angular/material/snack-bar';
@Injectable({
providedIn: 'root'
providedIn: 'root',
})
export class ToasterService {
constructor(private snackBar: MatSnackBar) {
}
constructor(private snackBar: MatSnackBar) {}
show(type: string, msg: string) {
this.snackBar.open(msg, type, {

View File

@ -1,11 +1,11 @@
import {inject, TestBed} from '@angular/core/testing';
import { inject, TestBed } from '@angular/core/testing';
import {VoucherService} from './voucher.service';
import { VoucherService } from './voucher.service';
describe('VoucherService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [VoucherService]
providers: [VoucherService],
});
});

View File

@ -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 });
}
}

View File

@ -1,8 +1,8 @@
import {Account} from './account';
import {User} from './user';
import {CostCentre} from './cost-centre';
import {Product} from './product';
import {Employee} from "../employee/employee";
import { Account } from './account';
import { User } from './user';
import { CostCentre } from './cost-centre';
import { Product } from './product';
import { Employee } from '../employee/employee';
export class Voucher {
id: string;
@ -56,7 +56,6 @@ export class Incentive {
department: string;
daysWorked: number;
points: number;
}
export class Inventory {