From 57ef355170667e8f1472061543969a8ca5884118 Mon Sep 17 00:00:00 2001 From: tanshu Date: Tue, 8 Dec 2020 12:09:19 +0530 Subject: [PATCH] Fix: Login deleting old clients was conflicting with login history Chore: Moved to angular linting using the recommended plugins / settings --- brewman/brewman/routers/login.py | 18 ++++- overlord/.eslintrc.js | 43 ----------- overlord/.eslintrc.json | 62 +++++++++++++++ .../account-detail.component.spec.ts | 2 +- .../account-detail.component.ts | 4 +- .../account-list-resolver.service.spec.ts | 2 +- .../account-list/account-list-datasource.ts | 24 ++++-- .../account-list/account-list.component.ts | 4 +- .../account/account-resolver.service.spec.ts | 2 +- .../account-type-resolver.service.spec.ts | 2 +- .../app/account/account-type.service.spec.ts | 2 +- .../src/app/account/account-type.service.ts | 6 +- overlord/src/app/app.component.spec.ts | 1 + .../attendance-resolver.service.spec.ts | 2 +- .../app/attendance/attendance-type.service.ts | 8 +- .../attendance/attendance.component.spec.ts | 2 +- .../app/attendance/attendance.service.spec.ts | 2 +- .../src/app/attendance/attendance.service.ts | 22 ++---- overlord/src/app/auth/auth.service.spec.ts | 2 +- overlord/src/app/auth/auth.service.ts | 2 +- .../app/auth/login/login.component.spec.ts | 2 +- .../src/app/auth/login/login.component.ts | 4 +- .../app/auth/logout/logout.component.spec.ts | 2 +- .../balance-sheet/balance-sheet-datasource.ts | 28 ++++--- .../balance-sheet-resolver.service.spec.ts | 2 +- .../balance-sheet.service.spec.ts | 2 +- .../balance-sheet/balance-sheet.service.ts | 8 +- .../cash-flow-resolver.service.spec.ts | 2 +- .../app/cash-flow/cash-flow.service.spec.ts | 2 +- .../src/app/cash-flow/cash-flow.service.ts | 8 +- overlord/src/app/cash-flow/cash-flow.ts | 24 +++--- .../client-detail.component.spec.ts | 2 +- .../client-detail/client-detail.component.ts | 4 +- .../client-list-resolver.service.spec.ts | 2 +- .../client-list/client-list-datasource.ts | 24 ++++-- .../client/client-resolver.service.spec.ts | 2 +- .../src/app/client/client.service.spec.ts | 2 +- overlord/src/app/client/client.service.ts | 35 +++------ .../closing-stock/closing-stock-datasource.ts | 24 ++++-- .../closing-stock-resolver.service.spec.ts | 2 +- .../closing-stock.service.spec.ts | 2 +- .../closing-stock/closing-stock.service.ts | 8 +- overlord/src/app/core/account.service.spec.ts | 2 +- overlord/src/app/core/account.service.ts | 76 +++++++------------ overlord/src/app/core/batch.service.ts | 8 +- overlord/src/app/core/error-logger.service.ts | 1 + .../src/app/core/http-auth-interceptor.ts | 4 +- .../app/core/nav-bar/nav-bar.component.html | 2 +- overlord/src/app/core/voucher.service.spec.ts | 2 +- overlord/src/app/core/voucher.service.ts | 62 ++++++--------- .../cost-centre-detail.component.ts | 4 +- .../cost-centre-list-resolver.service.spec.ts | 2 +- .../cost-centre-list-datasource.ts | 24 ++++-- .../cost-centre-resolver.service.spec.ts | 2 +- .../cost-centre/cost-centre.service.spec.ts | 2 +- .../app/cost-centre/cost-centre.service.ts | 45 +++++------ .../src/app/daybook/daybook-datasource.ts | 24 ++++-- .../daybook/daybook-resolver.service.spec.ts | 2 +- .../src/app/daybook/daybook.service.spec.ts | 2 +- overlord/src/app/daybook/daybook.service.ts | 8 +- .../employee-attendance.component.ts | 4 +- .../employee-attendance.service.ts | 26 +++---- .../employee-benefits.component.ts | 10 ++- .../employee-functions.service.ts | 14 ++-- .../employee-detail.component.spec.ts | 2 +- .../employee-detail.component.ts | 4 +- .../employee-list-resolver.service.spec.ts | 2 +- .../employee-list/employee-list-datasource.ts | 24 ++++-- .../employee-list/employee-list.component.ts | 4 +- .../employee-resolver.service.spec.ts | 2 +- .../src/app/employee/employee.service.spec.ts | 2 +- overlord/src/app/employee/employee.service.ts | 54 +++++-------- .../incentive-resolver.service.spec.ts | 2 +- .../app/incentive/incentive.component.spec.ts | 2 +- .../src/app/incentive/incentive.component.ts | 2 +- .../src/app/issue/issue-grid.service.spec.ts | 2 +- overlord/src/app/issue/issue-grid.service.ts | 10 +-- .../app/issue/issue-resolver.service.spec.ts | 2 +- .../src/app/issue/issue.component.spec.ts | 2 +- overlord/src/app/issue/issue.component.ts | 14 +++- .../journal/journal-resolver.service.spec.ts | 2 +- .../src/app/journal/journal.component.spec.ts | 4 +- overlord/src/app/journal/journal.component.ts | 14 +++- overlord/src/app/ledger/ledger-datasource.ts | 24 ++++-- .../ledger/ledger-resolver.service.spec.ts | 2 +- .../src/app/ledger/ledger.component.spec.ts | 2 +- overlord/src/app/ledger/ledger.component.ts | 4 +- .../src/app/ledger/ledger.service.spec.ts | 2 +- overlord/src/app/ledger/ledger.service.ts | 8 +- .../net-transactions-datasource.ts | 24 ++++-- .../net-transactions-resolver.service.spec.ts | 2 +- .../net-transactions.service.spec.ts | 2 +- .../net-transactions.service.ts | 8 +- .../payment-accounts-resolver.service.spec.ts | 2 +- .../payment/payment-resolver.service.spec.ts | 2 +- overlord/src/app/payment/payment.component.ts | 21 +++-- .../product-group-detail.component.ts | 4 +- ...roduct-group-list-resolver.service.spec.ts | 2 +- .../product-group-list-datasource.ts | 24 ++++-- .../product-group-resolver.service.spec.ts | 2 +- .../product-group.service.spec.ts | 2 +- .../product-group/product-group.service.ts | 45 +++++------ .../product-ledger-datasource.ts | 24 ++++-- .../product-ledger-resolver.service.spec.ts | 2 +- .../product-ledger.component.spec.ts | 2 +- .../product-ledger.component.ts | 4 +- .../product-ledger.service.spec.ts | 2 +- .../product-ledger/product-ledger.service.ts | 8 +- .../product-detail.component.spec.ts | 2 +- .../product-detail.component.ts | 4 +- .../product-list-resolver.service.spec.ts | 2 +- .../product-list/product-list-datasource.ts | 24 ++++-- .../product-list/product-list.component.ts | 5 +- .../product/product-resolver.service.spec.ts | 2 +- .../src/app/product/product.service.spec.ts | 2 +- overlord/src/app/product/product.service.ts | 52 +++++-------- .../app/profit-loss/profit-loss-datasource.ts | 24 ++++-- .../profit-loss-resolver.service.spec.ts | 2 +- .../profit-loss/profit-loss.service.spec.ts | 2 +- .../app/profit-loss/profit-loss.service.ts | 8 +- .../purchase-entries-datasource.ts | 24 ++++-- .../purchase-entries-resolver.service.spec.ts | 2 +- .../purchase-entries.service.spec.ts | 2 +- .../purchase-entries.service.ts | 8 +- .../purchase-return-resolver.service.spec.ts | 2 +- .../purchase-return.component.spec.ts | 2 +- .../purchase-return.component.ts | 14 +++- .../purchase-resolver.service.spec.ts | 2 +- .../app/purchase/purchase.component.spec.ts | 2 +- .../src/app/purchase/purchase.component.ts | 14 +++- .../src/app/purchases/purchases-datasource.ts | 24 ++++-- .../purchases-resolver.service.spec.ts | 2 +- .../app/purchases/purchases.component.spec.ts | 2 +- .../app/purchases/purchases.service.spec.ts | 2 +- .../src/app/purchases/purchases.service.ts | 8 +- .../raw-material-cost-datasource.ts | 24 ++++-- ...raw-material-cost-resolver.service.spec.ts | 2 +- .../raw-material-cost.component.ts | 2 +- .../raw-material-cost.service.spec.ts | 2 +- .../raw-material-cost.service.ts | 8 +- .../receipt-accounts-resolver.service.spec.ts | 2 +- .../receipt/receipt-resolver.service.spec.ts | 2 +- .../src/app/receipt/receipt.component.spec.ts | 2 +- overlord/src/app/receipt/receipt.component.ts | 14 +++- .../role/role-detail/role-detail.component.ts | 4 +- .../role/role-list-resolver.service.spec.ts | 2 +- .../role/role-list/role-list-datasource.ts | 24 ++++-- .../app/role/role-resolver.service.spec.ts | 2 +- overlord/src/app/role/role.service.spec.ts | 2 +- overlord/src/app/role/role.service.ts | 43 ++++------- overlord/src/app/settings/settings.service.ts | 64 +++++++--------- overlord/src/app/shared/clear.pipe.ts | 4 +- overlord/src/app/shared/image.service.ts | 12 +-- .../stock-movement-datasource.ts | 24 ++++-- .../stock-movement-resolver.service.spec.ts | 2 +- .../stock-movement.service.spec.ts | 2 +- .../stock-movement/stock-movement.service.ts | 8 +- .../trial-balance/trial-balance-datasource.ts | 24 ++++-- .../trial-balance-resolver.service.spec.ts | 2 +- .../trial-balance.service.spec.ts | 2 +- .../trial-balance/trial-balance.service.ts | 8 +- .../src/app/unposted/unposted-datasource.ts | 24 ++++-- .../unposted-resolver.service.spec.ts | 2 +- .../app/unposted/unposted.component.spec.ts | 2 +- .../src/app/unposted/unposted.service.spec.ts | 2 +- overlord/src/app/unposted/unposted.service.ts | 6 +- .../user/user-detail/user-detail.component.ts | 4 +- .../user/user-list-resolver.service.spec.ts | 2 +- .../user/user-list/user-list-datasource.ts | 24 ++++-- .../app/user/user-resolver.service.spec.ts | 2 +- overlord/src/app/user/user.service.spec.ts | 2 +- overlord/src/app/user/user.service.ts | 61 ++++++--------- overlord/src/environments/environment.prod.ts | 1 + overlord/src/environments/environment.ts | 1 + overlord/src/index.html | 7 +- overlord/tsconfig.spec.json | 2 +- 176 files changed, 940 insertions(+), 831 deletions(-) delete mode 100644 overlord/.eslintrc.js create mode 100644 overlord/.eslintrc.json diff --git a/brewman/brewman/routers/login.py b/brewman/brewman/routers/login.py index c05b881e..75c79a9f 100644 --- a/brewman/brewman/routers/login.py +++ b/brewman/brewman/routers/login.py @@ -12,7 +12,7 @@ from fastapi import ( ) from fastapi.responses import JSONResponse from fastapi.security import OAuth2PasswordRequestForm -from sqlalchemy import and_ +from sqlalchemy import and_, or_ from sqlalchemy.orm import Session from .. import __version__ @@ -61,7 +61,21 @@ async def login_for_access_token( if allowed: history = LoginHistory(user.id, client.id) db.add(history) - db.execute(LoginHistory.__table__.delete(LoginHistory.date < datetime.utcnow() - timedelta(days=30))) + db.execute( + LoginHistory.__table__.delete( + or_( + LoginHistory.date < datetime.utcnow() - timedelta(days=30), + LoginHistory.client_id.in_( + db.query(Client.id) + .filter( + Client.creation_date < datetime.utcnow() - timedelta(days=3), + Client.enabled == False, # noqa: E712 + ) + .subquery() + ), + ) + ) + ) db.execute( Client.__table__.delete( and_(Client.creation_date < datetime.utcnow() - timedelta(days=3), Client.enabled == False) # noqa: E712 diff --git a/overlord/.eslintrc.js b/overlord/.eslintrc.js deleted file mode 100644 index fe395d1a..00000000 --- a/overlord/.eslintrc.js +++ /dev/null @@ -1,43 +0,0 @@ -/* -We recommend eventually switching this configuration to extend from -the recommended rulesets in typescript-eslint. -https://github.com/typescript-eslint/tslint-to-eslint-config/blob/master/docs/FAQs.md - -Happy linting! ๐Ÿ’– -*/ -module.exports = { - "extends": [ - "plugin:@angular-eslint/recommended", - // AirBnB Styleguide rules - "airbnb-typescript/base", - // Settings for Prettier - "prettier", - "prettier/@typescript-eslint", - "prettier/react", - ], - "env": { - "browser": true, - "node": true - }, - "parser": "@typescript-eslint/parser", - "parserOptions": { - "project": "tsconfig.json", - "ecmaVersion": 2020, - "sourceType": "module" - }, - "plugins": [ - "eslint-plugin-import", - "eslint-plugin-jsdoc", - "@angular-eslint/eslint-plugin", - "@typescript-eslint", - ], - "ignorePatterns": ["/src/**/*.spec.ts", "src/test.ts", "src/polyfills.ts"], - "rules": { - "import/prefer-default-export": "off", - "no-param-reassign": ["error", { "props": false }], - "@typescript-eslint/lines-between-class-members": ["error", "always", { "exceptAfterSingleLine": true }], - "class-methods-use-this": ["error", {"exceptMethods": ["disconnect", "displayFn", "transform"]}], - "import/order": ["error", {"alphabetize": {"order": "asc", "caseInsensitive": true}, "newlines-between": "always"}], - "@typescript-eslint/no-explicit-any": "error", - } -}; diff --git a/overlord/.eslintrc.json b/overlord/.eslintrc.json new file mode 100644 index 00000000..2f27844e --- /dev/null +++ b/overlord/.eslintrc.json @@ -0,0 +1,62 @@ +{ + "root": true, + "ignorePatterns": [ + "projects/**/*" + ], + "overrides": [ + { + "files": [ + "*.ts" + ], + "parserOptions": { + "project": [ + "tsconfig.json", + "e2e/tsconfig.json" + ], + "createDefaultProgram": true + }, + "extends": [ + "plugin:@angular-eslint/ng-cli-compat", + "plugin:@angular-eslint/ng-cli-compat--formatting-add-on", + "plugin:@angular-eslint/template/process-inline-templates" + ], + "rules": { + "@angular-eslint/component-selector": [ + "error", + { + "type": "element", + "prefix": "app", + "style": "kebab-case" + } + ], + "@angular-eslint/directive-selector": [ + "error", + { + "type": "attribute", + "prefix": "app", + "style": "camelCase" + } + ], + "import/order": [ + "error", + { + "alphabetize": {"order": "asc", "caseInsensitive": true}, + "newlines-between": "always" + } + ], + "@typescript-eslint/naming-convention": [ + "off" + ] + } + }, + { + "files": [ + "*.html" + ], + "extends": [ + "plugin:@angular-eslint/template/recommended" + ], + "rules": {} + } + ] +} diff --git a/overlord/src/app/account/account-detail/account-detail.component.spec.ts b/overlord/src/app/account/account-detail/account-detail.component.spec.ts index 92a88194..1b4cb02e 100644 --- a/overlord/src/app/account/account-detail/account-detail.component.spec.ts +++ b/overlord/src/app/account/account-detail/account-detail.component.spec.ts @@ -1,6 +1,6 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; -import { MatDialogModule } from '@angular/material/dialog'; import { ReactiveFormsModule } from '@angular/forms'; +import { MatDialogModule } from '@angular/material/dialog'; import { RouterTestingModule } from '@angular/router/testing'; import { AccountDetailComponent } from './account-detail.component'; diff --git a/overlord/src/app/account/account-detail/account-detail.component.ts b/overlord/src/app/account/account-detail/account-detail.component.ts index d5d88813..3625d729 100644 --- a/overlord/src/app/account/account-detail/account-detail.component.ts +++ b/overlord/src/app/account/account-detail/account-detail.component.ts @@ -68,7 +68,9 @@ export class AccountDetailComponent implements OnInit, AfterViewInit { ngAfterViewInit() { setTimeout(() => { - if (this.nameElement) this.nameElement.nativeElement.focus(); + if (this.nameElement) { + this.nameElement.nativeElement.focus(); + } }, 0); } diff --git a/overlord/src/app/account/account-list-resolver.service.spec.ts b/overlord/src/app/account/account-list-resolver.service.spec.ts index 3f5c7918..ce9f77dd 100644 --- a/overlord/src/app/account/account-list-resolver.service.spec.ts +++ b/overlord/src/app/account/account-list-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { AccountListResolver } from './account-list-resolver.service'; diff --git a/overlord/src/app/account/account-list/account-list-datasource.ts b/overlord/src/app/account/account-list/account-list-datasource.ts index 4377930d..57a32cba 100644 --- a/overlord/src/app/account/account-list/account-list-datasource.ts +++ b/overlord/src/app/account/account-list/account-list-datasource.ts @@ -8,9 +8,7 @@ import { map, tap } from 'rxjs/operators'; import { Account } from '../../core/account'; /** Simple sort comparator for example ID/Name columns (for client-side sorting). */ -function compare(a: string | number | boolean, b: string | number | boolean, isAsc: boolean) { - return (a < b ? -1 : 1) * (isAsc ? 1 : -1); -} +const compare = (a: string | number | boolean, b: string | number | boolean, isAsc: boolean) => (a < b ? -1 : 1) * (isAsc ? 1 : -1); export class AccountListDataSource extends DataSource { private filterValue = ''; @@ -35,14 +33,20 @@ export class AccountListDataSource extends DataSource { | EventEmitter | EventEmitter )[] = [observableOf(this.data), this.filter]; - if (this.paginator) dataMutations.push((this.paginator as MatPaginator).page); - if (this.sort) dataMutations.push((this.sort as MatSort).sortChange); + if (this.paginator) { + dataMutations.push((this.paginator as MatPaginator).page); + } + if (this.sort) { + dataMutations.push((this.sort as MatSort).sortChange); + } return merge(...dataMutations) .pipe( map(() => this.getFilteredData([...this.data])), tap((x: Account[]) => { - if (this.paginator) this.paginator.length = x.length; + if (this.paginator) { + this.paginator.length = x.length; + } }), ) .pipe(map((x: Account[]) => this.getPagedData(this.getSortedData(x)))); @@ -64,13 +68,17 @@ export class AccountListDataSource extends DataSource { } private getPagedData(data: Account[]) { - if (this.paginator === undefined) return data; + if (this.paginator === undefined) { + return data; + } const startIndex = this.paginator.pageIndex * this.paginator.pageSize; return data.splice(startIndex, this.paginator.pageSize); } private getSortedData(data: Account[]) { - if (this.sort === undefined) return data; + if (this.sort === undefined) { + return data; + } if (!this.sort.active || this.sort.direction === '') { return data; } diff --git a/overlord/src/app/account/account-list/account-list.component.ts b/overlord/src/app/account/account-list/account-list.component.ts index 8b882e6f..5758b4f5 100644 --- a/overlord/src/app/account/account-list/account-list.component.ts +++ b/overlord/src/app/account/account-list/account-list.component.ts @@ -51,7 +51,9 @@ export class AccountListComponent implements OnInit, AfterViewInit { ngAfterViewInit() { setTimeout(() => { - if (this.filterElement) this.filterElement.nativeElement.focus(); + if (this.filterElement) { + this.filterElement.nativeElement.focus(); + } }, 0); } } diff --git a/overlord/src/app/account/account-resolver.service.spec.ts b/overlord/src/app/account/account-resolver.service.spec.ts index 22925f94..85afcfaf 100644 --- a/overlord/src/app/account/account-resolver.service.spec.ts +++ b/overlord/src/app/account/account-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { AccountResolver } from './account-resolver.service'; diff --git a/overlord/src/app/account/account-type-resolver.service.spec.ts b/overlord/src/app/account/account-type-resolver.service.spec.ts index 761b1349..a996ef88 100644 --- a/overlord/src/app/account/account-type-resolver.service.spec.ts +++ b/overlord/src/app/account/account-type-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { AccountTypeResolver } from './account-type-resolver.service'; diff --git a/overlord/src/app/account/account-type.service.spec.ts b/overlord/src/app/account/account-type.service.spec.ts index 3915e06d..f0e5e8e7 100644 --- a/overlord/src/app/account/account-type.service.spec.ts +++ b/overlord/src/app/account/account-type.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { AccountTypeService } from './account-type.service'; diff --git a/overlord/src/app/account/account-type.service.ts b/overlord/src/app/account/account-type.service.ts index 30f53abc..ae4f6292 100644 --- a/overlord/src/app/account/account-type.service.ts +++ b/overlord/src/app/account/account-type.service.ts @@ -16,8 +16,8 @@ export class AccountTypeService { constructor(private http: HttpClient, private log: ErrorLoggerService) {} list(): Observable { - return >( - this.http.get(url).pipe(catchError(this.log.handleError(serviceName, 'list'))) - ); + return this.http + .get(url) + .pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable; } } diff --git a/overlord/src/app/app.component.spec.ts b/overlord/src/app/app.component.spec.ts index 5f33816a..676b5c8e 100644 --- a/overlord/src/app/app.component.spec.ts +++ b/overlord/src/app/app.component.spec.ts @@ -1,4 +1,5 @@ import { TestBed, waitForAsync } from '@angular/core/testing'; + import { AppComponent } from './app.component'; describe('AppComponent', () => { diff --git a/overlord/src/app/attendance/attendance-resolver.service.spec.ts b/overlord/src/app/attendance/attendance-resolver.service.spec.ts index df978bed..c75b877e 100644 --- a/overlord/src/app/attendance/attendance-resolver.service.spec.ts +++ b/overlord/src/app/attendance/attendance-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { AttendanceResolver } from './attendance-resolver.service'; diff --git a/overlord/src/app/attendance/attendance-type.service.ts b/overlord/src/app/attendance/attendance-type.service.ts index e94811e8..1ca1101e 100644 --- a/overlord/src/app/attendance/attendance-type.service.ts +++ b/overlord/src/app/attendance/attendance-type.service.ts @@ -15,10 +15,8 @@ export class AttendanceTypeService { constructor(private http: HttpClient, private log: ErrorLoggerService) {} list(): Observable { - return >( - this.http - .get(url) - .pipe(catchError(this.log.handleError(serviceName, 'list'))) - ); + return this.http + .get(url) + .pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable; } } diff --git a/overlord/src/app/attendance/attendance.component.spec.ts b/overlord/src/app/attendance/attendance.component.spec.ts index 7a3a5780..95fcb89c 100644 --- a/overlord/src/app/attendance/attendance.component.spec.ts +++ b/overlord/src/app/attendance/attendance.component.spec.ts @@ -1,6 +1,6 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; -import { MatDialogModule } from '@angular/material/dialog'; import { ReactiveFormsModule } from '@angular/forms'; +import { MatDialogModule } from '@angular/material/dialog'; import { RouterTestingModule } from '@angular/router/testing'; import { AttendanceComponent } from './attendance.component'; diff --git a/overlord/src/app/attendance/attendance.service.spec.ts b/overlord/src/app/attendance/attendance.service.spec.ts index b0fbbbd6..4814f723 100644 --- a/overlord/src/app/attendance/attendance.service.spec.ts +++ b/overlord/src/app/attendance/attendance.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { AttendanceService } from './attendance.service'; diff --git a/overlord/src/app/attendance/attendance.service.ts b/overlord/src/app/attendance/attendance.service.ts index b93881b8..4ab12b49 100644 --- a/overlord/src/app/attendance/attendance.service.ts +++ b/overlord/src/app/attendance/attendance.service.ts @@ -7,10 +7,6 @@ import { ErrorLoggerService } from '../core/error-logger.service'; import { Attendance } from './attendance'; -const httpOptions = { - headers: new HttpHeaders({ 'Content-Type': 'application/json' }), -}; - const url = '/api/attendance'; const serviceName = 'AttendanceService'; @@ -20,18 +16,16 @@ export class AttendanceService { get(date: string | null): Observable { const getUrl: string = date === null ? url : `${url}/${date}`; - return >( - this.http - .get(getUrl) - .pipe(catchError(this.log.handleError(serviceName, `get date=${date}`))) - ); + return this.http + .get(getUrl) + .pipe( + catchError(this.log.handleError(serviceName, `get date as Observable=${date}`)), + ) as Observable; } save(attendance: Attendance): Observable { - return >( - this.http - .post(`${url}/${attendance.date}`, attendance, httpOptions) - .pipe(catchError(this.log.handleError(serviceName, 'save'))) - ); + return this.http + .post(`${url}/${attendance.date}`, attendance) + .pipe(catchError(this.log.handleError(serviceName, 'save'))) as Observable; } } diff --git a/overlord/src/app/auth/auth.service.spec.ts b/overlord/src/app/auth/auth.service.spec.ts index dbc66c0c..60c47166 100644 --- a/overlord/src/app/auth/auth.service.spec.ts +++ b/overlord/src/app/auth/auth.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { AuthService } from './auth.service'; diff --git a/overlord/src/app/auth/auth.service.ts b/overlord/src/app/auth/auth.service.ts index a0f15615..30e5b482 100644 --- a/overlord/src/app/auth/auth.service.ts +++ b/overlord/src/app/auth/auth.service.ts @@ -12,8 +12,8 @@ const JWT_USER = 'JWT_USER'; @Injectable({ providedIn: 'root' }) export class AuthService { - private currentUserSubject: BehaviorSubject = new BehaviorSubject(null); public currentUser: Observable; + private currentUserSubject: BehaviorSubject = new BehaviorSubject(null); constructor(private http: HttpClient) { this.checkStorage(); diff --git a/overlord/src/app/auth/login/login.component.spec.ts b/overlord/src/app/auth/login/login.component.spec.ts index 39be77e6..12ed5ee2 100644 --- a/overlord/src/app/auth/login/login.component.spec.ts +++ b/overlord/src/app/auth/login/login.component.spec.ts @@ -1,5 +1,5 @@ -import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { LoginComponent } from './login.component'; diff --git a/overlord/src/app/auth/login/login.component.ts b/overlord/src/app/auth/login/login.component.ts index e943b8da..2b4de5d2 100644 --- a/overlord/src/app/auth/login/login.component.ts +++ b/overlord/src/app/auth/login/login.component.ts @@ -42,7 +42,9 @@ export class LoginComponent implements OnInit, AfterViewInit { ngAfterViewInit() { setTimeout(() => { - if (this.nameElement) this.nameElement.nativeElement.focus(); + if (this.nameElement) { + this.nameElement.nativeElement.focus(); + } }, 0); } diff --git a/overlord/src/app/auth/logout/logout.component.spec.ts b/overlord/src/app/auth/logout/logout.component.spec.ts index c16dede8..1a25f67a 100644 --- a/overlord/src/app/auth/logout/logout.component.spec.ts +++ b/overlord/src/app/auth/logout/logout.component.spec.ts @@ -1,5 +1,5 @@ -import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { LogoutComponent } from './logout.component'; diff --git a/overlord/src/app/balance-sheet/balance-sheet-datasource.ts b/overlord/src/app/balance-sheet/balance-sheet-datasource.ts index 8e923d99..d4302194 100644 --- a/overlord/src/app/balance-sheet/balance-sheet-datasource.ts +++ b/overlord/src/app/balance-sheet/balance-sheet-datasource.ts @@ -8,9 +8,7 @@ import { map } from 'rxjs/operators'; import { BalanceSheetItem } from './balance-sheet-item'; /** Simple sort comparator for example ID/Name columns (for client-side sorting). */ -function compare(a: string | number, b: string | number, isAsc: boolean) { - return (a < b ? -1 : 1) * (isAsc ? 1 : -1); -} +const compare = (a: string | number, b: string | number, isAsc: boolean) => (a < b ? -1 : 1) * (isAsc ? 1 : -1); export class BalanceSheetDataSource extends DataSource { constructor( public data: BalanceSheetItem[], @@ -26,11 +24,17 @@ export class BalanceSheetDataSource extends DataSource { | EventEmitter | EventEmitter )[] = [observableOf(this.data)]; - if (this.paginator) dataMutations.push((this.paginator as MatPaginator).page); - if (this.sort) dataMutations.push((this.sort as MatSort).sortChange); + if (this.paginator) { + dataMutations.push((this.paginator as MatPaginator).page); + } + if (this.sort) { + dataMutations.push((this.sort as MatSort).sortChange); + } // Set the paginators length - if (this.paginator) this.paginator.length = this.data.length; + if (this.paginator) { + this.paginator.length = this.data.length; + } return merge(...dataMutations).pipe( map(() => this.getPagedData(this.getSortedData([...this.data]))), @@ -40,13 +44,17 @@ export class BalanceSheetDataSource extends DataSource { disconnect() {} private getPagedData(data: BalanceSheetItem[]) { - if (this.paginator === undefined) return data; + if (this.paginator === undefined) { + return data; + } const startIndex = this.paginator.pageIndex * this.paginator.pageSize; return data.splice(startIndex, this.paginator.pageSize); } private getSortedData(data: BalanceSheetItem[]) { - if (this.sort === undefined) return data; + if (this.sort === undefined) { + return data; + } if (!this.sort.active || this.sort.direction === '') { return data; } @@ -56,7 +64,9 @@ export class BalanceSheetDataSource extends DataSource { const isAsc = sort.direction === 'asc'; switch (sort.active) { case 'name': - if (a.name === undefined || b.name === undefined) return 0; + if (a.name === undefined || b.name === undefined) { + return 0; + } return compare(a.name, b.name, isAsc); default: return 0; diff --git a/overlord/src/app/balance-sheet/balance-sheet-resolver.service.spec.ts b/overlord/src/app/balance-sheet/balance-sheet-resolver.service.spec.ts index 6edb6a85..496f9f46 100644 --- a/overlord/src/app/balance-sheet/balance-sheet-resolver.service.spec.ts +++ b/overlord/src/app/balance-sheet/balance-sheet-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { BalanceSheetResolver } from './balance-sheet-resolver.service'; diff --git a/overlord/src/app/balance-sheet/balance-sheet.service.spec.ts b/overlord/src/app/balance-sheet/balance-sheet.service.spec.ts index c3821bb3..dbd8e1cb 100644 --- a/overlord/src/app/balance-sheet/balance-sheet.service.spec.ts +++ b/overlord/src/app/balance-sheet/balance-sheet.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { BalanceSheetService } from './balance-sheet.service'; diff --git a/overlord/src/app/balance-sheet/balance-sheet.service.ts b/overlord/src/app/balance-sheet/balance-sheet.service.ts index c9e834eb..70fee5e8 100644 --- a/overlord/src/app/balance-sheet/balance-sheet.service.ts +++ b/overlord/src/app/balance-sheet/balance-sheet.service.ts @@ -18,10 +18,8 @@ export class BalanceSheetService { list(date: string | null): Observable { const listUrl = date === null ? url : `${url}/${date}`; - return >( - this.http - .get(listUrl) - .pipe(catchError(this.log.handleError(serviceName, 'list'))) - ); + return this.http + .get(listUrl) + .pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable; } } diff --git a/overlord/src/app/cash-flow/cash-flow-resolver.service.spec.ts b/overlord/src/app/cash-flow/cash-flow-resolver.service.spec.ts index c5712f8f..426cf889 100644 --- a/overlord/src/app/cash-flow/cash-flow-resolver.service.spec.ts +++ b/overlord/src/app/cash-flow/cash-flow-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { CashFlowResolver } from './cash-flow-resolver.service'; diff --git a/overlord/src/app/cash-flow/cash-flow.service.spec.ts b/overlord/src/app/cash-flow/cash-flow.service.spec.ts index 9f59cbef..76fd1dd1 100644 --- a/overlord/src/app/cash-flow/cash-flow.service.spec.ts +++ b/overlord/src/app/cash-flow/cash-flow.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { CashFlowService } from './cash-flow.service'; diff --git a/overlord/src/app/cash-flow/cash-flow.service.ts b/overlord/src/app/cash-flow/cash-flow.service.ts index 900a2d3f..627e792f 100644 --- a/overlord/src/app/cash-flow/cash-flow.service.ts +++ b/overlord/src/app/cash-flow/cash-flow.service.ts @@ -36,10 +36,8 @@ export class CashFlowService { } else { listUrl = url; } - return >( - this.http - .get(listUrl, options) - .pipe(catchError(this.log.handleError(serviceName, 'list'))) - ); + return this.http + .get(listUrl, options) + .pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable; } } diff --git a/overlord/src/app/cash-flow/cash-flow.ts b/overlord/src/app/cash-flow/cash-flow.ts index 9b90749b..216f36d8 100644 --- a/overlord/src/app/cash-flow/cash-flow.ts +++ b/overlord/src/app/cash-flow/cash-flow.ts @@ -12,6 +12,18 @@ export class CashFlow { footer?: CashFlowItem[]; + public constructor(init?: Partial) { + this.startDate = ''; + this.finishDate = ''; + this.body = { + operating: [], + investing: [], + financing: [], + details: [], + }; + Object.assign(this, init); + } + static Data(value: CashFlow): CashFlowItem[] { const d: CashFlowItem[] = []; if (value.body.operating?.length) { @@ -31,16 +43,4 @@ export class CashFlow { } return d; } - - public constructor(init?: Partial) { - this.startDate = ''; - this.finishDate = ''; - this.body = { - operating: [], - investing: [], - financing: [], - details: [], - }; - Object.assign(this, init); - } } diff --git a/overlord/src/app/client/client-detail/client-detail.component.spec.ts b/overlord/src/app/client/client-detail/client-detail.component.spec.ts index df8712a2..23a5ccf5 100644 --- a/overlord/src/app/client/client-detail/client-detail.component.spec.ts +++ b/overlord/src/app/client/client-detail/client-detail.component.spec.ts @@ -1,6 +1,6 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; -import { MatDialogModule } from '@angular/material/dialog'; import { ReactiveFormsModule } from '@angular/forms'; +import { MatDialogModule } from '@angular/material/dialog'; import { RouterTestingModule } from '@angular/router/testing'; import { ClientDetailComponent } from './client-detail.component'; diff --git a/overlord/src/app/client/client-detail/client-detail.component.ts b/overlord/src/app/client/client-detail/client-detail.component.ts index 44a50b4e..693327ea 100644 --- a/overlord/src/app/client/client-detail/client-detail.component.ts +++ b/overlord/src/app/client/client-detail/client-detail.component.ts @@ -54,7 +54,9 @@ export class ClientDetailComponent implements OnInit, AfterViewInit { ngAfterViewInit() { setTimeout(() => { - if (this.nameElement) this.nameElement.nativeElement.focus(); + if (this.nameElement) { + this.nameElement.nativeElement.focus(); + } }, 0); } diff --git a/overlord/src/app/client/client-list-resolver.service.spec.ts b/overlord/src/app/client/client-list-resolver.service.spec.ts index bb811d0a..cc6c9d01 100644 --- a/overlord/src/app/client/client-list-resolver.service.spec.ts +++ b/overlord/src/app/client/client-list-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { ClientListResolver } from './client-list-resolver.service'; diff --git a/overlord/src/app/client/client-list/client-list-datasource.ts b/overlord/src/app/client/client-list/client-list-datasource.ts index 812a74e9..88448369 100644 --- a/overlord/src/app/client/client-list/client-list-datasource.ts +++ b/overlord/src/app/client/client-list/client-list-datasource.ts @@ -8,9 +8,7 @@ import { map } from 'rxjs/operators'; import { Client } from '../client'; /** Simple sort comparator for example ID/Name columns (for client-side sorting). */ -function compare(a: string | number, b: string | number, isAsc: boolean) { - return (a < b ? -1 : 1) * (isAsc ? 1 : -1); -} +const compare = (a: string | number, b: string | number, isAsc: boolean) => (a < b ? -1 : 1) * (isAsc ? 1 : -1); export class ClientListDataSource extends DataSource { constructor(public data: Client[], private paginator?: MatPaginator, private sort?: MatSort) { super(); @@ -20,11 +18,17 @@ export class ClientListDataSource extends DataSource { const dataMutations: (Observable | EventEmitter | EventEmitter)[] = [ observableOf(this.data), ]; - if (this.paginator) dataMutations.push((this.paginator as MatPaginator).page); - if (this.sort) dataMutations.push((this.sort as MatSort).sortChange); + if (this.paginator) { + dataMutations.push((this.paginator as MatPaginator).page); + } + if (this.sort) { + dataMutations.push((this.sort as MatSort).sortChange); + } // Set the paginators length - if (this.paginator) this.paginator.length = this.data.length; + if (this.paginator) { + this.paginator.length = this.data.length; + } return merge(...dataMutations).pipe( map(() => this.getPagedData(this.getSortedData([...this.data]))), @@ -34,13 +38,17 @@ export class ClientListDataSource extends DataSource { disconnect() {} private getPagedData(data: Client[]) { - if (this.paginator === undefined) return data; + if (this.paginator === undefined) { + return data; + } const startIndex = this.paginator.pageIndex * this.paginator.pageSize; return data.splice(startIndex, this.paginator.pageSize); } private getSortedData(data: Client[]) { - if (this.sort === undefined) return data; + if (this.sort === undefined) { + return data; + } if (!this.sort.active || this.sort.direction === '') { return data; } diff --git a/overlord/src/app/client/client-resolver.service.spec.ts b/overlord/src/app/client/client-resolver.service.spec.ts index b7c8f219..46cf2d71 100644 --- a/overlord/src/app/client/client-resolver.service.spec.ts +++ b/overlord/src/app/client/client-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { ClientResolver } from './client-resolver.service'; diff --git a/overlord/src/app/client/client.service.spec.ts b/overlord/src/app/client/client.service.spec.ts index 89debca7..ccfe428f 100644 --- a/overlord/src/app/client/client.service.spec.ts +++ b/overlord/src/app/client/client.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { ClientService } from './client.service'; diff --git a/overlord/src/app/client/client.service.ts b/overlord/src/app/client/client.service.ts index 0f11ffca..7d2b6dca 100644 --- a/overlord/src/app/client/client.service.ts +++ b/overlord/src/app/client/client.service.ts @@ -7,9 +7,6 @@ import { ErrorLoggerService } from '../core/error-logger.service'; import { Client } from './client'; -const httpOptions = { - headers: new HttpHeaders({ 'Content-Type': 'application/json' }), -}; const url = '/api/clients'; const serviceName = 'ClientService'; @@ -21,34 +18,26 @@ export class ClientService { get(id: string | null): Observable { const getUrl: string = id === null ? url : `${url}/${id}`; - return >( - this.http - .get(getUrl) - .pipe(catchError(this.log.handleError(serviceName, `get id=${id}`))) - ); + return this.http + .get(getUrl) + .pipe(catchError(this.log.handleError(serviceName, `get id as Observable=${id}`))) as Observable; } list(): Observable { - return >( - this.http - .get(`${url}/list`) - .pipe(catchError(this.log.handleError(serviceName, 'list'))) - ); + return this.http + .get(`${url}/list`) + .pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable; } update(client: Client): Observable { - return >( - this.http - .put(`${url}/${client.id}`, client, httpOptions) - .pipe(catchError(this.log.handleError(serviceName, 'update'))) - ); + return this.http + .put(`${url}/${client.id}`, client) + .pipe(catchError(this.log.handleError(serviceName, 'update'))) as Observable; } delete(id: string): Observable { - return >( - this.http - .delete(`${url}/${id}`, httpOptions) - .pipe(catchError(this.log.handleError(serviceName, 'delete'))) - ); + return this.http + .delete(`${url}/${id}`) + .pipe(catchError(this.log.handleError(serviceName, 'delete'))) as Observable; } } diff --git a/overlord/src/app/closing-stock/closing-stock-datasource.ts b/overlord/src/app/closing-stock/closing-stock-datasource.ts index e2e7377b..4a6ec09b 100644 --- a/overlord/src/app/closing-stock/closing-stock-datasource.ts +++ b/overlord/src/app/closing-stock/closing-stock-datasource.ts @@ -8,9 +8,7 @@ import { map } from 'rxjs/operators'; import { ClosingStockItem } from './closing-stock-item'; /** Simple sort comparator for example ID/Name columns (for client-side sorting). */ -function compare(a: string | number, b: string | number, isAsc: boolean) { - return (a < b ? -1 : 1) * (isAsc ? 1 : -1); -} +const compare = (a: string | number, b: string | number, isAsc: boolean) => (a < b ? -1 : 1) * (isAsc ? 1 : -1); export class ClosingStockDataSource extends DataSource { constructor( public data: ClosingStockItem[], @@ -26,11 +24,17 @@ export class ClosingStockDataSource extends DataSource { | EventEmitter | EventEmitter )[] = [observableOf(this.data)]; - if (this.paginator) dataMutations.push((this.paginator as MatPaginator).page); - if (this.sort) dataMutations.push((this.sort as MatSort).sortChange); + if (this.paginator) { + dataMutations.push((this.paginator as MatPaginator).page); + } + if (this.sort) { + dataMutations.push((this.sort as MatSort).sortChange); + } // Set the paginators length - if (this.paginator) this.paginator.length = this.data.length; + if (this.paginator) { + this.paginator.length = this.data.length; + } return merge(...dataMutations).pipe( map(() => this.getPagedData(this.getSortedData([...this.data]))), @@ -40,13 +44,17 @@ export class ClosingStockDataSource extends DataSource { disconnect() {} private getPagedData(data: ClosingStockItem[]) { - if (this.paginator === undefined) return data; + if (this.paginator === undefined) { + return data; + } const startIndex = this.paginator.pageIndex * this.paginator.pageSize; return data.splice(startIndex, this.paginator.pageSize); } private getSortedData(data: ClosingStockItem[]) { - if (this.sort === undefined) return data; + if (this.sort === undefined) { + return data; + } if (!this.sort.active || this.sort.direction === '') { return data; } diff --git a/overlord/src/app/closing-stock/closing-stock-resolver.service.spec.ts b/overlord/src/app/closing-stock/closing-stock-resolver.service.spec.ts index 003ca74c..fae8af23 100644 --- a/overlord/src/app/closing-stock/closing-stock-resolver.service.spec.ts +++ b/overlord/src/app/closing-stock/closing-stock-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { ClosingStockResolver } from './closing-stock-resolver.service'; diff --git a/overlord/src/app/closing-stock/closing-stock.service.spec.ts b/overlord/src/app/closing-stock/closing-stock.service.spec.ts index 4f242f5e..7cf3d6c3 100644 --- a/overlord/src/app/closing-stock/closing-stock.service.spec.ts +++ b/overlord/src/app/closing-stock/closing-stock.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { ClosingStockService } from './closing-stock.service'; diff --git a/overlord/src/app/closing-stock/closing-stock.service.ts b/overlord/src/app/closing-stock/closing-stock.service.ts index 1f136227..feb05d6d 100644 --- a/overlord/src/app/closing-stock/closing-stock.service.ts +++ b/overlord/src/app/closing-stock/closing-stock.service.ts @@ -18,10 +18,8 @@ export class ClosingStockService { list(date: string | null): Observable { const listUrl = date === null ? url : `${url}/${date}`; - return >( - this.http - .get(listUrl) - .pipe(catchError(this.log.handleError(serviceName, 'list'))) - ); + return this.http + .get(listUrl) + .pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable; } } diff --git a/overlord/src/app/core/account.service.spec.ts b/overlord/src/app/core/account.service.spec.ts index 667116e6..24338dd7 100644 --- a/overlord/src/app/core/account.service.spec.ts +++ b/overlord/src/app/core/account.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { AccountService } from './account.service'; diff --git a/overlord/src/app/core/account.service.ts b/overlord/src/app/core/account.service.ts index c24e3c09..e48cfdce 100644 --- a/overlord/src/app/core/account.service.ts +++ b/overlord/src/app/core/account.service.ts @@ -7,10 +7,6 @@ import { Account } from './account'; import { AccountBalance } from './account-balance'; import { ErrorLoggerService } from './error-logger.service'; -const httpOptions = { - headers: new HttpHeaders({ 'Content-Type': 'application/json' }), -}; - const url = '/api/accounts'; const serviceName = 'AccountService'; @@ -20,53 +16,41 @@ export class AccountService { get(id: string | null): Observable { const getUrl: string = id === null ? `${url}` : `${url}/${id}`; - return >( - this.http - .get(getUrl) - .pipe(catchError(this.log.handleError(serviceName, `get id=${id}`))) - ); + return this.http + .get(getUrl) + .pipe(catchError(this.log.handleError(serviceName, `get id as Observable=${id}`))) as Observable; } list(): Observable { - return >( - this.http - .get(`${url}/list`) - .pipe(catchError(this.log.handleError(serviceName, 'list'))) - ); + return this.http + .get(`${url}/list`) + .pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable; } paymentAutocomplete(query: string): Observable { const options = { params: new HttpParams().set('q', query).set('t', '1') }; - return >( - this.http - .get(`${url}/query`, options) - .pipe(catchError(this.log.handleError(serviceName, 'list'))) - ); + return this.http + .get(`${url}/query`, options) + .pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable; } receiptAutocomplete(query: string): Observable { const options = { params: new HttpParams().set('q', query).set('t', '1') }; - return >( - this.http - .get(`${url}/query`, options) - .pipe(catchError(this.log.handleError(serviceName, 'list'))) - ); + return this.http + .get(`${url}/query`, options) + .pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable; } save(account: Account): Observable { - return >( - this.http - .post(`${url}`, account, httpOptions) - .pipe(catchError(this.log.handleError(serviceName, 'save'))) - ); + return this.http + .post(`${url}`, account) + .pipe(catchError(this.log.handleError(serviceName, 'save'))) as Observable; } update(account: Account): Observable { - return >( - this.http - .put(`${url}/${account.id}`, account, httpOptions) - .pipe(catchError(this.log.handleError(serviceName, 'update'))) - ); + return this.http + .put(`${url}/${account.id}`, account) + .pipe(catchError(this.log.handleError(serviceName, 'update'))) as Observable; } saveOrUpdate(account: Account): Observable { @@ -77,28 +61,22 @@ export class AccountService { } delete(id: string): Observable { - return >( - this.http - .delete(`${url}/${id}`, httpOptions) - .pipe(catchError(this.log.handleError(serviceName, 'delete'))) - ); + return this.http + .delete(`${url}/${id}`) + .pipe(catchError(this.log.handleError(serviceName, 'delete'))) as Observable; } autocomplete(query: string): Observable { const options = { params: new HttpParams().set('q', query) }; - return >( - this.http - .get(`${url}/query`, options) - .pipe(catchError(this.log.handleError(serviceName, 'autocomplete'))) - ); + return this.http + .get(`${url}/query`, options) + .pipe(catchError(this.log.handleError(serviceName, 'autocomplete'))) as Observable; } balance(id: string, date: string): Observable { const options = { params: new HttpParams().set('d', date) }; - return >( - this.http - .get(`${url}/${id}/balance`, options) - .pipe(catchError(this.log.handleError(serviceName, 'balance'))) - ); + return this.http + .get(`${url}/${id}/balance`, options) + .pipe(catchError(this.log.handleError(serviceName, 'balance'))) as Observable; } } diff --git a/overlord/src/app/core/batch.service.ts b/overlord/src/app/core/batch.service.ts index 614c19f1..2b62239e 100644 --- a/overlord/src/app/core/batch.service.ts +++ b/overlord/src/app/core/batch.service.ts @@ -15,10 +15,8 @@ export class BatchService { autocomplete(date: string, term: string): Observable { const options = { params: new HttpParams().set('q', term).set('d', date) }; - return >( - this.http - .get(url, options) - .pipe(catchError(this.log.handleError(serviceName, 'autocomplete'))) - ); + return this.http + .get(url, options) + .pipe(catchError(this.log.handleError(serviceName, 'autocomplete'))) as Observable; } } diff --git a/overlord/src/app/core/error-logger.service.ts b/overlord/src/app/core/error-logger.service.ts index 3d875cf7..16a2bdf8 100644 --- a/overlord/src/app/core/error-logger.service.ts +++ b/overlord/src/app/core/error-logger.service.ts @@ -14,6 +14,7 @@ export class ErrorLoggerService { /** * Handle Http operation that failed. * Let the app continue. + * * @param operation - name of the operation that failed * @param result - optional value to return as the observable result */ diff --git a/overlord/src/app/core/http-auth-interceptor.ts b/overlord/src/app/core/http-auth-interceptor.ts index 25c2b4b7..54326433 100644 --- a/overlord/src/app/core/http-auth-interceptor.ts +++ b/overlord/src/app/core/http-auth-interceptor.ts @@ -46,7 +46,9 @@ export class ErrorInterceptor implements HttpInterceptor { 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.', + 'You have been logged out.\n' + + 'You 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) => { diff --git a/overlord/src/app/core/nav-bar/nav-bar.component.html b/overlord/src/app/core/nav-bar/nav-bar.component.html index 8e7439ec..384b9e4b 100644 --- a/overlord/src/app/core/nav-bar/nav-bar.component.html +++ b/overlord/src/app/core/nav-bar/nav-bar.component.html @@ -69,7 +69,7 @@ account_box {{ name }} - + account_box Login diff --git a/overlord/src/app/core/voucher.service.spec.ts b/overlord/src/app/core/voucher.service.spec.ts index 2d40efd3..42c96843 100644 --- a/overlord/src/app/core/voucher.service.spec.ts +++ b/overlord/src/app/core/voucher.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { VoucherService } from './voucher.service'; diff --git a/overlord/src/app/core/voucher.service.ts b/overlord/src/app/core/voucher.service.ts index d141f067..d3751203 100644 --- a/overlord/src/app/core/voucher.service.ts +++ b/overlord/src/app/core/voucher.service.ts @@ -6,10 +6,6 @@ import { catchError } from 'rxjs/operators'; import { ErrorLoggerService } from './error-logger.service'; import { Voucher } from './voucher'; -const httpOptions = { - headers: new HttpHeaders({ 'Content-Type': 'application/json' }), -}; - const url = '/api'; const serviceName = 'VoucherService'; @@ -36,11 +32,9 @@ export class VoucherService { get(id: string, type: string): Observable { const endpoint = type.replace(/ /g, '-').toLowerCase(); - return >( - this.http - .get(`${url}/${endpoint}/${id}`) - .pipe(catchError(this.log.handleError(serviceName, 'Get Voucher'))) - ); + return this.http + .get(`${url}/${endpoint}/${id}`) + .pipe(catchError(this.log.handleError(serviceName, 'Get Voucher'))) as Observable; } getOfType(type: string, account?: string): Observable { @@ -50,36 +44,30 @@ export class VoucherService { // eslint-disable-next-line @typescript-eslint/dot-notation options = { params: new HttpParams().set('a', account) }; } - return >( - this.http - .get(`${url}/${endpoint}`, options) - .pipe(catchError(this.log.handleError(serviceName, 'Get Voucher of Type'))) - ); + return this.http + .get(`${url}/${endpoint}`, options) + .pipe( + catchError(this.log.handleError(serviceName, 'Get Voucher of Type')), + ) as Observable; } getIncentive(date: string): Observable { const options = { params: new HttpParams().set('d', date) }; - return >( - this.http - .get(`${url}/incentive`, options) - .pipe(catchError(this.log.handleError(serviceName, 'Get Incentive'))) - ); + return this.http + .get(`${url}/incentive`, options) + .pipe(catchError(this.log.handleError(serviceName, 'Get Incentive'))) as Observable; } post(id: string): Observable { - return >( - this.http - .post(`${url}/post-voucher/${id}`, {}) - .pipe(catchError(this.log.handleError(serviceName, 'Post Voucher'))) - ); + return this.http + .post(`${url}/post as Observable-voucher/${id}`, {}) + .pipe(catchError(this.log.handleError(serviceName, 'Post Voucher'))) as Observable; } delete(id: string): Observable { - return >( - this.http - .delete(`${url}/delete/${id}`, httpOptions) - .pipe(catchError(this.log.handleError(serviceName, 'Delete Voucher'))) - ); + return this.http + .delete(`${url}/delete/${id}`) + .pipe(catchError(this.log.handleError(serviceName, 'Delete Voucher'))) as Observable; } saveOrUpdate(voucher: Voucher): Observable { @@ -100,11 +88,9 @@ export class VoucherService { }); voucher.files = voucher.files.filter((x) => x.id); fd.append('data', JSON.stringify(voucher)); - return >( - this.http - .post(`${url}/${endpoint}`, fd) - .pipe(catchError(this.log.handleError(serviceName, 'Save Voucher'))) - ); + return this.http + .post(`${url}/${endpoint}`, fd) + .pipe(catchError(this.log.handleError(serviceName, 'Save Voucher'))) as Observable; } update(voucher: Voucher, endpoint: string): Observable { @@ -117,10 +103,8 @@ export class VoucherService { }); voucher.files = voucher.files.filter((x) => x.id); fd.append('data', JSON.stringify(voucher)); - return >( - this.http - .put(`${url}/${endpoint}/${voucher.id}`, fd) - .pipe(catchError(this.log.handleError(serviceName, 'Update Voucher'))) - ); + return this.http + .put(`${url}/${endpoint}/${voucher.id}`, fd) + .pipe(catchError(this.log.handleError(serviceName, 'Update Voucher'))) as Observable; } } diff --git a/overlord/src/app/cost-centre/cost-centre-detail/cost-centre-detail.component.ts b/overlord/src/app/cost-centre/cost-centre-detail/cost-centre-detail.component.ts index 22f192a8..47485721 100644 --- a/overlord/src/app/cost-centre/cost-centre-detail/cost-centre-detail.component.ts +++ b/overlord/src/app/cost-centre/cost-centre-detail/cost-centre-detail.component.ts @@ -45,7 +45,9 @@ export class CostCentreDetailComponent implements OnInit, AfterViewInit { ngAfterViewInit() { setTimeout(() => { - if (this.nameElement) this.nameElement.nativeElement.focus(); + if (this.nameElement) { + this.nameElement.nativeElement.focus(); + } }, 0); } diff --git a/overlord/src/app/cost-centre/cost-centre-list-resolver.service.spec.ts b/overlord/src/app/cost-centre/cost-centre-list-resolver.service.spec.ts index b06bd349..712ed632 100644 --- a/overlord/src/app/cost-centre/cost-centre-list-resolver.service.spec.ts +++ b/overlord/src/app/cost-centre/cost-centre-list-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { CostCentreListResolver } from './cost-centre-list-resolver.service'; diff --git a/overlord/src/app/cost-centre/cost-centre-list/cost-centre-list-datasource.ts b/overlord/src/app/cost-centre/cost-centre-list/cost-centre-list-datasource.ts index c18fa0b8..9fcc02ab 100644 --- a/overlord/src/app/cost-centre/cost-centre-list/cost-centre-list-datasource.ts +++ b/overlord/src/app/cost-centre/cost-centre-list/cost-centre-list-datasource.ts @@ -8,9 +8,7 @@ import { map } from 'rxjs/operators'; import { CostCentre } from '../../core/cost-centre'; /** Simple sort comparator for example ID/Name columns (for client-side sorting). */ -function compare(a: string | number, b: string | number, isAsc: boolean) { - return (a < b ? -1 : 1) * (isAsc ? 1 : -1); -} +const compare = (a: string | number, b: string | number, isAsc: boolean) => (a < b ? -1 : 1) * (isAsc ? 1 : -1); export class CostCentreListDataSource extends DataSource { constructor(public data: CostCentre[], private paginator?: MatPaginator, private sort?: MatSort) { super(); @@ -22,11 +20,17 @@ export class CostCentreListDataSource extends DataSource { | EventEmitter | EventEmitter )[] = [observableOf(this.data)]; - if (this.paginator) dataMutations.push((this.paginator as MatPaginator).page); - if (this.sort) dataMutations.push((this.sort as MatSort).sortChange); + if (this.paginator) { + dataMutations.push((this.paginator as MatPaginator).page); + } + if (this.sort) { + dataMutations.push((this.sort as MatSort).sortChange); + } // Set the paginators length - if (this.paginator) this.paginator.length = this.data.length; + if (this.paginator) { + this.paginator.length = this.data.length; + } return merge(...dataMutations).pipe( map(() => this.getPagedData(this.getSortedData([...this.data]))), @@ -36,13 +40,17 @@ export class CostCentreListDataSource extends DataSource { disconnect() {} private getPagedData(data: CostCentre[]) { - if (this.paginator === undefined) return data; + if (this.paginator === undefined) { + return data; + } const startIndex = this.paginator.pageIndex * this.paginator.pageSize; return data.splice(startIndex, this.paginator.pageSize); } private getSortedData(data: CostCentre[]) { - if (this.sort === undefined) return data; + if (this.sort === undefined) { + return data; + } if (!this.sort.active || this.sort.direction === '') { return data; } diff --git a/overlord/src/app/cost-centre/cost-centre-resolver.service.spec.ts b/overlord/src/app/cost-centre/cost-centre-resolver.service.spec.ts index d021a0f1..bbe55c58 100644 --- a/overlord/src/app/cost-centre/cost-centre-resolver.service.spec.ts +++ b/overlord/src/app/cost-centre/cost-centre-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { CostCentreResolver } from './cost-centre-resolver.service'; diff --git a/overlord/src/app/cost-centre/cost-centre.service.spec.ts b/overlord/src/app/cost-centre/cost-centre.service.spec.ts index ace5ae2d..40925391 100644 --- a/overlord/src/app/cost-centre/cost-centre.service.spec.ts +++ b/overlord/src/app/cost-centre/cost-centre.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { CostCentreService } from './cost-centre.service'; diff --git a/overlord/src/app/cost-centre/cost-centre.service.ts b/overlord/src/app/cost-centre/cost-centre.service.ts index 250b8faf..257a9ab8 100644 --- a/overlord/src/app/cost-centre/cost-centre.service.ts +++ b/overlord/src/app/cost-centre/cost-centre.service.ts @@ -6,9 +6,6 @@ import { catchError } from 'rxjs/operators'; import { CostCentre } from '../core/cost-centre'; import { ErrorLoggerService } from '../core/error-logger.service'; -const httpOptions = { - headers: new HttpHeaders({ 'Content-Type': 'application/json' }), -}; const url = '/api/cost-centres'; const serviceName = 'CostCentreService'; @@ -20,35 +17,29 @@ export class CostCentreService { get(id: string | null): Observable { const getUrl: string = id === null ? `${url}` : `${url}/${id}`; - return >( - this.http - .get(getUrl) - .pipe(catchError(this.log.handleError(serviceName, `get id=${id}`))) - ); + return this.http + .get(getUrl) + .pipe( + catchError(this.log.handleError(serviceName, `get id as Observable=${id}`)), + ) as Observable; } list(): Observable { - return >( - this.http - .get(`${url}/list`) - .pipe(catchError(this.log.handleError(serviceName, 'list'))) - ); + return this.http + .get(`${url}/list`) + .pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable; } save(costCentre: CostCentre): Observable { - return >( - this.http - .post(`${url}`, costCentre, httpOptions) - .pipe(catchError(this.log.handleError(serviceName, 'save'))) - ); + return this.http + .post(`${url}`, costCentre) + .pipe(catchError(this.log.handleError(serviceName, 'save'))) as Observable; } update(costCentre: CostCentre): Observable { - return >( - this.http - .put(`${url}/${costCentre.id}`, costCentre, httpOptions) - .pipe(catchError(this.log.handleError(serviceName, 'update'))) - ); + return this.http + .put(`${url}/${costCentre.id}`, costCentre) + .pipe(catchError(this.log.handleError(serviceName, 'update'))) as Observable; } saveOrUpdate(costCentre: CostCentre): Observable { @@ -59,10 +50,8 @@ export class CostCentreService { } delete(id: string): Observable { - return >( - this.http - .delete(`${url}/${id}`, httpOptions) - .pipe(catchError(this.log.handleError(serviceName, 'delete'))) - ); + return this.http + .delete(`${url}/${id}`) + .pipe(catchError(this.log.handleError(serviceName, 'delete'))) as Observable; } } diff --git a/overlord/src/app/daybook/daybook-datasource.ts b/overlord/src/app/daybook/daybook-datasource.ts index d201bc60..a9edd272 100644 --- a/overlord/src/app/daybook/daybook-datasource.ts +++ b/overlord/src/app/daybook/daybook-datasource.ts @@ -8,9 +8,7 @@ import { map } from 'rxjs/operators'; import { DaybookItem } from './daybook-item'; /** Simple sort comparator for example ID/Name columns (for client-side sorting). */ -function compare(a: string | number, b: string | number, isAsc: boolean) { - return (a < b ? -1 : 1) * (isAsc ? 1 : -1); -} +const compare = (a: string | number, b: string | number, isAsc: boolean) => (a < b ? -1 : 1) * (isAsc ? 1 : -1); export class DaybookDataSource extends DataSource { constructor( public data: DaybookItem[], @@ -26,11 +24,17 @@ export class DaybookDataSource extends DataSource { | EventEmitter | EventEmitter )[] = [observableOf(this.data)]; - if (this.paginator) dataMutations.push((this.paginator as MatPaginator).page); - if (this.sort) dataMutations.push((this.sort as MatSort).sortChange); + if (this.paginator) { + dataMutations.push((this.paginator as MatPaginator).page); + } + if (this.sort) { + dataMutations.push((this.sort as MatSort).sortChange); + } // Set the paginators length - if (this.paginator) this.paginator.length = this.data.length; + if (this.paginator) { + this.paginator.length = this.data.length; + } return merge(...dataMutations).pipe( map(() => this.getPagedData(this.getSortedData([...this.data]))), @@ -40,13 +44,17 @@ export class DaybookDataSource extends DataSource { disconnect() {} private getPagedData(data: DaybookItem[]) { - if (this.paginator === undefined) return data; + if (this.paginator === undefined) { + return data; + } const startIndex = this.paginator.pageIndex * this.paginator.pageSize; return data.splice(startIndex, this.paginator.pageSize); } private getSortedData(data: DaybookItem[]) { - if (this.sort === undefined) return data; + if (this.sort === undefined) { + return data; + } if (!this.sort.active || this.sort.direction === '') { return data; } diff --git a/overlord/src/app/daybook/daybook-resolver.service.spec.ts b/overlord/src/app/daybook/daybook-resolver.service.spec.ts index 90da8452..63c41bc7 100644 --- a/overlord/src/app/daybook/daybook-resolver.service.spec.ts +++ b/overlord/src/app/daybook/daybook-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { DaybookResolver } from './daybook-resolver.service'; diff --git a/overlord/src/app/daybook/daybook.service.spec.ts b/overlord/src/app/daybook/daybook.service.spec.ts index 038adb9b..80e55074 100644 --- a/overlord/src/app/daybook/daybook.service.spec.ts +++ b/overlord/src/app/daybook/daybook.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { DaybookService } from './daybook.service'; diff --git a/overlord/src/app/daybook/daybook.service.ts b/overlord/src/app/daybook/daybook.service.ts index 9a36cca8..db8a4f43 100644 --- a/overlord/src/app/daybook/daybook.service.ts +++ b/overlord/src/app/daybook/daybook.service.ts @@ -19,10 +19,8 @@ export class DaybookService { list(startDate: string | null, finishDate: string | null): Observable { const startDateWithSlash = startDate ? `/${startDate}` : ''; const finishDateWithSlash = finishDate ? `/${finishDate}` : ''; - return >( - this.http - .get(`${url}${startDateWithSlash}${finishDateWithSlash}`) - .pipe(catchError(this.log.handleError(serviceName, 'list'))) - ); + return this.http + .get(`${url}${startDateWithSlash}${finishDateWithSlash}`) + .pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable; } } diff --git a/overlord/src/app/employee-attendance/employee-attendance.component.ts b/overlord/src/app/employee-attendance/employee-attendance.component.ts index afb3e3e9..b8628d08 100644 --- a/overlord/src/app/employee-attendance/employee-attendance.component.ts +++ b/overlord/src/app/employee-attendance/employee-attendance.component.ts @@ -95,7 +95,9 @@ export class EmployeeAttendanceComponent implements OnInit, AfterViewInit { ngAfterViewInit() { setTimeout(() => { - if (this.employeeElement) this.employeeElement.nativeElement.focus(); + if (this.employeeElement) { + this.employeeElement.nativeElement.focus(); + } }, 0); } diff --git a/overlord/src/app/employee-attendance/employee-attendance.service.ts b/overlord/src/app/employee-attendance/employee-attendance.service.ts index ec06dd22..ec4d998b 100644 --- a/overlord/src/app/employee-attendance/employee-attendance.service.ts +++ b/overlord/src/app/employee-attendance/employee-attendance.service.ts @@ -7,10 +7,6 @@ import { ErrorLoggerService } from '../core/error-logger.service'; import { EmployeeAttendance } from './employee-attendance'; -const httpOptions = { - headers: new HttpHeaders({ 'Content-Type': 'application/json' }), -}; - const url = '/api/employee-attendance'; const serviceName = 'EmployeeAttendanceService'; @@ -31,19 +27,21 @@ export class EmployeeAttendanceService { if (finishDate !== null) { options.params = options.params.set('f', finishDate); } - return >( - this.http - .get(getUrl, options) - .pipe(catchError(this.log.handleError(serviceName, `get id=${id}`))) - ); + return this.http + .get(getUrl, options) + .pipe( + catchError( + this.log.handleError(serviceName, `get id as Observable=${id}`), + ), + ) as Observable; } save(employeeAttendance: EmployeeAttendance): Observable { const { id } = employeeAttendance.employee; - return >( - this.http - .post(`${url}/${id}`, employeeAttendance, httpOptions) - .pipe(catchError(this.log.handleError(serviceName, 'save'))) - ); + return this.http + .post(`${url}/${id}`, employeeAttendance) + .pipe( + catchError(this.log.handleError(serviceName, 'save')), + ) as Observable; } } diff --git a/overlord/src/app/employee-benefits/employee-benefits.component.ts b/overlord/src/app/employee-benefits/employee-benefits.component.ts index bf9a763c..63e25ceb 100644 --- a/overlord/src/app/employee-benefits/employee-benefits.component.ts +++ b/overlord/src/app/employee-benefits/employee-benefits.component.ts @@ -110,7 +110,9 @@ export class EmployeeBenefitsComponent implements OnInit, AfterViewInit { ngAfterViewInit() { setTimeout(() => { - if (this.employeeElement) this.employeeElement.nativeElement.focus(); + if (this.employeeElement) { + this.employeeElement.nativeElement.focus(); + } }, 0); } @@ -176,7 +178,9 @@ export class EmployeeBenefitsComponent implements OnInit, AfterViewInit { }); this.employee = null; setTimeout(() => { - if (this.employeeElement) this.employeeElement.nativeElement.focus(); + if (this.employeeElement) { + this.employeeElement.nativeElement.focus(); + } }, 0); } @@ -194,7 +198,7 @@ export class EmployeeBenefitsComponent implements OnInit, AfterViewInit { } return ( this.voucher.user.id === (this.auth.user as User).id || - this.auth.allowed("edit-other-user's-vouchers") + this.auth.allowed('edit-other-user\'s-vouchers') ); } diff --git a/overlord/src/app/employee-functions/employee-functions.service.ts b/overlord/src/app/employee-functions/employee-functions.service.ts index 9de97b49..9cc26806 100644 --- a/overlord/src/app/employee-functions/employee-functions.service.ts +++ b/overlord/src/app/employee-functions/employee-functions.service.ts @@ -13,19 +13,19 @@ export class EmployeeFunctionsService { creditSalary(month: string): Observable { const url = '/api/credit-salary'; - return >this.http + return this.http .post(url, { month }) - .pipe(catchError(this.log.handleError(serviceName, 'creditSalary'))); + .pipe(catchError(this.log.handleError(serviceName, 'creditSalary'))) as Observable; } uploadFingerprints(fingerprintFile: File): Observable { const url = '/api/fingerprint'; const fd = new FormData(); fd.append('fingerprints', fingerprintFile); - return >( - this.http - .post(url, fd) - .pipe(catchError(this.log.handleError(serviceName, 'uploadFingerprints'))) - ); + return this.http + .post(url, fd) + .pipe( + catchError(this.log.handleError(serviceName, 'uploadFingerprints')), + ) as Observable; } } diff --git a/overlord/src/app/employee/employee-detail/employee-detail.component.spec.ts b/overlord/src/app/employee/employee-detail/employee-detail.component.spec.ts index f733d944..8e7c02f0 100644 --- a/overlord/src/app/employee/employee-detail/employee-detail.component.spec.ts +++ b/overlord/src/app/employee/employee-detail/employee-detail.component.spec.ts @@ -1,6 +1,6 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; -import { MatDialogModule } from '@angular/material/dialog'; import { ReactiveFormsModule } from '@angular/forms'; +import { MatDialogModule } from '@angular/material/dialog'; import { RouterTestingModule } from '@angular/router/testing'; import { EmployeeDetailComponent } from './employee-detail.component'; diff --git a/overlord/src/app/employee/employee-detail/employee-detail.component.ts b/overlord/src/app/employee/employee-detail/employee-detail.component.ts index 2c65d106..697597e3 100644 --- a/overlord/src/app/employee/employee-detail/employee-detail.component.ts +++ b/overlord/src/app/employee/employee-detail/employee-detail.component.ts @@ -76,7 +76,9 @@ export class EmployeeDetailComponent implements OnInit, AfterViewInit { ngAfterViewInit() { setTimeout(() => { - if (this.nameElement) this.nameElement.nativeElement.focus(); + if (this.nameElement) { + this.nameElement.nativeElement.focus(); + } }, 0); } diff --git a/overlord/src/app/employee/employee-list-resolver.service.spec.ts b/overlord/src/app/employee/employee-list-resolver.service.spec.ts index ea994a8a..e3a84852 100644 --- a/overlord/src/app/employee/employee-list-resolver.service.spec.ts +++ b/overlord/src/app/employee/employee-list-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { EmployeeListResolver } from './employee-list-resolver.service'; diff --git a/overlord/src/app/employee/employee-list/employee-list-datasource.ts b/overlord/src/app/employee/employee-list/employee-list-datasource.ts index 306e0095..bfa53fe3 100644 --- a/overlord/src/app/employee/employee-list/employee-list-datasource.ts +++ b/overlord/src/app/employee/employee-list/employee-list-datasource.ts @@ -8,9 +8,7 @@ import { map, tap } from 'rxjs/operators'; import { Employee } from '../employee'; /** Simple sort comparator for example ID/Name columns (for client-side sorting). */ -function compare(a: string | number, b: string | number, isAsc: boolean) { - return (a < b ? -1 : 1) * (isAsc ? 1 : -1); -} +const compare = (a: string | number, b: string | number, isAsc: boolean) => (a < b ? -1 : 1) * (isAsc ? 1 : -1); export class EmployeeListDataSource extends DataSource { private filterValue = ''; @@ -35,14 +33,20 @@ export class EmployeeListDataSource extends DataSource { | EventEmitter | EventEmitter )[] = [observableOf(this.data), this.filter]; - if (this.paginator) dataMutations.push((this.paginator as MatPaginator).page); - if (this.sort) dataMutations.push((this.sort as MatSort).sortChange); + if (this.paginator) { + dataMutations.push((this.paginator as MatPaginator).page); + } + if (this.sort) { + dataMutations.push((this.sort as MatSort).sortChange); + } return merge(...dataMutations) .pipe( map(() => this.getFilteredData([...this.data])), tap((x: Employee[]) => { - if (this.paginator) this.paginator.length = x.length; + if (this.paginator) { + this.paginator.length = x.length; + } }), ) .pipe(map((x: Employee[]) => this.getPagedData(this.getSortedData(x)))); @@ -64,13 +68,17 @@ export class EmployeeListDataSource extends DataSource { } private getPagedData(data: Employee[]) { - if (this.paginator === undefined) return data; + if (this.paginator === undefined) { + return data; + } const startIndex = this.paginator.pageIndex * this.paginator.pageSize; return data.splice(startIndex, this.paginator.pageSize); } private getSortedData(data: Employee[]) { - if (this.sort === undefined) return data; + if (this.sort === undefined) { + return data; + } if (!this.sort.active || this.sort.direction === '') { return data; } diff --git a/overlord/src/app/employee/employee-list/employee-list.component.ts b/overlord/src/app/employee/employee-list/employee-list.component.ts index 676901ff..87e8aa8c 100644 --- a/overlord/src/app/employee/employee-list/employee-list.component.ts +++ b/overlord/src/app/employee/employee-list/employee-list.component.ts @@ -60,7 +60,9 @@ export class EmployeeListComponent implements OnInit, AfterViewInit { ngAfterViewInit() { setTimeout(() => { - if (this.filterElement) this.filterElement.nativeElement.focus(); + if (this.filterElement) { + this.filterElement.nativeElement.focus(); + } }, 0); } diff --git a/overlord/src/app/employee/employee-resolver.service.spec.ts b/overlord/src/app/employee/employee-resolver.service.spec.ts index 63c94d59..7348550e 100644 --- a/overlord/src/app/employee/employee-resolver.service.spec.ts +++ b/overlord/src/app/employee/employee-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { EmployeeResolver } from './employee-resolver.service'; diff --git a/overlord/src/app/employee/employee.service.spec.ts b/overlord/src/app/employee/employee.service.spec.ts index 027be59e..6cc0f65c 100644 --- a/overlord/src/app/employee/employee.service.spec.ts +++ b/overlord/src/app/employee/employee.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { EmployeeService } from './employee.service'; diff --git a/overlord/src/app/employee/employee.service.ts b/overlord/src/app/employee/employee.service.ts index cc22a232..19844bc9 100644 --- a/overlord/src/app/employee/employee.service.ts +++ b/overlord/src/app/employee/employee.service.ts @@ -7,10 +7,6 @@ import { ErrorLoggerService } from '../core/error-logger.service'; import { Employee } from './employee'; -const httpOptions = { - headers: new HttpHeaders({ 'Content-Type': 'application/json' }), -}; - const url = '/api/employees'; const serviceName = 'EmployeeService'; @@ -20,35 +16,27 @@ export class EmployeeService { get(id: string | null): Observable { const getUrl: string = id === null ? `${url}` : `${url}/${id}`; - return >( - this.http - .get(getUrl) - .pipe(catchError(this.log.handleError(serviceName, `get id=${id}`))) - ); + return this.http + .get(getUrl) + .pipe(catchError(this.log.handleError(serviceName, `get id as Observable=${id}`))) as Observable; } list(): Observable { - return >( - this.http - .get(`${url}/list`) - .pipe(catchError(this.log.handleError(serviceName, 'list'))) - ); + return this.http + .get(`${url}/list`) + .pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable; } save(employee: Employee): Observable { - return >( - this.http - .post(`${url}`, employee, httpOptions) - .pipe(catchError(this.log.handleError(serviceName, 'save'))) - ); + return this.http + .post(`${url}`, employee) + .pipe(catchError(this.log.handleError(serviceName, 'save'))) as Observable; } update(employee: Employee): Observable { - return >( - this.http - .put(`${url}/${employee.id}`, employee, httpOptions) - .pipe(catchError(this.log.handleError(serviceName, 'update'))) - ); + return this.http + .put(`${url}/${employee.id}`, employee) + .pipe(catchError(this.log.handleError(serviceName, 'update'))) as Observable; } saveOrUpdate(employee: Employee): Observable { @@ -59,19 +47,17 @@ export class EmployeeService { } delete(id: string): Observable { - return >( - this.http - .delete(`${url}/${id}`, httpOptions) - .pipe(catchError(this.log.handleError(serviceName, 'delete'))) - ); + return this.http + .delete(`${url}/${id}`) + .pipe(catchError(this.log.handleError(serviceName, 'delete'))) as Observable; } autocomplete(term: string): Observable { const options = { params: new HttpParams().set('q', term) }; - return >( - this.http - .get(`${url}/query`, options) - .pipe(catchError(this.log.handleError(serviceName, 'autocomplete'))) - ); + return this.http + .get(`${url}/query`, options) + .pipe(catchError(this.log.handleError(serviceName, 'autocomplete'))) as Observable< + Employee[] + >; } } diff --git a/overlord/src/app/incentive/incentive-resolver.service.spec.ts b/overlord/src/app/incentive/incentive-resolver.service.spec.ts index fdba6a4d..db539888 100644 --- a/overlord/src/app/incentive/incentive-resolver.service.spec.ts +++ b/overlord/src/app/incentive/incentive-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { IncentiveResolver } from './incentive-resolver.service'; diff --git a/overlord/src/app/incentive/incentive.component.spec.ts b/overlord/src/app/incentive/incentive.component.spec.ts index c4e23902..e72d23f8 100644 --- a/overlord/src/app/incentive/incentive.component.spec.ts +++ b/overlord/src/app/incentive/incentive.component.spec.ts @@ -1,6 +1,6 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; -import { MatDialogModule } from '@angular/material/dialog'; import { ReactiveFormsModule } from '@angular/forms'; +import { MatDialogModule } from '@angular/material/dialog'; import { RouterTestingModule } from '@angular/router/testing'; import { IncentiveComponent } from './incentive.component'; diff --git a/overlord/src/app/incentive/incentive.component.ts b/overlord/src/app/incentive/incentive.component.ts index d30194c5..5868c762 100644 --- a/overlord/src/app/incentive/incentive.component.ts +++ b/overlord/src/app/incentive/incentive.component.ts @@ -134,7 +134,7 @@ export class IncentiveComponent implements OnInit { } return ( this.voucher.user.id === (this.auth.user as User).id || - this.auth.allowed("edit-other-user's-vouchers") + this.auth.allowed('edit-other-user\'s-vouchers') ); } diff --git a/overlord/src/app/issue/issue-grid.service.spec.ts b/overlord/src/app/issue/issue-grid.service.spec.ts index 2434650c..34783a30 100644 --- a/overlord/src/app/issue/issue-grid.service.spec.ts +++ b/overlord/src/app/issue/issue-grid.service.spec.ts @@ -1,5 +1,5 @@ -import { TestBed, inject } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { TestBed, inject } from '@angular/core/testing'; import { IssueGridService } from './issue-grid.service'; diff --git a/overlord/src/app/issue/issue-grid.service.ts b/overlord/src/app/issue/issue-grid.service.ts index 70f76088..97662656 100644 --- a/overlord/src/app/issue/issue-grid.service.ts +++ b/overlord/src/app/issue/issue-grid.service.ts @@ -16,10 +16,10 @@ export class IssueGridService { constructor(private http: HttpClient, private log: ErrorLoggerService) {} issueGrid(date: string): Observable { - return >( - this.http - .get(`${url}/${date}`) - .pipe(catchError(this.log.handleError(serviceName, 'autocomplete'))) - ); + return this.http + .get(`${url}/${date}`) + .pipe(catchError(this.log.handleError(serviceName, 'autocomplete'))) as Observable< + IssueGridItem[] + >; } } diff --git a/overlord/src/app/issue/issue-resolver.service.spec.ts b/overlord/src/app/issue/issue-resolver.service.spec.ts index a231269a..54834144 100644 --- a/overlord/src/app/issue/issue-resolver.service.spec.ts +++ b/overlord/src/app/issue/issue-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { IssueResolver } from './issue-resolver.service'; diff --git a/overlord/src/app/issue/issue.component.spec.ts b/overlord/src/app/issue/issue.component.spec.ts index f92eef03..3dcedc58 100644 --- a/overlord/src/app/issue/issue.component.spec.ts +++ b/overlord/src/app/issue/issue.component.spec.ts @@ -1,6 +1,6 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; -import { MatDialogModule } from '@angular/material/dialog'; import { ReactiveFormsModule } from '@angular/forms'; +import { MatDialogModule } from '@angular/material/dialog'; import { RouterTestingModule } from '@angular/router/testing'; import { IssueComponent } from './issue.component'; diff --git a/overlord/src/app/issue/issue.component.ts b/overlord/src/app/issue/issue.component.ts index 7fcd4a77..69108d22 100644 --- a/overlord/src/app/issue/issue.component.ts +++ b/overlord/src/app/issue/issue.component.ts @@ -103,7 +103,9 @@ export class IssueComponent implements OnInit, AfterViewInit, OnDestroy { 'f2', (): boolean => { setTimeout(() => { - if (this.dateElement) this.dateElement.nativeElement.focus(); + if (this.dateElement) { + this.dateElement.nativeElement.focus(); + } }, 0); return false; // Prevent bubbling }, @@ -151,7 +153,9 @@ export class IssueComponent implements OnInit, AfterViewInit, OnDestroy { focusBatch() { setTimeout(() => { - if (this.batchElement) this.batchElement.nativeElement.focus(); + if (this.batchElement) { + this.batchElement.nativeElement.focus(); + } }, 0); } @@ -204,7 +208,9 @@ export class IssueComponent implements OnInit, AfterViewInit, OnDestroy { }); this.batch = null; setTimeout(() => { - if (this.batchElement) this.batchElement.nativeElement.focus(); + if (this.batchElement) { + this.batchElement.nativeElement.focus(); + } }, 0); } @@ -256,7 +262,7 @@ export class IssueComponent implements OnInit, AfterViewInit, OnDestroy { } return ( this.voucher.user.id === (this.auth.user as User).id || - this.auth.allowed("edit-other-user's-vouchers") + this.auth.allowed('edit-other-user\'s-vouchers') ); } diff --git a/overlord/src/app/journal/journal-resolver.service.spec.ts b/overlord/src/app/journal/journal-resolver.service.spec.ts index 0b472618..8d0e3d16 100644 --- a/overlord/src/app/journal/journal-resolver.service.spec.ts +++ b/overlord/src/app/journal/journal-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { JournalResolver } from './journal-resolver.service'; diff --git a/overlord/src/app/journal/journal.component.spec.ts b/overlord/src/app/journal/journal.component.spec.ts index 6db73e2a..74a2da5c 100644 --- a/overlord/src/app/journal/journal.component.spec.ts +++ b/overlord/src/app/journal/journal.component.spec.ts @@ -1,9 +1,9 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; -import { JournalComponent } from './journal.component'; import { ReactiveFormsModule } from '@angular/forms'; +import { MatDialogModule } from '@angular/material/dialog'; import { RouterTestingModule } from '@angular/router/testing'; -import { MatDialogModule } from '@angular/material/dialog'; +import { JournalComponent } from './journal.component'; describe('JournalComponent', () => { let component: JournalComponent; diff --git a/overlord/src/app/journal/journal.component.ts b/overlord/src/app/journal/journal.component.ts index 922d8b6a..9d71a563 100644 --- a/overlord/src/app/journal/journal.component.ts +++ b/overlord/src/app/journal/journal.component.ts @@ -93,7 +93,9 @@ export class JournalComponent implements OnInit, AfterViewInit, OnDestroy { 'f2', (): boolean => { setTimeout(() => { - if (this.dateElement) this.dateElement.nativeElement.focus(); + if (this.dateElement) { + this.dateElement.nativeElement.focus(); + } }, 0); return false; // Prevent bubbling }, @@ -151,7 +153,9 @@ export class JournalComponent implements OnInit, AfterViewInit, OnDestroy { focusAccount() { setTimeout(() => { - if (this.accountElement) this.accountElement.nativeElement.focus(); + if (this.accountElement) { + this.accountElement.nativeElement.focus(); + } }, 0); } @@ -197,7 +201,9 @@ export class JournalComponent implements OnInit, AfterViewInit, OnDestroy { this.account = null; this.accBal = null; setTimeout(() => { - if (this.accountElement) this.accountElement.nativeElement.focus(); + if (this.accountElement) { + this.accountElement.nativeElement.focus(); + } }, 0); } @@ -247,7 +253,7 @@ export class JournalComponent implements OnInit, AfterViewInit, OnDestroy { } return ( this.voucher.user.id === (this.auth.user as User).id || - this.auth.allowed("edit-other-user's-vouchers") + this.auth.allowed('edit-other-user\'s-vouchers') ); } diff --git a/overlord/src/app/ledger/ledger-datasource.ts b/overlord/src/app/ledger/ledger-datasource.ts index d0b0afba..53b68cff 100644 --- a/overlord/src/app/ledger/ledger-datasource.ts +++ b/overlord/src/app/ledger/ledger-datasource.ts @@ -8,9 +8,7 @@ import { map } from 'rxjs/operators'; import { LedgerItem } from './ledger-item'; /** Simple sort comparator for example ID/Name columns (for client-side sorting). */ -function compare(a: string | number, b: string | number, isAsc: boolean) { - return (a < b ? -1 : 1) * (isAsc ? 1 : -1); -} +const compare = (a: string | number, b: string | number, isAsc: boolean) => (a < b ? -1 : 1) * (isAsc ? 1 : -1); export class LedgerDataSource extends DataSource { constructor(public data: LedgerItem[], private paginator?: MatPaginator, private sort?: MatSort) { super(); @@ -22,11 +20,17 @@ export class LedgerDataSource extends DataSource { | EventEmitter | EventEmitter )[] = [observableOf(this.data)]; - if (this.paginator) dataMutations.push((this.paginator as MatPaginator).page); - if (this.sort) dataMutations.push((this.sort as MatSort).sortChange); + if (this.paginator) { + dataMutations.push((this.paginator as MatPaginator).page); + } + if (this.sort) { + dataMutations.push((this.sort as MatSort).sortChange); + } // Set the paginators length - if (this.paginator) this.paginator.length = this.data.length; + if (this.paginator) { + this.paginator.length = this.data.length; + } return merge(...dataMutations).pipe( map(() => this.getPagedData(this.getSortedData([...this.data]))), @@ -36,13 +40,17 @@ export class LedgerDataSource extends DataSource { disconnect() {} private getPagedData(data: LedgerItem[]) { - if (this.paginator === undefined) return data; + if (this.paginator === undefined) { + return data; + } const startIndex = this.paginator.pageIndex * this.paginator.pageSize; return data.splice(startIndex, this.paginator.pageSize); } private getSortedData(data: LedgerItem[]) { - if (this.sort === undefined) return data; + if (this.sort === undefined) { + return data; + } if (!this.sort.active || this.sort.direction === '') { return data; } diff --git a/overlord/src/app/ledger/ledger-resolver.service.spec.ts b/overlord/src/app/ledger/ledger-resolver.service.spec.ts index 295767a7..510bf250 100644 --- a/overlord/src/app/ledger/ledger-resolver.service.spec.ts +++ b/overlord/src/app/ledger/ledger-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { LedgerResolver } from './ledger-resolver.service'; diff --git a/overlord/src/app/ledger/ledger.component.spec.ts b/overlord/src/app/ledger/ledger.component.spec.ts index 34313218..bd496a05 100644 --- a/overlord/src/app/ledger/ledger.component.spec.ts +++ b/overlord/src/app/ledger/ledger.component.spec.ts @@ -1,5 +1,5 @@ -import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; import { ReactiveFormsModule } from '@angular/forms'; import { RouterTestingModule } from '@angular/router/testing'; diff --git a/overlord/src/app/ledger/ledger.component.ts b/overlord/src/app/ledger/ledger.component.ts index 66b3d996..b9437852 100644 --- a/overlord/src/app/ledger/ledger.component.ts +++ b/overlord/src/app/ledger/ledger.component.ts @@ -77,7 +77,9 @@ export class LedgerComponent implements OnInit, AfterViewInit { ngAfterViewInit() { setTimeout(() => { - if (this.accountElement) this.accountElement.nativeElement.focus(); + if (this.accountElement) { + this.accountElement.nativeElement.focus(); + } }, 0); } diff --git a/overlord/src/app/ledger/ledger.service.spec.ts b/overlord/src/app/ledger/ledger.service.spec.ts index a382895c..e6e9a754 100644 --- a/overlord/src/app/ledger/ledger.service.spec.ts +++ b/overlord/src/app/ledger/ledger.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { LedgerService } from './ledger.service'; diff --git a/overlord/src/app/ledger/ledger.service.ts b/overlord/src/app/ledger/ledger.service.ts index 9fe6639f..74d7defe 100644 --- a/overlord/src/app/ledger/ledger.service.ts +++ b/overlord/src/app/ledger/ledger.service.ts @@ -25,10 +25,8 @@ export class LedgerService { if (finishDate !== null) { options.params = options.params.set('f', finishDate); } - return >( - this.http - .get(listUrl, options) - .pipe(catchError(this.log.handleError(serviceName, 'list'))) - ); + return this.http + .get(listUrl, options) + .pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable; } } diff --git a/overlord/src/app/net-transactions/net-transactions-datasource.ts b/overlord/src/app/net-transactions/net-transactions-datasource.ts index b98e5efd..3af6abf0 100644 --- a/overlord/src/app/net-transactions/net-transactions-datasource.ts +++ b/overlord/src/app/net-transactions/net-transactions-datasource.ts @@ -8,9 +8,7 @@ import { map } from 'rxjs/operators'; import { NetTransactionsItem } from './net-transactions-item'; /** Simple sort comparator for example ID/Name columns (for client-side sorting). */ -function compare(a: string | number, b: string | number, isAsc: boolean) { - return (a < b ? -1 : 1) * (isAsc ? 1 : -1); -} +const compare = (a: string | number, b: string | number, isAsc: boolean) => (a < b ? -1 : 1) * (isAsc ? 1 : -1); export class NetTransactionsDataSource extends DataSource { constructor( public data: NetTransactionsItem[], @@ -26,11 +24,17 @@ export class NetTransactionsDataSource extends DataSource { | EventEmitter | EventEmitter )[] = [observableOf(this.data)]; - if (this.paginator) dataMutations.push((this.paginator as MatPaginator).page); - if (this.sort) dataMutations.push((this.sort as MatSort).sortChange); + if (this.paginator) { + dataMutations.push((this.paginator as MatPaginator).page); + } + if (this.sort) { + dataMutations.push((this.sort as MatSort).sortChange); + } // Set the paginators length - if (this.paginator) this.paginator.length = this.data.length; + if (this.paginator) { + this.paginator.length = this.data.length; + } return merge(...dataMutations).pipe( map(() => this.getPagedData(this.getSortedData([...this.data]))), @@ -40,13 +44,17 @@ export class NetTransactionsDataSource extends DataSource { disconnect() {} private getPagedData(data: NetTransactionsItem[]) { - if (this.paginator === undefined) return data; + if (this.paginator === undefined) { + return data; + } const startIndex = this.paginator.pageIndex * this.paginator.pageSize; return data.splice(startIndex, this.paginator.pageSize); } private getSortedData(data: NetTransactionsItem[]) { - if (this.sort === undefined) return data; + if (this.sort === undefined) { + return data; + } if (!this.sort.active || this.sort.direction === '') { return data; } diff --git a/overlord/src/app/net-transactions/net-transactions-resolver.service.spec.ts b/overlord/src/app/net-transactions/net-transactions-resolver.service.spec.ts index ccf19879..169c8d7f 100644 --- a/overlord/src/app/net-transactions/net-transactions-resolver.service.spec.ts +++ b/overlord/src/app/net-transactions/net-transactions-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { NetTransactionsResolver } from './net-transactions-resolver.service'; diff --git a/overlord/src/app/net-transactions/net-transactions.service.spec.ts b/overlord/src/app/net-transactions/net-transactions.service.spec.ts index 8edb49c8..915e74c5 100644 --- a/overlord/src/app/net-transactions/net-transactions.service.spec.ts +++ b/overlord/src/app/net-transactions/net-transactions.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { NetTransactionsService } from './net-transactions.service'; diff --git a/overlord/src/app/net-transactions/net-transactions.service.ts b/overlord/src/app/net-transactions/net-transactions.service.ts index 318d01fb..236d4f29 100644 --- a/overlord/src/app/net-transactions/net-transactions.service.ts +++ b/overlord/src/app/net-transactions/net-transactions.service.ts @@ -19,10 +19,8 @@ export class NetTransactionsService { list(startDate: string | null, finishDate: string | null): Observable { const startDateWithSlash = startDate ? `/${startDate}` : ''; const finishDateWithSlash = finishDate ? `/${finishDate}` : ''; - return >( - this.http - .get(`${url}${startDateWithSlash}${finishDateWithSlash}`) - .pipe(catchError(this.log.handleError(serviceName, 'list'))) - ); + return this.http + .get(`${url}${startDateWithSlash}${finishDateWithSlash}`) + .pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable; } } diff --git a/overlord/src/app/payment/payment-accounts-resolver.service.spec.ts b/overlord/src/app/payment/payment-accounts-resolver.service.spec.ts index dfa2b98b..4831c600 100644 --- a/overlord/src/app/payment/payment-accounts-resolver.service.spec.ts +++ b/overlord/src/app/payment/payment-accounts-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { PaymentAccountsResolver } from './payment-accounts-resolver.service'; diff --git a/overlord/src/app/payment/payment-resolver.service.spec.ts b/overlord/src/app/payment/payment-resolver.service.spec.ts index b11e2b4f..d7564c35 100644 --- a/overlord/src/app/payment/payment-resolver.service.spec.ts +++ b/overlord/src/app/payment/payment-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { PaymentResolver } from './payment-resolver.service'; diff --git a/overlord/src/app/payment/payment.component.ts b/overlord/src/app/payment/payment.component.ts index 8c2cc8dc..ab0c40f5 100644 --- a/overlord/src/app/payment/payment.component.ts +++ b/overlord/src/app/payment/payment.component.ts @@ -105,7 +105,9 @@ export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy { 'f2', (): boolean => { setTimeout(() => { - if (this.dateElement) this.dateElement.nativeElement.focus(); + if (this.dateElement) { + this.dateElement.nativeElement.focus(); + } }, 0); return false; // Prevent bubbling }, @@ -116,7 +118,9 @@ export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy { new Hotkey( 'ctrl+s', (): boolean => { - if (this.canSave()) this.save(); + if (this.canSave()) { + this.save(); + } return false; // Prevent bubbling }, ['INPUT', 'SELECT', 'TEXTAREA'], @@ -126,8 +130,9 @@ export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy { new Hotkey( 'ctrl+p', (): boolean => { - if (this.voucher.id && !this.voucher.posted && this.auth.allowed('post-vouchers')) + if (this.voucher.id && !this.voucher.posted && this.auth.allowed('post-vouchers')) { this.post(); + } return false; // Prevent bubbling }, ['INPUT', 'SELECT', 'TEXTAREA'], @@ -162,7 +167,9 @@ export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy { focusAccount() { setTimeout(() => { - if (this.accountElement) this.accountElement.nativeElement.focus(); + if (this.accountElement) { + this.accountElement.nativeElement.focus(); + } }, 0); } @@ -203,7 +210,9 @@ export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy { this.account = null; this.accBal = null; setTimeout(() => { - if (this.accountElement) this.accountElement.nativeElement.focus(); + if (this.accountElement) { + this.accountElement.nativeElement.focus(); + } }, 0); } @@ -256,7 +265,7 @@ export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy { } return ( this.voucher.user.id === (this.auth.user as User).id || - this.auth.allowed("edit-other-user's-vouchers") + this.auth.allowed('edit-other-user\'s-vouchers') ); } diff --git a/overlord/src/app/product-group/product-group-detail/product-group-detail.component.ts b/overlord/src/app/product-group/product-group-detail/product-group-detail.component.ts index 122ea59b..639f56f2 100644 --- a/overlord/src/app/product-group/product-group-detail/product-group-detail.component.ts +++ b/overlord/src/app/product-group/product-group-detail/product-group-detail.component.ts @@ -45,7 +45,9 @@ export class ProductGroupDetailComponent implements OnInit, AfterViewInit { ngAfterViewInit() { setTimeout(() => { - if (this.nameElement) this.nameElement.nativeElement.focus(); + if (this.nameElement) { + this.nameElement.nativeElement.focus(); + } }, 0); } diff --git a/overlord/src/app/product-group/product-group-list-resolver.service.spec.ts b/overlord/src/app/product-group/product-group-list-resolver.service.spec.ts index ab0082f1..b4753054 100644 --- a/overlord/src/app/product-group/product-group-list-resolver.service.spec.ts +++ b/overlord/src/app/product-group/product-group-list-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { ProductGroupListResolver } from './product-group-list-resolver.service'; diff --git a/overlord/src/app/product-group/product-group-list/product-group-list-datasource.ts b/overlord/src/app/product-group/product-group-list/product-group-list-datasource.ts index 62eac5e2..f4028177 100644 --- a/overlord/src/app/product-group/product-group-list/product-group-list-datasource.ts +++ b/overlord/src/app/product-group/product-group-list/product-group-list-datasource.ts @@ -8,9 +8,7 @@ import { map } from 'rxjs/operators'; import { ProductGroup } from '../../core/product-group'; /** Simple sort comparator for example ID/Name columns (for client-side sorting). */ -function compare(a: string | number, b: string | number, isAsc: boolean) { - return (a < b ? -1 : 1) * (isAsc ? 1 : -1); -} +const compare = (a: string | number, b: string | number, isAsc: boolean) => (a < b ? -1 : 1) * (isAsc ? 1 : -1); export class ProductGroupListDataSource extends DataSource { constructor( public data: ProductGroup[], @@ -26,11 +24,17 @@ export class ProductGroupListDataSource extends DataSource { | EventEmitter | EventEmitter )[] = [observableOf(this.data)]; - if (this.paginator) dataMutations.push((this.paginator as MatPaginator).page); - if (this.sort) dataMutations.push((this.sort as MatSort).sortChange); + if (this.paginator) { + dataMutations.push((this.paginator as MatPaginator).page); + } + if (this.sort) { + dataMutations.push((this.sort as MatSort).sortChange); + } // Set the paginators length - if (this.paginator) this.paginator.length = this.data.length; + if (this.paginator) { + this.paginator.length = this.data.length; + } return merge(...dataMutations).pipe( map(() => this.getPagedData(this.getSortedData([...this.data]))), @@ -40,13 +44,17 @@ export class ProductGroupListDataSource extends DataSource { disconnect() {} private getPagedData(data: ProductGroup[]) { - if (this.paginator === undefined) return data; + if (this.paginator === undefined) { + return data; + } const startIndex = this.paginator.pageIndex * this.paginator.pageSize; return data.splice(startIndex, this.paginator.pageSize); } private getSortedData(data: ProductGroup[]) { - if (this.sort === undefined) return data; + if (this.sort === undefined) { + return data; + } if (!this.sort.active || this.sort.direction === '') { return data; } diff --git a/overlord/src/app/product-group/product-group-resolver.service.spec.ts b/overlord/src/app/product-group/product-group-resolver.service.spec.ts index d25ee0c3..376555c1 100644 --- a/overlord/src/app/product-group/product-group-resolver.service.spec.ts +++ b/overlord/src/app/product-group/product-group-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { ProductGroupResolver } from './product-group-resolver.service'; diff --git a/overlord/src/app/product-group/product-group.service.spec.ts b/overlord/src/app/product-group/product-group.service.spec.ts index ab9ab532..474fdb14 100644 --- a/overlord/src/app/product-group/product-group.service.spec.ts +++ b/overlord/src/app/product-group/product-group.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { ProductGroupService } from './product-group.service'; diff --git a/overlord/src/app/product-group/product-group.service.ts b/overlord/src/app/product-group/product-group.service.ts index 1f01e6de..ec08113e 100644 --- a/overlord/src/app/product-group/product-group.service.ts +++ b/overlord/src/app/product-group/product-group.service.ts @@ -6,9 +6,6 @@ import { catchError } from 'rxjs/operators'; import { ErrorLoggerService } from '../core/error-logger.service'; import { ProductGroup } from '../core/product-group'; -const httpOptions = { - headers: new HttpHeaders({ 'Content-Type': 'application/json' }), -}; const url = '/api/product-groups'; const serviceName = 'ProductGroupService'; @@ -20,35 +17,29 @@ export class ProductGroupService { get(id: string | null): Observable { const getUrl: string = id === null ? `${url}` : `${url}/${id}`; - return >( - this.http - .get(getUrl) - .pipe(catchError(this.log.handleError(serviceName, `get id=${id}`))) - ); + return this.http + .get(getUrl) + .pipe( + catchError(this.log.handleError(serviceName, `get id as Observable=${id}`)), + ) as Observable; } list(): Observable { - return >( - this.http - .get(`${url}/list`) - .pipe(catchError(this.log.handleError(serviceName, 'list'))) - ); + return this.http + .get(`${url}/list`) + .pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable; } save(productGroup: ProductGroup): Observable { - return >( - this.http - .post(`${url}`, productGroup, httpOptions) - .pipe(catchError(this.log.handleError(serviceName, 'save'))) - ); + return this.http + .post(`${url}`, productGroup) + .pipe(catchError(this.log.handleError(serviceName, 'save'))) as Observable; } update(productGroup: ProductGroup): Observable { - return >( - this.http - .put(`${url}/${productGroup.id}`, productGroup, httpOptions) - .pipe(catchError(this.log.handleError(serviceName, 'update'))) - ); + return this.http + .put(`${url}/${productGroup.id}`, productGroup) + .pipe(catchError(this.log.handleError(serviceName, 'update'))) as Observable; } saveOrUpdate(productGroup: ProductGroup): Observable { @@ -59,10 +50,8 @@ export class ProductGroupService { } delete(id: string): Observable { - return >( - this.http - .delete(`${url}/${id}`, httpOptions) - .pipe(catchError(this.log.handleError(serviceName, 'delete'))) - ); + return this.http + .delete(`${url}/${id}`) + .pipe(catchError(this.log.handleError(serviceName, 'delete'))) as Observable; } } diff --git a/overlord/src/app/product-ledger/product-ledger-datasource.ts b/overlord/src/app/product-ledger/product-ledger-datasource.ts index f82ae5ec..62608c52 100644 --- a/overlord/src/app/product-ledger/product-ledger-datasource.ts +++ b/overlord/src/app/product-ledger/product-ledger-datasource.ts @@ -8,9 +8,7 @@ import { map } from 'rxjs/operators'; import { ProductLedgerItem } from './product-ledger-item'; /** Simple sort comparator for example ID/Name columns (for client-side sorting). */ -function compare(a: string | number, b: string | number, isAsc: boolean) { - return (a < b ? -1 : 1) * (isAsc ? 1 : -1); -} +const compare = (a: string | number, b: string | number, isAsc: boolean) => (a < b ? -1 : 1) * (isAsc ? 1 : -1); export class ProductLedgerDataSource extends DataSource { constructor( public data: ProductLedgerItem[], @@ -26,11 +24,17 @@ export class ProductLedgerDataSource extends DataSource { | EventEmitter | EventEmitter )[] = [observableOf(this.data)]; - if (this.paginator) dataMutations.push((this.paginator as MatPaginator).page); - if (this.sort) dataMutations.push((this.sort as MatSort).sortChange); + if (this.paginator) { + dataMutations.push((this.paginator as MatPaginator).page); + } + if (this.sort) { + dataMutations.push((this.sort as MatSort).sortChange); + } // Set the paginators length - if (this.paginator) this.paginator.length = this.data.length; + if (this.paginator) { + this.paginator.length = this.data.length; + } return merge(...dataMutations).pipe( map(() => this.getPagedData(this.getSortedData([...this.data]))), @@ -40,13 +44,17 @@ export class ProductLedgerDataSource extends DataSource { disconnect() {} private getPagedData(data: ProductLedgerItem[]) { - if (this.paginator === undefined) return data; + if (this.paginator === undefined) { + return data; + } const startIndex = this.paginator.pageIndex * this.paginator.pageSize; return data.splice(startIndex, this.paginator.pageSize); } private getSortedData(data: ProductLedgerItem[]) { - if (this.sort === undefined) return data; + if (this.sort === undefined) { + return data; + } if (!this.sort.active || this.sort.direction === '') { return data; } diff --git a/overlord/src/app/product-ledger/product-ledger-resolver.service.spec.ts b/overlord/src/app/product-ledger/product-ledger-resolver.service.spec.ts index a6d64c20..661e3d8a 100644 --- a/overlord/src/app/product-ledger/product-ledger-resolver.service.spec.ts +++ b/overlord/src/app/product-ledger/product-ledger-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { ProductLedgerResolver } from './product-ledger-resolver.service'; diff --git a/overlord/src/app/product-ledger/product-ledger.component.spec.ts b/overlord/src/app/product-ledger/product-ledger.component.spec.ts index 82d4bdef..538e3354 100644 --- a/overlord/src/app/product-ledger/product-ledger.component.spec.ts +++ b/overlord/src/app/product-ledger/product-ledger.component.spec.ts @@ -1,5 +1,5 @@ -import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; import { ReactiveFormsModule } from '@angular/forms'; import { RouterTestingModule } from '@angular/router/testing'; diff --git a/overlord/src/app/product-ledger/product-ledger.component.ts b/overlord/src/app/product-ledger/product-ledger.component.ts index f50279d5..f5fd0a38 100644 --- a/overlord/src/app/product-ledger/product-ledger.component.ts +++ b/overlord/src/app/product-ledger/product-ledger.component.ts @@ -91,7 +91,9 @@ export class ProductLedgerComponent implements OnInit, AfterViewInit { ngAfterViewInit() { setTimeout(() => { - if (this.productElement) this.productElement.nativeElement.focus(); + if (this.productElement) { + this.productElement.nativeElement.focus(); + } }, 0); } diff --git a/overlord/src/app/product-ledger/product-ledger.service.spec.ts b/overlord/src/app/product-ledger/product-ledger.service.spec.ts index 80275281..eb4864c5 100644 --- a/overlord/src/app/product-ledger/product-ledger.service.spec.ts +++ b/overlord/src/app/product-ledger/product-ledger.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { ProductLedgerService } from './product-ledger.service'; diff --git a/overlord/src/app/product-ledger/product-ledger.service.ts b/overlord/src/app/product-ledger/product-ledger.service.ts index aad0ce60..d8639391 100644 --- a/overlord/src/app/product-ledger/product-ledger.service.ts +++ b/overlord/src/app/product-ledger/product-ledger.service.ts @@ -29,10 +29,8 @@ export class ProductLedgerService { if (finishDate !== null) { options.params = options.params.set('f', finishDate); } - return >( - this.http - .get(listUrl, options) - .pipe(catchError(this.log.handleError(serviceName, 'list'))) - ); + return this.http + .get(listUrl, options) + .pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable; } } diff --git a/overlord/src/app/product/product-detail/product-detail.component.spec.ts b/overlord/src/app/product/product-detail/product-detail.component.spec.ts index 11a911f7..551a3a79 100644 --- a/overlord/src/app/product/product-detail/product-detail.component.spec.ts +++ b/overlord/src/app/product/product-detail/product-detail.component.spec.ts @@ -1,6 +1,6 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; -import { MatDialogModule } from '@angular/material/dialog'; import { ReactiveFormsModule } from '@angular/forms'; +import { MatDialogModule } from '@angular/material/dialog'; import { RouterTestingModule } from '@angular/router/testing'; import { ProductDetailComponent } from './product-detail.component'; diff --git a/overlord/src/app/product/product-detail/product-detail.component.ts b/overlord/src/app/product/product-detail/product-detail.component.ts index f7411992..a0697256 100644 --- a/overlord/src/app/product/product-detail/product-detail.component.ts +++ b/overlord/src/app/product/product-detail/product-detail.component.ts @@ -73,7 +73,9 @@ export class ProductDetailComponent implements OnInit, AfterViewInit { ngAfterViewInit() { setTimeout(() => { - if (this.nameElement) this.nameElement.nativeElement.focus(); + if (this.nameElement) { + this.nameElement.nativeElement.focus(); + } }, 0); } diff --git a/overlord/src/app/product/product-list-resolver.service.spec.ts b/overlord/src/app/product/product-list-resolver.service.spec.ts index 49c4d5b3..e285b2b0 100644 --- a/overlord/src/app/product/product-list-resolver.service.spec.ts +++ b/overlord/src/app/product/product-list-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { ProductListResolver } from './product-list-resolver.service'; diff --git a/overlord/src/app/product/product-list/product-list-datasource.ts b/overlord/src/app/product/product-list/product-list-datasource.ts index 5242e6ea..4507a4ff 100644 --- a/overlord/src/app/product/product-list/product-list-datasource.ts +++ b/overlord/src/app/product/product-list/product-list-datasource.ts @@ -9,9 +9,7 @@ import { Product } from '../../core/product'; import { ProductGroup } from '../../core/product-group'; /** Simple sort comparator for example ID/Name columns (for client-side sorting). */ -function compare(a: string | number, b: string | number, isAsc: boolean) { - return (a < b ? -1 : 1) * (isAsc ? 1 : -1); -} +const compare = (a: string | number, b: string | number, isAsc: boolean) => (a < b ? -1 : 1) * (isAsc ? 1 : -1); export class ProductListDataSource extends DataSource { private filterValue = ''; @@ -36,14 +34,20 @@ export class ProductListDataSource extends DataSource { | EventEmitter | EventEmitter )[] = [observableOf(this.data), this.filter]; - if (this.paginator) dataMutations.push((this.paginator as MatPaginator).page); - if (this.sort) dataMutations.push((this.sort as MatSort).sortChange); + if (this.paginator) { + dataMutations.push((this.paginator as MatPaginator).page); + } + if (this.sort) { + dataMutations.push((this.sort as MatSort).sortChange); + } return merge(...dataMutations) .pipe( map(() => this.getFilteredData([...this.data])), tap((x: Product[]) => { - if (this.paginator) this.paginator.length = x.length; + if (this.paginator) { + this.paginator.length = x.length; + } }), ) .pipe(map((x: Product[]) => this.getPagedData(this.getSortedData(x)))); @@ -65,13 +69,17 @@ export class ProductListDataSource extends DataSource { } private getPagedData(data: Product[]) { - if (this.paginator === undefined) return data; + if (this.paginator === undefined) { + return data; + } const startIndex = this.paginator.pageIndex * this.paginator.pageSize; return data.splice(startIndex, this.paginator.pageSize); } private getSortedData(data: Product[]) { - if (this.sort === undefined) return data; + if (this.sort === undefined) { + return data; + } if (!this.sort.active || this.sort.direction === '') { return data; } diff --git a/overlord/src/app/product/product-list/product-list.component.ts b/overlord/src/app/product/product-list/product-list.component.ts index 4187f362..ada78601 100644 --- a/overlord/src/app/product/product-list/product-list.component.ts +++ b/overlord/src/app/product/product-list/product-list.component.ts @@ -69,11 +69,14 @@ export class ProductListComponent implements OnInit, AfterViewInit { ngAfterViewInit() { setTimeout(() => { - if (this.filterElement) this.filterElement.nativeElement.focus(); + if (this.filterElement) { + this.filterElement.nativeElement.focus(); + } }, 0); } exportCsv() { + // eslint-disable-next-line @typescript-eslint/naming-convention const headers = { Code: 'code', Name: 'name', diff --git a/overlord/src/app/product/product-resolver.service.spec.ts b/overlord/src/app/product/product-resolver.service.spec.ts index 8ddf2d8e..fb76cb88 100644 --- a/overlord/src/app/product/product-resolver.service.spec.ts +++ b/overlord/src/app/product/product-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { ProductResolver } from './product-resolver.service'; diff --git a/overlord/src/app/product/product.service.spec.ts b/overlord/src/app/product/product.service.spec.ts index c230974e..85555f5e 100644 --- a/overlord/src/app/product/product.service.spec.ts +++ b/overlord/src/app/product/product.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { ProductService } from './product.service'; diff --git a/overlord/src/app/product/product.service.ts b/overlord/src/app/product/product.service.ts index 59b752be..c582a015 100644 --- a/overlord/src/app/product/product.service.ts +++ b/overlord/src/app/product/product.service.ts @@ -6,10 +6,6 @@ import { catchError } from 'rxjs/operators'; import { ErrorLoggerService } from '../core/error-logger.service'; import { Product } from '../core/product'; -const httpOptions = { - headers: new HttpHeaders({ 'Content-Type': 'application/json' }), -}; - const url = '/api/products'; const serviceName = 'ProductService'; @@ -19,35 +15,27 @@ export class ProductService { get(id: string | null): Observable { const getUrl: string = id === null ? `${url}` : `${url}/${id}`; - return >( - this.http - .get(getUrl) - .pipe(catchError(this.log.handleError(serviceName, `get id=${id}`))) - ); + return this.http + .get(getUrl) + .pipe(catchError(this.log.handleError(serviceName, `get id as Observable=${id}`))) as Observable; } list(): Observable { - return >( - this.http - .get(`${url}/list`) - .pipe(catchError(this.log.handleError(serviceName, 'getList'))) - ); + return this.http + .get(`${url}/list`) + .pipe(catchError(this.log.handleError(serviceName, 'getList'))) as Observable; } save(product: Product): Observable { - return >( - this.http - .post(`${url}`, product, httpOptions) - .pipe(catchError(this.log.handleError(serviceName, 'save'))) - ); + return this.http + .post(`${url}`, product) + .pipe(catchError(this.log.handleError(serviceName, 'save'))) as Observable; } update(product: Product): Observable { - return >( - this.http - .put(`${url}/${product.id}`, product, httpOptions) - .pipe(catchError(this.log.handleError(serviceName, 'update'))) - ); + return this.http + .put(`${url}/${product.id}`, product) + .pipe(catchError(this.log.handleError(serviceName, 'update'))) as Observable; } saveOrUpdate(product: Product): Observable { @@ -58,19 +46,15 @@ export class ProductService { } delete(id: string): Observable { - return >( - this.http - .delete(`${url}/${id}`, httpOptions) - .pipe(catchError(this.log.handleError(serviceName, 'delete'))) - ); + return this.http + .delete(`${url}/${id}`) + .pipe(catchError(this.log.handleError(serviceName, 'delete'))) as Observable; } autocomplete(query: string): Observable { const options = { params: new HttpParams().set('q', query) }; - return >( - this.http - .get(`${url}/query`, options) - .pipe(catchError(this.log.handleError(serviceName, 'autocomplete'))) - ); + return this.http + .get(`${url}/query`, options) + .pipe(catchError(this.log.handleError(serviceName, 'autocomplete'))) as Observable; } } diff --git a/overlord/src/app/profit-loss/profit-loss-datasource.ts b/overlord/src/app/profit-loss/profit-loss-datasource.ts index 61fe6c53..a18552ef 100644 --- a/overlord/src/app/profit-loss/profit-loss-datasource.ts +++ b/overlord/src/app/profit-loss/profit-loss-datasource.ts @@ -8,9 +8,7 @@ import { map } from 'rxjs/operators'; import { ProfitLossItem } from './profit-loss-item'; /** Simple sort comparator for example ID/Name columns (for client-side sorting). */ -function compare(a: string | number, b: string | number, isAsc: boolean) { - return (a < b ? -1 : 1) * (isAsc ? 1 : -1); -} +const compare = (a: string | number, b: string | number, isAsc: boolean) => (a < b ? -1 : 1) * (isAsc ? 1 : -1); export class ProfitLossDataSource extends DataSource { constructor( public data: ProfitLossItem[], @@ -26,11 +24,17 @@ export class ProfitLossDataSource extends DataSource { | EventEmitter | EventEmitter )[] = [observableOf(this.data)]; - if (this.paginator) dataMutations.push((this.paginator as MatPaginator).page); - if (this.sort) dataMutations.push((this.sort as MatSort).sortChange); + if (this.paginator) { + dataMutations.push((this.paginator as MatPaginator).page); + } + if (this.sort) { + dataMutations.push((this.sort as MatSort).sortChange); + } // Set the paginators length - if (this.paginator) this.paginator.length = this.data.length; + if (this.paginator) { + this.paginator.length = this.data.length; + } return merge(...dataMutations).pipe( map(() => this.getPagedData(this.getSortedData([...this.data]))), @@ -40,13 +44,17 @@ export class ProfitLossDataSource extends DataSource { disconnect() {} private getPagedData(data: ProfitLossItem[]) { - if (this.paginator === undefined) return data; + if (this.paginator === undefined) { + return data; + } const startIndex = this.paginator.pageIndex * this.paginator.pageSize; return data.splice(startIndex, this.paginator.pageSize); } private getSortedData(data: ProfitLossItem[]) { - if (this.sort === undefined) return data; + if (this.sort === undefined) { + return data; + } if (!this.sort.active || this.sort.direction === '') { return data; } diff --git a/overlord/src/app/profit-loss/profit-loss-resolver.service.spec.ts b/overlord/src/app/profit-loss/profit-loss-resolver.service.spec.ts index 535d1e2e..664edcd5 100644 --- a/overlord/src/app/profit-loss/profit-loss-resolver.service.spec.ts +++ b/overlord/src/app/profit-loss/profit-loss-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { ProfitLossResolver } from './profit-loss-resolver.service'; diff --git a/overlord/src/app/profit-loss/profit-loss.service.spec.ts b/overlord/src/app/profit-loss/profit-loss.service.spec.ts index c81ef71f..8fd3bac2 100644 --- a/overlord/src/app/profit-loss/profit-loss.service.spec.ts +++ b/overlord/src/app/profit-loss/profit-loss.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { ProfitLossService } from './profit-loss.service'; diff --git a/overlord/src/app/profit-loss/profit-loss.service.ts b/overlord/src/app/profit-loss/profit-loss.service.ts index 9d69c248..74e1e49e 100644 --- a/overlord/src/app/profit-loss/profit-loss.service.ts +++ b/overlord/src/app/profit-loss/profit-loss.service.ts @@ -19,10 +19,8 @@ export class ProfitLossService { list(startDate: string | null, finishDate: string | null): Observable { const startDateWithSlash = startDate ? `/${startDate}` : ''; const finishDateWithSlash = finishDate ? `/${finishDate}` : ''; - return >( - this.http - .get(`${url}${startDateWithSlash}${finishDateWithSlash}`) - .pipe(catchError(this.log.handleError(serviceName, 'list'))) - ); + return this.http + .get(`${url}${startDateWithSlash}${finishDateWithSlash}`) + .pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable; } } diff --git a/overlord/src/app/purchase-entries/purchase-entries-datasource.ts b/overlord/src/app/purchase-entries/purchase-entries-datasource.ts index 10e9efda..7c461da8 100644 --- a/overlord/src/app/purchase-entries/purchase-entries-datasource.ts +++ b/overlord/src/app/purchase-entries/purchase-entries-datasource.ts @@ -8,9 +8,7 @@ import { map } from 'rxjs/operators'; import { PurchaseEntriesItem } from './purchase-entries-item'; /** Simple sort comparator for example ID/Name columns (for client-side sorting). */ -function compare(a: string | number, b: string | number, isAsc: boolean) { - return (a < b ? -1 : 1) * (isAsc ? 1 : -1); -} +const compare = (a: string | number, b: string | number, isAsc: boolean) => (a < b ? -1 : 1) * (isAsc ? 1 : -1); export class PurchaseEntriesDataSource extends DataSource { constructor( public data: PurchaseEntriesItem[], @@ -26,11 +24,17 @@ export class PurchaseEntriesDataSource extends DataSource { | EventEmitter | EventEmitter )[] = [observableOf(this.data)]; - if (this.paginator) dataMutations.push((this.paginator as MatPaginator).page); - if (this.sort) dataMutations.push((this.sort as MatSort).sortChange); + if (this.paginator) { + dataMutations.push((this.paginator as MatPaginator).page); + } + if (this.sort) { + dataMutations.push((this.sort as MatSort).sortChange); + } // Set the paginators length - if (this.paginator) this.paginator.length = this.data.length; + if (this.paginator) { + this.paginator.length = this.data.length; + } return merge(...dataMutations).pipe( map(() => this.getPagedData(this.getSortedData([...this.data]))), @@ -40,13 +44,17 @@ export class PurchaseEntriesDataSource extends DataSource { disconnect() {} private getPagedData(data: PurchaseEntriesItem[]) { - if (this.paginator === undefined) return data; + if (this.paginator === undefined) { + return data; + } const startIndex = this.paginator.pageIndex * this.paginator.pageSize; return data.splice(startIndex, this.paginator.pageSize); } private getSortedData(data: PurchaseEntriesItem[]) { - if (this.sort === undefined) return data; + if (this.sort === undefined) { + return data; + } if (!this.sort.active || this.sort.direction === '') { return data; } diff --git a/overlord/src/app/purchase-entries/purchase-entries-resolver.service.spec.ts b/overlord/src/app/purchase-entries/purchase-entries-resolver.service.spec.ts index e51b2170..a0704f39 100644 --- a/overlord/src/app/purchase-entries/purchase-entries-resolver.service.spec.ts +++ b/overlord/src/app/purchase-entries/purchase-entries-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { PurchaseEntriesResolver } from './purchase-entries-resolver.service'; diff --git a/overlord/src/app/purchase-entries/purchase-entries.service.spec.ts b/overlord/src/app/purchase-entries/purchase-entries.service.spec.ts index a52c93e8..5cbe8741 100644 --- a/overlord/src/app/purchase-entries/purchase-entries.service.spec.ts +++ b/overlord/src/app/purchase-entries/purchase-entries.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { PurchaseEntriesService } from './purchase-entries.service'; diff --git a/overlord/src/app/purchase-entries/purchase-entries.service.ts b/overlord/src/app/purchase-entries/purchase-entries.service.ts index a9e6a113..fa1fc8c9 100644 --- a/overlord/src/app/purchase-entries/purchase-entries.service.ts +++ b/overlord/src/app/purchase-entries/purchase-entries.service.ts @@ -19,10 +19,8 @@ export class PurchaseEntriesService { list(startDate: string | null, finishDate: string | null): Observable { const startDateWithSlash = startDate ? `/${startDate}` : ''; const finishDateWithSlash = finishDate ? `/${finishDate}` : ''; - return >( - this.http - .get(`${url}${startDateWithSlash}${finishDateWithSlash}`) - .pipe(catchError(this.log.handleError(serviceName, 'list'))) - ); + return this.http + .get(`${url}${startDateWithSlash}${finishDateWithSlash}`) + .pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable; } } diff --git a/overlord/src/app/purchase-return/purchase-return-resolver.service.spec.ts b/overlord/src/app/purchase-return/purchase-return-resolver.service.spec.ts index b7aae525..1af2d40e 100644 --- a/overlord/src/app/purchase-return/purchase-return-resolver.service.spec.ts +++ b/overlord/src/app/purchase-return/purchase-return-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { PurchaseReturnResolver } from './purchase-return-resolver.service'; diff --git a/overlord/src/app/purchase-return/purchase-return.component.spec.ts b/overlord/src/app/purchase-return/purchase-return.component.spec.ts index bcc4f040..4c3fe869 100644 --- a/overlord/src/app/purchase-return/purchase-return.component.spec.ts +++ b/overlord/src/app/purchase-return/purchase-return.component.spec.ts @@ -1,6 +1,6 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; -import { MatDialogModule } from '@angular/material/dialog'; import { ReactiveFormsModule } from '@angular/forms'; +import { MatDialogModule } from '@angular/material/dialog'; import { RouterTestingModule } from '@angular/router/testing'; import { PurchaseReturnComponent } from './purchase-return.component'; diff --git a/overlord/src/app/purchase-return/purchase-return.component.ts b/overlord/src/app/purchase-return/purchase-return.component.ts index 1d0853ea..9a0d28ec 100644 --- a/overlord/src/app/purchase-return/purchase-return.component.ts +++ b/overlord/src/app/purchase-return/purchase-return.component.ts @@ -106,7 +106,9 @@ export class PurchaseReturnComponent implements OnInit, AfterViewInit, OnDestroy 'f2', (): boolean => { setTimeout(() => { - if (this.dateElement) this.dateElement.nativeElement.focus(); + if (this.dateElement) { + this.dateElement.nativeElement.focus(); + } }, 0); return false; // Prevent bubbling }, @@ -165,7 +167,9 @@ export class PurchaseReturnComponent implements OnInit, AfterViewInit, OnDestroy focusAccount() { setTimeout(() => { - if (this.accountElement) this.accountElement.nativeElement.focus(); + if (this.accountElement) { + this.accountElement.nativeElement.focus(); + } }, 0); } @@ -204,7 +208,9 @@ export class PurchaseReturnComponent implements OnInit, AfterViewInit, OnDestroy }); this.batch = null; setTimeout(() => { - if (this.batchElement) this.batchElement.nativeElement.focus(); + if (this.batchElement) { + this.batchElement.nativeElement.focus(); + } }, 0); } @@ -254,7 +260,7 @@ export class PurchaseReturnComponent implements OnInit, AfterViewInit, OnDestroy } return ( this.voucher.user.id === (this.auth.user as User).id || - this.auth.allowed("edit-other-user's-vouchers") + this.auth.allowed('edit-other-user\'s-vouchers') ); } diff --git a/overlord/src/app/purchase/purchase-resolver.service.spec.ts b/overlord/src/app/purchase/purchase-resolver.service.spec.ts index 122e7673..e048a883 100644 --- a/overlord/src/app/purchase/purchase-resolver.service.spec.ts +++ b/overlord/src/app/purchase/purchase-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { PurchaseResolver } from './purchase-resolver.service'; diff --git a/overlord/src/app/purchase/purchase.component.spec.ts b/overlord/src/app/purchase/purchase.component.spec.ts index 1035459a..722ddf1a 100644 --- a/overlord/src/app/purchase/purchase.component.spec.ts +++ b/overlord/src/app/purchase/purchase.component.spec.ts @@ -1,6 +1,6 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; -import { MatDialogModule } from '@angular/material/dialog'; import { ReactiveFormsModule } from '@angular/forms'; +import { MatDialogModule } from '@angular/material/dialog'; import { RouterTestingModule } from '@angular/router/testing'; import { PurchaseComponent } from './purchase.component'; diff --git a/overlord/src/app/purchase/purchase.component.ts b/overlord/src/app/purchase/purchase.component.ts index 16197217..19d9cf16 100644 --- a/overlord/src/app/purchase/purchase.component.ts +++ b/overlord/src/app/purchase/purchase.component.ts @@ -109,7 +109,9 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy { 'f2', (): boolean => { setTimeout(() => { - if (this.dateElement) this.dateElement.nativeElement.focus(); + if (this.dateElement) { + this.dateElement.nativeElement.focus(); + } }, 0); return false; // Prevent bubbling }, @@ -171,7 +173,9 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy { focusAccount() { setTimeout(() => { - if (this.accountElement) this.accountElement.nativeElement.focus(); + if (this.accountElement) { + this.accountElement.nativeElement.focus(); + } }, 0); } @@ -216,7 +220,9 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy { }); this.product = null; setTimeout(() => { - if (this.productElement) this.productElement.nativeElement.focus(); + if (this.productElement) { + this.productElement.nativeElement.focus(); + } }, 0); } @@ -263,7 +269,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy { } return ( this.voucher.user.id === (this.auth.user as User).id || - this.auth.allowed("edit-other-user's-vouchers") + this.auth.allowed('edit-other-user\'s-vouchers') ); } diff --git a/overlord/src/app/purchases/purchases-datasource.ts b/overlord/src/app/purchases/purchases-datasource.ts index 92ebc288..07338fe8 100644 --- a/overlord/src/app/purchases/purchases-datasource.ts +++ b/overlord/src/app/purchases/purchases-datasource.ts @@ -8,9 +8,7 @@ import { map } from 'rxjs/operators'; import { PurchasesItem } from './purchases-item'; /** Simple sort comparator for example ID/Name columns (for client-side sorting). */ -function compare(a: string | number, b: string | number, isAsc: boolean) { - return (a < b ? -1 : 1) * (isAsc ? 1 : -1); -} +const compare = (a: string | number, b: string | number, isAsc: boolean) => (a < b ? -1 : 1) * (isAsc ? 1 : -1); export class PurchasesDataSource extends DataSource { constructor( public data: PurchasesItem[], @@ -26,11 +24,17 @@ export class PurchasesDataSource extends DataSource { | EventEmitter | EventEmitter )[] = [observableOf(this.data)]; - if (this.paginator) dataMutations.push((this.paginator as MatPaginator).page); - if (this.sort) dataMutations.push((this.sort as MatSort).sortChange); + if (this.paginator) { + dataMutations.push((this.paginator as MatPaginator).page); + } + if (this.sort) { + dataMutations.push((this.sort as MatSort).sortChange); + } // Set the paginators length - if (this.paginator) this.paginator.length = this.data.length; + if (this.paginator) { + this.paginator.length = this.data.length; + } return merge(...dataMutations).pipe( map(() => this.getPagedData(this.getSortedData([...this.data]))), @@ -40,13 +44,17 @@ export class PurchasesDataSource extends DataSource { disconnect() {} private getPagedData(data: PurchasesItem[]) { - if (this.paginator === undefined) return data; + if (this.paginator === undefined) { + return data; + } const startIndex = this.paginator.pageIndex * this.paginator.pageSize; return data.splice(startIndex, this.paginator.pageSize); } private getSortedData(data: PurchasesItem[]) { - if (this.sort === undefined) return data; + if (this.sort === undefined) { + return data; + } if (!this.sort.active || this.sort.direction === '') { return data; } diff --git a/overlord/src/app/purchases/purchases-resolver.service.spec.ts b/overlord/src/app/purchases/purchases-resolver.service.spec.ts index 77eec551..f12140c0 100644 --- a/overlord/src/app/purchases/purchases-resolver.service.spec.ts +++ b/overlord/src/app/purchases/purchases-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { PurchasesResolver } from './purchases-resolver.service'; diff --git a/overlord/src/app/purchases/purchases.component.spec.ts b/overlord/src/app/purchases/purchases.component.spec.ts index e592e594..5c824d0b 100644 --- a/overlord/src/app/purchases/purchases.component.spec.ts +++ b/overlord/src/app/purchases/purchases.component.spec.ts @@ -1,6 +1,6 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; -import { MatDialogModule } from '@angular/material/dialog'; import { ReactiveFormsModule } from '@angular/forms'; +import { MatDialogModule } from '@angular/material/dialog'; import { RouterTestingModule } from '@angular/router/testing'; import { PurchasesComponent } from './purchases.component'; diff --git a/overlord/src/app/purchases/purchases.service.spec.ts b/overlord/src/app/purchases/purchases.service.spec.ts index 1335f54a..3e5fc216 100644 --- a/overlord/src/app/purchases/purchases.service.spec.ts +++ b/overlord/src/app/purchases/purchases.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { PurchasesService } from './purchases.service'; diff --git a/overlord/src/app/purchases/purchases.service.ts b/overlord/src/app/purchases/purchases.service.ts index 33c55b60..6ad1dff8 100644 --- a/overlord/src/app/purchases/purchases.service.ts +++ b/overlord/src/app/purchases/purchases.service.ts @@ -19,10 +19,8 @@ export class PurchasesService { list(startDate: string | null, finishDate: string | null): Observable { const startDateWithSlash = startDate ? `/${startDate}` : ''; const finishDateWithSlash = finishDate ? `/${finishDate}` : ''; - return >( - this.http - .get(`${url}${startDateWithSlash}${finishDateWithSlash}`) - .pipe(catchError(this.log.handleError(serviceName, 'list'))) - ); + return this.http + .get(`${url}${startDateWithSlash}${finishDateWithSlash}`) + .pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable; } } diff --git a/overlord/src/app/raw-material-cost/raw-material-cost-datasource.ts b/overlord/src/app/raw-material-cost/raw-material-cost-datasource.ts index 8d394249..d2e3737a 100644 --- a/overlord/src/app/raw-material-cost/raw-material-cost-datasource.ts +++ b/overlord/src/app/raw-material-cost/raw-material-cost-datasource.ts @@ -8,9 +8,7 @@ import { map } from 'rxjs/operators'; import { RawMaterialCostItem } from './raw-material-cost-item'; /** Simple sort comparator for example ID/Name columns (for client-side sorting). */ -function compare(a: string | number, b: string | number, isAsc: boolean) { - return (a < b ? -1 : 1) * (isAsc ? 1 : -1); -} +const compare = (a: string | number, b: string | number, isAsc: boolean) => (a < b ? -1 : 1) * (isAsc ? 1 : -1); export class RawMaterialCostDataSource extends DataSource { constructor( public data: RawMaterialCostItem[], @@ -26,11 +24,17 @@ export class RawMaterialCostDataSource extends DataSource { | EventEmitter | EventEmitter )[] = [observableOf(this.data)]; - if (this.paginator) dataMutations.push((this.paginator as MatPaginator).page); - if (this.sort) dataMutations.push((this.sort as MatSort).sortChange); + if (this.paginator) { + dataMutations.push((this.paginator as MatPaginator).page); + } + if (this.sort) { + dataMutations.push((this.sort as MatSort).sortChange); + } // Set the paginators length - if (this.paginator) this.paginator.length = this.data.length; + if (this.paginator) { + this.paginator.length = this.data.length; + } return merge(...dataMutations).pipe( map(() => this.getPagedData(this.getSortedData([...this.data]))), @@ -40,13 +44,17 @@ export class RawMaterialCostDataSource extends DataSource { disconnect() {} private getPagedData(data: RawMaterialCostItem[]) { - if (this.paginator === undefined) return data; + if (this.paginator === undefined) { + return data; + } const startIndex = this.paginator.pageIndex * this.paginator.pageSize; return data.splice(startIndex, this.paginator.pageSize); } private getSortedData(data: RawMaterialCostItem[]) { - if (this.sort === undefined) return data; + if (this.sort === undefined) { + return data; + } if (!this.sort.active || this.sort.direction === '') { return data; } diff --git a/overlord/src/app/raw-material-cost/raw-material-cost-resolver.service.spec.ts b/overlord/src/app/raw-material-cost/raw-material-cost-resolver.service.spec.ts index a170b04e..d7b6c949 100644 --- a/overlord/src/app/raw-material-cost/raw-material-cost-resolver.service.spec.ts +++ b/overlord/src/app/raw-material-cost/raw-material-cost-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { RawMaterialCostResolver } from './raw-material-cost-resolver.service'; diff --git a/overlord/src/app/raw-material-cost/raw-material-cost.component.ts b/overlord/src/app/raw-material-cost/raw-material-cost.component.ts index b6a9bd91..5b59e8aa 100644 --- a/overlord/src/app/raw-material-cost/raw-material-cost.component.ts +++ b/overlord/src/app/raw-material-cost/raw-material-cost.component.ts @@ -78,7 +78,7 @@ export class RawMaterialCostComponent implements OnInit { } exportCsv() { - let headers: {}; + let headers: { [display: string]: string }; if (this.info.id) { headers = { Name: 'name', Group: 'group', Quantity: 'quantity', Net: 'net', Gross: 'gross' }; } else { diff --git a/overlord/src/app/raw-material-cost/raw-material-cost.service.spec.ts b/overlord/src/app/raw-material-cost/raw-material-cost.service.spec.ts index 4e1742f4..905d9a12 100644 --- a/overlord/src/app/raw-material-cost/raw-material-cost.service.spec.ts +++ b/overlord/src/app/raw-material-cost/raw-material-cost.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { RawMaterialCostService } from './raw-material-cost.service'; diff --git a/overlord/src/app/raw-material-cost/raw-material-cost.service.ts b/overlord/src/app/raw-material-cost/raw-material-cost.service.ts index bf9fccd3..e6e43e42 100644 --- a/overlord/src/app/raw-material-cost/raw-material-cost.service.ts +++ b/overlord/src/app/raw-material-cost/raw-material-cost.service.ts @@ -36,10 +36,8 @@ export class RawMaterialCostService { } else { listUrl = url; } - return >( - this.http - .get(listUrl, options) - .pipe(catchError(this.log.handleError(serviceName, 'list'))) - ); + return this.http + .get(listUrl, options) + .pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable; } } diff --git a/overlord/src/app/receipt/receipt-accounts-resolver.service.spec.ts b/overlord/src/app/receipt/receipt-accounts-resolver.service.spec.ts index 95094e54..e353aad2 100644 --- a/overlord/src/app/receipt/receipt-accounts-resolver.service.spec.ts +++ b/overlord/src/app/receipt/receipt-accounts-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { ReceiptAccountsResolver } from './receipt-accounts-resolver.service'; diff --git a/overlord/src/app/receipt/receipt-resolver.service.spec.ts b/overlord/src/app/receipt/receipt-resolver.service.spec.ts index de75c06e..fa3bfd92 100644 --- a/overlord/src/app/receipt/receipt-resolver.service.spec.ts +++ b/overlord/src/app/receipt/receipt-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { ReceiptResolver } from './receipt-resolver.service'; diff --git a/overlord/src/app/receipt/receipt.component.spec.ts b/overlord/src/app/receipt/receipt.component.spec.ts index 8a69235f..a1dd4a0b 100644 --- a/overlord/src/app/receipt/receipt.component.spec.ts +++ b/overlord/src/app/receipt/receipt.component.spec.ts @@ -1,6 +1,6 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; -import { MatDialogModule } from '@angular/material/dialog'; import { ReactiveFormsModule } from '@angular/forms'; +import { MatDialogModule } from '@angular/material/dialog'; import { RouterTestingModule } from '@angular/router/testing'; import { ReceiptComponent } from './receipt.component'; diff --git a/overlord/src/app/receipt/receipt.component.ts b/overlord/src/app/receipt/receipt.component.ts index e53bd548..cb7bbc90 100644 --- a/overlord/src/app/receipt/receipt.component.ts +++ b/overlord/src/app/receipt/receipt.component.ts @@ -104,7 +104,9 @@ export class ReceiptComponent implements OnInit, AfterViewInit, OnDestroy { 'f2', (): boolean => { setTimeout(() => { - if (this.dateElement) this.dateElement.nativeElement.focus(); + if (this.dateElement) { + this.dateElement.nativeElement.focus(); + } }, 0); return false; // Prevent bubbling }, @@ -164,7 +166,9 @@ export class ReceiptComponent implements OnInit, AfterViewInit, OnDestroy { focusAccount() { setTimeout(() => { - if (this.accountElement) this.accountElement.nativeElement.focus(); + if (this.accountElement) { + this.accountElement.nativeElement.focus(); + } }, 0); } @@ -205,7 +209,9 @@ export class ReceiptComponent implements OnInit, AfterViewInit, OnDestroy { this.account = null; this.accBal = null; setTimeout(() => { - if (this.accountElement) this.accountElement.nativeElement.focus(); + if (this.accountElement) { + this.accountElement.nativeElement.focus(); + } }, 0); } @@ -258,7 +264,7 @@ export class ReceiptComponent implements OnInit, AfterViewInit, OnDestroy { } return ( this.voucher.user.id === (this.auth.user as User).id || - this.auth.allowed("edit-other-user's-vouchers") + this.auth.allowed('edit-other-user\'s-vouchers') ); } diff --git a/overlord/src/app/role/role-detail/role-detail.component.ts b/overlord/src/app/role/role-detail/role-detail.component.ts index f848cd3b..a4bdd94d 100644 --- a/overlord/src/app/role/role-detail/role-detail.component.ts +++ b/overlord/src/app/role/role-detail/role-detail.component.ts @@ -53,7 +53,9 @@ export class RoleDetailComponent implements OnInit, AfterViewInit { ngAfterViewInit() { setTimeout(() => { - if (this.nameElement) this.nameElement.nativeElement.focus(); + if (this.nameElement) { + this.nameElement.nativeElement.focus(); + } }, 0); } diff --git a/overlord/src/app/role/role-list-resolver.service.spec.ts b/overlord/src/app/role/role-list-resolver.service.spec.ts index d720ba96..df006769 100644 --- a/overlord/src/app/role/role-list-resolver.service.spec.ts +++ b/overlord/src/app/role/role-list-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { RoleListResolver } from './role-list-resolver.service'; diff --git a/overlord/src/app/role/role-list/role-list-datasource.ts b/overlord/src/app/role/role-list/role-list-datasource.ts index 491b8f29..4c631b70 100644 --- a/overlord/src/app/role/role-list/role-list-datasource.ts +++ b/overlord/src/app/role/role-list/role-list-datasource.ts @@ -8,9 +8,7 @@ import { map } from 'rxjs/operators'; import { Role } from '../role'; /** Simple sort comparator for example ID/Name columns (for client-side sorting). */ -function compare(a: string | number, b: string | number, isAsc: boolean) { - return (a < b ? -1 : 1) * (isAsc ? 1 : -1); -} +const compare = (a: string | number, b: string | number, isAsc: boolean) => (a < b ? -1 : 1) * (isAsc ? 1 : -1); export class RoleListDatasource extends DataSource { constructor(public data: Role[], private paginator?: MatPaginator, private sort?: MatSort) { super(); @@ -20,11 +18,17 @@ export class RoleListDatasource extends DataSource { const dataMutations: (Observable | EventEmitter | EventEmitter)[] = [ observableOf(this.data), ]; - if (this.paginator) dataMutations.push((this.paginator as MatPaginator).page); - if (this.sort) dataMutations.push((this.sort as MatSort).sortChange); + if (this.paginator) { + dataMutations.push((this.paginator as MatPaginator).page); + } + if (this.sort) { + dataMutations.push((this.sort as MatSort).sortChange); + } // Set the paginators length - if (this.paginator) this.paginator.length = this.data.length; + if (this.paginator) { + this.paginator.length = this.data.length; + } return merge(...dataMutations).pipe( map(() => this.getPagedData(this.getSortedData([...this.data]))), @@ -34,13 +38,17 @@ export class RoleListDatasource extends DataSource { disconnect() {} private getPagedData(data: Role[]) { - if (this.paginator === undefined) return data; + if (this.paginator === undefined) { + return data; + } const startIndex = this.paginator.pageIndex * this.paginator.pageSize; return data.splice(startIndex, this.paginator.pageSize); } private getSortedData(data: Role[]) { - if (this.sort === undefined) return data; + if (this.sort === undefined) { + return data; + } if (!this.sort.active || this.sort.direction === '') { return data; } diff --git a/overlord/src/app/role/role-resolver.service.spec.ts b/overlord/src/app/role/role-resolver.service.spec.ts index adefdc0f..a55cf6ba 100644 --- a/overlord/src/app/role/role-resolver.service.spec.ts +++ b/overlord/src/app/role/role-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { RoleResolver } from './role-resolver.service'; diff --git a/overlord/src/app/role/role.service.spec.ts b/overlord/src/app/role/role.service.spec.ts index cd6ea76a..93ad5341 100644 --- a/overlord/src/app/role/role.service.spec.ts +++ b/overlord/src/app/role/role.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { RoleService } from './role.service'; diff --git a/overlord/src/app/role/role.service.ts b/overlord/src/app/role/role.service.ts index 3fb95af3..b020c2b9 100644 --- a/overlord/src/app/role/role.service.ts +++ b/overlord/src/app/role/role.service.ts @@ -7,9 +7,6 @@ import { ErrorLoggerService } from '../core/error-logger.service'; import { Role } from './role'; -const httpOptions = { - headers: new HttpHeaders({ 'Content-Type': 'application/json' }), -}; const url = '/api/roles'; const serviceName = 'RoleService'; @@ -21,35 +18,27 @@ export class RoleService { get(id: string | null): Observable { const getUrl: string = id === null ? `${url}` : `${url}/${id}`; - return >( - this.http - .get(getUrl) - .pipe(catchError(this.log.handleError(serviceName, `get id=${id}`))) - ); + return this.http + .get(getUrl) + .pipe(catchError(this.log.handleError(serviceName, `get id as Observable=${id}`))) as Observable; } list(): Observable { - return >( - this.http - .get(`${url}/list`) - .pipe(catchError(this.log.handleError(serviceName, 'list'))) - ); + return this.http + .get(`${url}/list`) + .pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable; } save(role: Role): Observable { - return >( - this.http - .post(`${url}`, role, httpOptions) - .pipe(catchError(this.log.handleError(serviceName, 'save'))) - ); + return this.http + .post(`${url}`, role) + .pipe(catchError(this.log.handleError(serviceName, 'save'))) as Observable; } update(role: Role): Observable { - return >( - this.http - .put(`${url}/${role.id}`, role, httpOptions) - .pipe(catchError(this.log.handleError(serviceName, 'update'))) - ); + return this.http + .put(`${url}/${role.id}`, role) + .pipe(catchError(this.log.handleError(serviceName, 'update'))) as Observable; } saveOrUpdate(role: Role): Observable { @@ -60,10 +49,8 @@ export class RoleService { } delete(id: string): Observable { - return >( - this.http - .delete(`${url}/${id}`, httpOptions) - .pipe(catchError(this.log.handleError(serviceName, 'delete'))) - ); + return this.http + .delete(`${url}/${id}`) + .pipe(catchError(this.log.handleError(serviceName, 'delete'))) as Observable; } } diff --git a/overlord/src/app/settings/settings.service.ts b/overlord/src/app/settings/settings.service.ts index a626e1a1..e9f0c7d1 100644 --- a/overlord/src/app/settings/settings.service.ts +++ b/overlord/src/app/settings/settings.service.ts @@ -16,29 +16,29 @@ export class SettingsService { getLockInformation(): Observable { const url = '/api/lock-information'; - return >( - this.http - .get(url) - .pipe(catchError(this.log.handleError(serviceName, 'getLockInformation'))) - ); + return this.http + .get(url) + .pipe( + catchError(this.log.handleError(serviceName, 'getLockInformation')), + ) as Observable; } setLockInformation(lockInformation: LockInfo): Observable { const url = '/api/lock-information'; - return >( - this.http - .post(url, lockInformation) - .pipe(catchError(this.log.handleError(serviceName, 'setLockInformation'))) - ); + return this.http + .post(url, lockInformation) + .pipe( + catchError(this.log.handleError(serviceName, 'setLockInformation')), + ) as Observable; } deleteLockInformation(): Observable { const url = '/api/lock-information'; - return >( - this.http - .delete(url) - .pipe(catchError(this.log.handleError(serviceName, 'deleteLockInformation'))) - ); + return this.http + .delete(url) + .pipe( + catchError(this.log.handleError(serviceName, 'deleteLockInformation')), + ) as Observable; } resetStock( @@ -48,42 +48,36 @@ export class SettingsService { quantity: number, ): Observable { const url = '/api/reset-stock'; - return >this.http + return this.http .post(`${url}/${product.id}`, { stockDate, resetDate, quantity }) - .pipe(catchError(this.log.handleError(serviceName, 'resetStock'))); + .pipe(catchError(this.log.handleError(serviceName, 'resetStock'))) as Observable; } - rebaseDatabase(date: string): Observable<{}> { + rebaseDatabase(date: string): Observable> { const url = '/api/rebase'; - return >( - this.http - .post<{}>(`${url}/${date}`, {}) - .pipe(catchError(this.log.handleError(serviceName, 'rebaseDatabase'))) - ); + return this.http + .post>(`${url}/${date}`, {}) + .pipe(catchError(this.log.handleError(serviceName, 'rebaseDatabase'))) as Observable>; } setMaintenance(enable: boolean): Observable<{ enabled: boolean; user: string }> { const url = '/api/maintenance'; - return >this.http + return this.http .post<{ enabled: boolean; user: string }>(url, { enabled: enable }) - .pipe(catchError(this.log.handleError(serviceName, 'setMaintenance'))); + .pipe(catchError(this.log.handleError(serviceName, 'setMaintenance'))) as Observable<{ enabled: boolean; user: string }>; } getMaintenance(): Observable<{ enabled: boolean; user: string }> { const url = '/api/maintenance'; - return >( - this.http + return this.http .get<{ enabled: boolean; user: string }>(url) - .pipe(catchError(this.log.handleError(serviceName, 'getMaintenance'))) - ); + .pipe(catchError(this.log.handleError(serviceName, 'getMaintenance'))) as Observable<{ enabled: boolean; user: string }>; } - checkDatabaseIntegrity(): Observable<{ 'Duplicate Attendances Fixed': number }> { + checkDatabaseIntegrity(): Observable<{ 'attendanceCount': number }> { const url = '/api/db-integrity'; - return >( - this.http - .post<{ 'Duplicate Attendances Fixed': number }>(url, {}) - .pipe(catchError(this.log.handleError(serviceName, 'checkDatabaseIntegrity'))) - ); + return this.http + .post<{ 'attendanceCount': number }>(url, {}) + .pipe(catchError(this.log.handleError(serviceName, 'checkDatabaseIntegrity'))) as Observable<{ 'attendanceCount': number }>; } } diff --git a/overlord/src/app/shared/clear.pipe.ts b/overlord/src/app/shared/clear.pipe.ts index e7403ce5..ce5855af 100644 --- a/overlord/src/app/shared/clear.pipe.ts +++ b/overlord/src/app/shared/clear.pipe.ts @@ -5,7 +5,9 @@ import { Pipe, PipeTransform } from '@angular/core'; }) export class ClearPipe implements PipeTransform { transform(value: string | null): string { - if (value === null) return ''; + if (value === null) { + return ''; + } return value === 'โ‚นย 0.00' || value === '0.00' ? '' : value; } } diff --git a/overlord/src/app/shared/image.service.ts b/overlord/src/app/shared/image.service.ts index 4c1ddd02..c9f61354 100644 --- a/overlord/src/app/shared/image.service.ts +++ b/overlord/src/app/shared/image.service.ts @@ -10,7 +10,7 @@ import { Voucher } from '../core/voucher'; }) export class ImageService { // eslint-disable-next-line class-methods-use-this - resizeImage(image: string, MAX_WIDTH: number, MAX_HEIGHT: number) { + resizeImage(image: string, maxWidth: number, maxHeight: number) { const canvas = document.createElement('canvas'); const ctx = canvas.getContext('2d') as CanvasRenderingContext2D; const img = new Image(); @@ -18,7 +18,7 @@ export class ImageService { map(() => { let width = img.naturalWidth; let height = img.naturalHeight; - const ratio = Math.min(1, MAX_WIDTH / width, MAX_HEIGHT / height); + const ratio = Math.min(1, maxWidth / width, maxHeight / height); if (ratio === 1) { return image; @@ -38,12 +38,12 @@ export class ImageService { } detectFiles(event: Event, voucher: Voucher) { - const { files } = event.target as HTMLInputElement; - if (!files) { + // const { files } = event.target as HTMLInputElement; + const fileList = (event.target as HTMLInputElement).files; + if (fileList === null) { return; } - for (let i = 0; i < files.length; i += 1) { - const file = files[i]; + for (const file of Array.from(fileList)) { const reader = new FileReader(); reader.onload = (e) => { const target = e.target as FileReader; diff --git a/overlord/src/app/stock-movement/stock-movement-datasource.ts b/overlord/src/app/stock-movement/stock-movement-datasource.ts index 3243c8cf..ebdc0086 100644 --- a/overlord/src/app/stock-movement/stock-movement-datasource.ts +++ b/overlord/src/app/stock-movement/stock-movement-datasource.ts @@ -8,9 +8,7 @@ import { map } from 'rxjs/operators'; import { StockMovementItem } from './stock-movement-item'; /** Simple sort comparator for example ID/Name columns (for client-side sorting). */ -function compare(a: string | number, b: string | number, isAsc: boolean) { - return (a < b ? -1 : 1) * (isAsc ? 1 : -1); -} +const compare = (a: string | number, b: string | number, isAsc: boolean) => (a < b ? -1 : 1) * (isAsc ? 1 : -1); export class StockMovementDataSource extends DataSource { constructor( public data: StockMovementItem[], @@ -26,11 +24,17 @@ export class StockMovementDataSource extends DataSource { | EventEmitter | EventEmitter )[] = [observableOf(this.data)]; - if (this.paginator) dataMutations.push((this.paginator as MatPaginator).page); - if (this.sort) dataMutations.push((this.sort as MatSort).sortChange); + if (this.paginator) { + dataMutations.push((this.paginator as MatPaginator).page); + } + if (this.sort) { + dataMutations.push((this.sort as MatSort).sortChange); + } // Set the paginators length - if (this.paginator) this.paginator.length = this.data.length; + if (this.paginator) { + this.paginator.length = this.data.length; + } return merge(...dataMutations).pipe( map(() => this.getPagedData(this.getSortedData([...this.data]))), @@ -40,13 +44,17 @@ export class StockMovementDataSource extends DataSource { disconnect() {} private getPagedData(data: StockMovementItem[]) { - if (this.paginator === undefined) return data; + if (this.paginator === undefined) { + return data; + } const startIndex = this.paginator.pageIndex * this.paginator.pageSize; return data.splice(startIndex, this.paginator.pageSize); } private getSortedData(data: StockMovementItem[]) { - if (this.sort === undefined) return data; + if (this.sort === undefined) { + return data; + } if (!this.sort.active || this.sort.direction === '') { return data; } diff --git a/overlord/src/app/stock-movement/stock-movement-resolver.service.spec.ts b/overlord/src/app/stock-movement/stock-movement-resolver.service.spec.ts index b06b7a7a..21157696 100644 --- a/overlord/src/app/stock-movement/stock-movement-resolver.service.spec.ts +++ b/overlord/src/app/stock-movement/stock-movement-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { StockMovementResolver } from './stock-movement-resolver.service'; diff --git a/overlord/src/app/stock-movement/stock-movement.service.spec.ts b/overlord/src/app/stock-movement/stock-movement.service.spec.ts index 8e1d06de..142788b8 100644 --- a/overlord/src/app/stock-movement/stock-movement.service.spec.ts +++ b/overlord/src/app/stock-movement/stock-movement.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { StockMovementService } from './stock-movement.service'; diff --git a/overlord/src/app/stock-movement/stock-movement.service.ts b/overlord/src/app/stock-movement/stock-movement.service.ts index 38bcafd0..6531ffe4 100644 --- a/overlord/src/app/stock-movement/stock-movement.service.ts +++ b/overlord/src/app/stock-movement/stock-movement.service.ts @@ -19,10 +19,8 @@ export class StockMovementService { list(startDate: string | null, finishDate: string | null): Observable { const startDateWithSlash = startDate ? `/${startDate}` : ''; const finishDateWishSlash = finishDate ? `/${finishDate}` : ''; - return >( - this.http - .get(`${url}${startDateWithSlash}${finishDateWishSlash}`) - .pipe(catchError(this.log.handleError(serviceName, 'list'))) - ); + return this.http + .get(`${url}${startDateWithSlash}${finishDateWishSlash}`) + .pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable; } } diff --git a/overlord/src/app/trial-balance/trial-balance-datasource.ts b/overlord/src/app/trial-balance/trial-balance-datasource.ts index 5b11c9d1..61b5aa02 100644 --- a/overlord/src/app/trial-balance/trial-balance-datasource.ts +++ b/overlord/src/app/trial-balance/trial-balance-datasource.ts @@ -8,9 +8,7 @@ import { map } from 'rxjs/operators'; import { TrialBalanceItem } from './trial-balance-item'; /** Simple sort comparator for example ID/Name columns (for client-side sorting). */ -function compare(a: string | number, b: string | number, isAsc: boolean) { - return (a < b ? -1 : 1) * (isAsc ? 1 : -1); -} +const compare = (a: string | number, b: string | number, isAsc: boolean) => (a < b ? -1 : 1) * (isAsc ? 1 : -1); export class TrialBalanceDataSource extends DataSource { constructor( public data: TrialBalanceItem[], @@ -26,11 +24,17 @@ export class TrialBalanceDataSource extends DataSource { | EventEmitter | EventEmitter )[] = [observableOf(this.data)]; - if (this.paginator) dataMutations.push((this.paginator as MatPaginator).page); - if (this.sort) dataMutations.push((this.sort as MatSort).sortChange); + if (this.paginator) { + dataMutations.push((this.paginator as MatPaginator).page); + } + if (this.sort) { + dataMutations.push((this.sort as MatSort).sortChange); + } // Set the paginators length - if (this.paginator) this.paginator.length = this.data.length; + if (this.paginator) { + this.paginator.length = this.data.length; + } return merge(...dataMutations).pipe( map(() => this.getPagedData(this.getSortedData([...this.data]))), @@ -40,13 +44,17 @@ export class TrialBalanceDataSource extends DataSource { disconnect() {} private getPagedData(data: TrialBalanceItem[]) { - if (this.paginator === undefined) return data; + if (this.paginator === undefined) { + return data; + } const startIndex = this.paginator.pageIndex * this.paginator.pageSize; return data.splice(startIndex, this.paginator.pageSize); } private getSortedData(data: TrialBalanceItem[]) { - if (this.sort === undefined) return data; + if (this.sort === undefined) { + return data; + } if (!this.sort.active || this.sort.direction === '') { return data; } diff --git a/overlord/src/app/trial-balance/trial-balance-resolver.service.spec.ts b/overlord/src/app/trial-balance/trial-balance-resolver.service.spec.ts index b3ff6631..deb205d6 100644 --- a/overlord/src/app/trial-balance/trial-balance-resolver.service.spec.ts +++ b/overlord/src/app/trial-balance/trial-balance-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { TrialBalanceResolver } from './trial-balance-resolver.service'; diff --git a/overlord/src/app/trial-balance/trial-balance.service.spec.ts b/overlord/src/app/trial-balance/trial-balance.service.spec.ts index 1ef4f599..769faeb0 100644 --- a/overlord/src/app/trial-balance/trial-balance.service.spec.ts +++ b/overlord/src/app/trial-balance/trial-balance.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { TrialBalanceService } from './trial-balance.service'; diff --git a/overlord/src/app/trial-balance/trial-balance.service.ts b/overlord/src/app/trial-balance/trial-balance.service.ts index d36615cf..642b4117 100644 --- a/overlord/src/app/trial-balance/trial-balance.service.ts +++ b/overlord/src/app/trial-balance/trial-balance.service.ts @@ -18,10 +18,8 @@ export class TrialBalanceService { list(date: string | null): Observable { const listUrl = date === null ? url : `${url}/${date}`; - return >( - this.http - .get(listUrl) - .pipe(catchError(this.log.handleError(serviceName, 'list'))) - ); + return this.http + .get(listUrl) + .pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable; } } diff --git a/overlord/src/app/unposted/unposted-datasource.ts b/overlord/src/app/unposted/unposted-datasource.ts index a144ceb3..7d8039ab 100644 --- a/overlord/src/app/unposted/unposted-datasource.ts +++ b/overlord/src/app/unposted/unposted-datasource.ts @@ -8,9 +8,7 @@ import { map } from 'rxjs/operators'; import { Unposted } from './unposted'; /** Simple sort comparator for example ID/Name columns (for client-side sorting). */ -function compare(a: string | number, b: string | number, isAsc: boolean) { - return (a < b ? -1 : 1) * (isAsc ? 1 : -1); -} +const compare = (a: string | number, b: string | number, isAsc: boolean) => (a < b ? -1 : 1) * (isAsc ? 1 : -1); export class UnpostedDataSource extends DataSource { constructor(public data: Unposted[], private paginator?: MatPaginator, private sort?: MatSort) { @@ -23,11 +21,17 @@ export class UnpostedDataSource extends DataSource { | EventEmitter | EventEmitter )[] = [observableOf(this.data)]; - if (this.paginator) dataMutations.push((this.paginator as MatPaginator).page); - if (this.sort) dataMutations.push((this.sort as MatSort).sortChange); + if (this.paginator) { + dataMutations.push((this.paginator as MatPaginator).page); + } + if (this.sort) { + dataMutations.push((this.sort as MatSort).sortChange); + } // Set the paginators length - if (this.paginator) this.paginator.length = this.data.length; + if (this.paginator) { + this.paginator.length = this.data.length; + } return merge(...dataMutations).pipe( map(() => this.getPagedData(this.getSortedData([...this.data]))), @@ -37,13 +41,17 @@ export class UnpostedDataSource extends DataSource { disconnect() {} private getPagedData(data: Unposted[]) { - if (this.paginator === undefined) return data; + if (this.paginator === undefined) { + return data; + } const startIndex = this.paginator.pageIndex * this.paginator.pageSize; return data.splice(startIndex, this.paginator.pageSize); } private getSortedData(data: Unposted[]) { - if (this.sort === undefined) return data; + if (this.sort === undefined) { + return data; + } if (!this.sort.active || this.sort.direction === '') { return data; } diff --git a/overlord/src/app/unposted/unposted-resolver.service.spec.ts b/overlord/src/app/unposted/unposted-resolver.service.spec.ts index d7d38fc9..8edaf037 100644 --- a/overlord/src/app/unposted/unposted-resolver.service.spec.ts +++ b/overlord/src/app/unposted/unposted-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { UnpostedResolver } from './unposted-resolver.service'; diff --git a/overlord/src/app/unposted/unposted.component.spec.ts b/overlord/src/app/unposted/unposted.component.spec.ts index 945a84ed..43a3e076 100644 --- a/overlord/src/app/unposted/unposted.component.spec.ts +++ b/overlord/src/app/unposted/unposted.component.spec.ts @@ -1,5 +1,5 @@ -import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { UnpostedComponent } from './unposted.component'; diff --git a/overlord/src/app/unposted/unposted.service.spec.ts b/overlord/src/app/unposted/unposted.service.spec.ts index 0d903c4c..ff0b67fe 100644 --- a/overlord/src/app/unposted/unposted.service.spec.ts +++ b/overlord/src/app/unposted/unposted.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { UnpostedService } from './unposted.service'; diff --git a/overlord/src/app/unposted/unposted.service.ts b/overlord/src/app/unposted/unposted.service.ts index 0c0965eb..c8bbbdce 100644 --- a/overlord/src/app/unposted/unposted.service.ts +++ b/overlord/src/app/unposted/unposted.service.ts @@ -17,8 +17,8 @@ export class UnpostedService { constructor(private http: HttpClient, private log: ErrorLoggerService) {} list(): Observable { - return >( - this.http.get(url).pipe(catchError(this.log.handleError(serviceName, 'list'))) - ); + return this.http + .get(url) + .pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable; } } diff --git a/overlord/src/app/user/user-detail/user-detail.component.ts b/overlord/src/app/user/user-detail/user-detail.component.ts index 3a3342d6..7acf316d 100644 --- a/overlord/src/app/user/user-detail/user-detail.component.ts +++ b/overlord/src/app/user/user-detail/user-detail.component.ts @@ -63,7 +63,9 @@ export class UserDetailComponent implements OnInit, AfterViewInit { ngAfterViewInit() { setTimeout(() => { - if (this.nameElement) this.nameElement.nativeElement.focus(); + if (this.nameElement) { + this.nameElement.nativeElement.focus(); + } }, 0); } diff --git a/overlord/src/app/user/user-list-resolver.service.spec.ts b/overlord/src/app/user/user-list-resolver.service.spec.ts index b6ebdf12..cc3d3d24 100644 --- a/overlord/src/app/user/user-list-resolver.service.spec.ts +++ b/overlord/src/app/user/user-list-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { UserListResolver } from './user-list-resolver.service'; diff --git a/overlord/src/app/user/user-list/user-list-datasource.ts b/overlord/src/app/user/user-list/user-list-datasource.ts index a836d404..b73fcafe 100644 --- a/overlord/src/app/user/user-list/user-list-datasource.ts +++ b/overlord/src/app/user/user-list/user-list-datasource.ts @@ -8,9 +8,7 @@ import { map } from 'rxjs/operators'; import { User } from '../../core/user'; /** Simple sort comparator for example ID/Name columns (for client-side sorting). */ -function compare(a: string | number, b: string | number, isAsc: boolean) { - return (a < b ? -1 : 1) * (isAsc ? 1 : -1); -} +const compare = (a: string | number, b: string | number, isAsc: boolean) => (a < b ? -1 : 1) * (isAsc ? 1 : -1); export class UserListDataSource extends DataSource { constructor(public data: User[], private paginator?: MatPaginator, private sort?: MatSort) { @@ -21,11 +19,17 @@ export class UserListDataSource extends DataSource { const dataMutations: (Observable | EventEmitter | EventEmitter)[] = [ observableOf(this.data), ]; - if (this.paginator) dataMutations.push((this.paginator as MatPaginator).page); - if (this.sort) dataMutations.push((this.sort as MatSort).sortChange); + if (this.paginator) { + dataMutations.push((this.paginator as MatPaginator).page); + } + if (this.sort) { + dataMutations.push((this.sort as MatSort).sortChange); + } // Set the paginators length - if (this.paginator) this.paginator.length = this.data.length; + if (this.paginator) { + this.paginator.length = this.data.length; + } return merge(...dataMutations).pipe( map(() => this.getPagedData(this.getSortedData([...this.data]))), @@ -35,13 +39,17 @@ export class UserListDataSource extends DataSource { disconnect() {} private getPagedData(data: User[]) { - if (this.paginator === undefined) return data; + if (this.paginator === undefined) { + return data; + } const startIndex = this.paginator.pageIndex * this.paginator.pageSize; return data.splice(startIndex, this.paginator.pageSize); } private getSortedData(data: User[]) { - if (this.sort === undefined) return data; + if (this.sort === undefined) { + return data; + } if (!this.sort.active || this.sort.direction === '') { return data; } diff --git a/overlord/src/app/user/user-resolver.service.spec.ts b/overlord/src/app/user/user-resolver.service.spec.ts index 22bde6dc..5ff94812 100644 --- a/overlord/src/app/user/user-resolver.service.spec.ts +++ b/overlord/src/app/user/user-resolver.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { UserResolver } from './user-resolver.service'; diff --git a/overlord/src/app/user/user.service.spec.ts b/overlord/src/app/user/user.service.spec.ts index ef41bb1b..cb61fe54 100644 --- a/overlord/src/app/user/user.service.spec.ts +++ b/overlord/src/app/user/user.service.spec.ts @@ -1,5 +1,5 @@ -import { inject, TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; +import { inject, TestBed } from '@angular/core/testing'; import { UserService } from './user.service'; diff --git a/overlord/src/app/user/user.service.ts b/overlord/src/app/user/user.service.ts index 2ff72202..d3a882d5 100644 --- a/overlord/src/app/user/user.service.ts +++ b/overlord/src/app/user/user.service.ts @@ -1,4 +1,4 @@ -import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/internal/Observable'; import { catchError } from 'rxjs/operators'; @@ -6,9 +6,6 @@ import { catchError } from 'rxjs/operators'; import { ErrorLoggerService } from '../core/error-logger.service'; import { User } from '../core/user'; -const httpOptions = { - headers: new HttpHeaders({ 'Content-Type': 'application/json' }), -}; const url = '/api/users'; const serviceName = 'UserService'; @@ -20,51 +17,39 @@ export class UserService { get(id: string | null): Observable { const getUrl: string = id === null ? `${url}` : `${url}/${id}`; - return >( - this.http - .get(getUrl) - .pipe(catchError(this.log.handleError(serviceName, `get id=${id}`))) - ); + return this.http + .get(getUrl) + .pipe(catchError(this.log.handleError(serviceName, `get id=${id}`))) as Observable; } list(): Observable { - return >( - this.http - .get(`${url}/list`) - .pipe(catchError(this.log.handleError(serviceName, 'list'))) - ); + return this.http + .get(`${url}/list`) + .pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable; } listOfNames(): Observable { - return >( - this.http - .get(`${url}/active`) - .pipe(catchError(this.log.handleError(serviceName, 'list'))) - ); + return this.http + .get(`${url}/active`) + .pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable; } save(user: User): Observable { - return >( - this.http - .post(`${url}`, user, httpOptions) - .pipe(catchError(this.log.handleError(serviceName, 'save'))) - ); + return this.http + .post(`${url}`, user) + .pipe(catchError(this.log.handleError(serviceName, 'save'))) as Observable; } update(user: User): Observable { - return >( - this.http - .put(`${url}/${user.id}`, user, httpOptions) - .pipe(catchError(this.log.handleError(serviceName, 'update'))) - ); + return this.http + .put(`${url}/${user.id}`, user) + .pipe(catchError(this.log.handleError(serviceName, 'update'))) as Observable; } updateMe(user: User): Observable { - return >( - this.http - .put(`${url}/me`, user, httpOptions) - .pipe(catchError(this.log.handleError(serviceName, 'update'))) - ); + return this.http + .put(`${url}/me`, user) + .pipe(catchError(this.log.handleError(serviceName, 'update'))) as Observable; } saveOrUpdate(user: User): Observable { @@ -75,10 +60,8 @@ export class UserService { } delete(id: string): Observable { - return >( - this.http - .delete(`${url}/${id}`, httpOptions) - .pipe(catchError(this.log.handleError(serviceName, 'delete'))) - ); + return this.http + .delete(`${url}/${id}`) + .pipe(catchError(this.log.handleError(serviceName, 'delete'))) as Observable; } } diff --git a/overlord/src/environments/environment.prod.ts b/overlord/src/environments/environment.prod.ts index ebca13bb..7c1f2383 100644 --- a/overlord/src/environments/environment.prod.ts +++ b/overlord/src/environments/environment.prod.ts @@ -1,5 +1,6 @@ export const environment = { production: true, + // eslint-disable-next-line @typescript-eslint/naming-convention ACCESS_TOKEN_REFRESH_MINUTES: 10, // refresh token 10 minutes before expiry version: '9.2.0', }; diff --git a/overlord/src/environments/environment.ts b/overlord/src/environments/environment.ts index a3aed89a..e1b68cb9 100644 --- a/overlord/src/environments/environment.ts +++ b/overlord/src/environments/environment.ts @@ -4,6 +4,7 @@ export const environment = { production: false, + // eslint-disable-next-line @typescript-eslint/naming-convention ACCESS_TOKEN_REFRESH_MINUTES: 10, // refresh token 10 minutes before expiry version: '9.2.0', }; diff --git a/overlord/src/index.html b/overlord/src/index.html index 44fa5c01..da670e8e 100644 --- a/overlord/src/index.html +++ b/overlord/src/index.html @@ -1,16 +1,15 @@ - - Overlord - + + - + diff --git a/overlord/tsconfig.spec.json b/overlord/tsconfig.spec.json index 3bdca8d7..092345b0 100644 --- a/overlord/tsconfig.spec.json +++ b/overlord/tsconfig.spec.json @@ -2,7 +2,7 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "outDir": "../out-tsc/spec", + "outDir": "./out-tsc/spec", "types": [ "jasmine" ]