From dbdd00119a77372c9acbc4f7d6f3ccfb172da34f Mon Sep 17 00:00:00 2001 From: Amritanshu <git@tanshu.com> Date: Sun, 17 Jul 2022 08:17:13 +0530 Subject: [PATCH] Instanceof operator was not working so changed the way of checking it --- docker/playbook.yml | 8 +++++--- overlord/.eslintrc.json | 3 +++ .../account/account-detail/account-detail.component.ts | 6 +++--- .../app/account/account-list/account-list-datasource.ts | 3 +-- .../app/account/account-list/account-list.component.html | 2 +- .../app/account/account-list/account-list.component.ts | 5 +---- overlord/src/app/closing-stock/closing-stock.component.ts | 1 - overlord/src/app/core/account.ts | 7 ++++--- overlord/src/app/core/error-logger.service.ts | 2 -- overlord/src/app/core/jwt.interceptor.ts | 1 - overlord/src/app/core/voucher.service.ts | 1 - .../employee-attendance/employee-attendance.component.ts | 2 +- overlord/src/app/entries/entries.component.ts | 1 - overlord/src/app/issue/issue-dialog.component.ts | 2 +- overlord/src/app/issue/issue.component.ts | 2 +- overlord/src/app/ledger/ledger.component.ts | 2 +- .../src/app/product-ledger/product-ledger.component.ts | 2 +- .../purchase-return/purchase-return-dialog.component.ts | 2 +- .../src/app/purchase-return/purchase-return.component.ts | 6 +++--- overlord/src/app/purchase/purchase-dialog.component.ts | 2 +- overlord/src/app/purchase/purchase.component.ts | 4 ++-- .../rate-contract-detail.component.ts | 7 +++---- .../app/recipe/recipe-detail/recipe-detail.component.ts | 2 +- .../src/app/role/role-detail/role-detail.component.ts | 3 ++- overlord/src/app/shared/cookie.service.ts | 2 -- overlord/src/app/shared/image.service.ts | 1 - overlord/src/app/shared/to-csv.service.ts | 1 - 27 files changed, 36 insertions(+), 44 deletions(-) diff --git a/docker/playbook.yml b/docker/playbook.yml index 436b08dd..9bc1d330 100755 --- a/docker/playbook.yml +++ b/docker/playbook.yml @@ -9,14 +9,16 @@ tasks: - name: Copy dockerfile - synchronize: src=app dest=/tmp + synchronize: + src: app + dest: "/tmp/{{ host_directory }}" - name: Build brewman image docker_image: name: brewman:latest build: - path: /tmp/app/ - dockerfile: /tmp/app/Dockerfile + path: "/tmp/{{ host_directory }}/" + dockerfile: "/tmp/{{ host_directory }}/Dockerfile" pull: yes state: present source: build diff --git a/overlord/.eslintrc.json b/overlord/.eslintrc.json index 6deda183..aa476315 100644 --- a/overlord/.eslintrc.json +++ b/overlord/.eslintrc.json @@ -56,6 +56,9 @@ "newlines-between": "always" } ], + "@typescript-eslint/no-explicit-any": [ + "error" + ], "unused-imports/no-unused-imports": "error" } }, 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 be1229fa..1c20f18f 100644 --- a/overlord/src/app/account/account-detail/account-detail.component.ts +++ b/overlord/src/app/account/account-detail/account-detail.component.ts @@ -20,7 +20,7 @@ export class AccountDetailComponent implements OnInit, AfterViewInit { form: FormGroup<{ code: FormControl<number | string>; name: FormControl<string | null>; - type: FormControl<any>; + type: FormControl<number>; isActive: FormControl<boolean>; isReconcilable: FormControl<boolean>; costCentre: FormControl<string | null>; @@ -40,7 +40,7 @@ export class AccountDetailComponent implements OnInit, AfterViewInit { this.form = new FormGroup({ code: new FormControl<string | number>({ value: 0, disabled: true }, { nonNullable: true }), name: new FormControl<string | null>(null), - type: new FormControl<any>(''), + type: new FormControl<number>(0, { nonNullable: true }), isActive: new FormControl<boolean>(true, { nonNullable: true }), isReconcilable: new FormControl<boolean>(false, { nonNullable: true }), costCentre: new FormControl<string | null>(null), @@ -121,7 +121,7 @@ export class AccountDetailComponent implements OnInit, AfterViewInit { getItem(): Account { const formModel = this.form.value; this.item.name = formModel.name!; - this.item.type = formModel.type; + this.item.type = formModel.type!; this.item.isActive = formModel.isActive!; this.item.isReconcilable = formModel.isReconcilable!; this.item.costCentre.id = formModel.costCentre!; 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 cb426f94..99bc6149 100644 --- a/overlord/src/app/account/account-list/account-list-datasource.ts +++ b/overlord/src/app/account/account-list/account-list-datasource.ts @@ -6,7 +6,6 @@ import { merge, Observable, of as observableOf } from 'rxjs'; import { map, tap } from 'rxjs/operators'; import { Account } from '../../core/account'; -import { AccountType } from '../../core/account-type'; /** Simple sort comparator for example ID/Name columns (for client-side sorting). */ const compare = (a: string | number | boolean, b: string | number | boolean, isAsc: boolean) => @@ -92,7 +91,7 @@ export class AccountListDataSource extends DataSource<Account> { case 'name': return compare(a.name, b.name, isAsc); case 'type': - return compare((a.type as AccountType).name, (b.type as AccountType).name, isAsc); + return compare(a.typeName, b.typeName, isAsc); case 'isActive': return compare(a.isActive, b.isActive, isAsc); case 'isReconcilable': diff --git a/overlord/src/app/account/account-list/account-list.component.html b/overlord/src/app/account/account-list/account-list.component.html index f84e3406..b9c287e8 100644 --- a/overlord/src/app/account/account-list/account-list.component.html +++ b/overlord/src/app/account/account-list/account-list.component.html @@ -42,7 +42,7 @@ <!-- Type Column --> <ng-container matColumnDef="type"> <mat-header-cell *matHeaderCellDef mat-sort-header>Type</mat-header-cell> - <mat-cell *matCellDef="let row">{{ row.type.name }}</mat-cell> + <mat-cell *matCellDef="let row">{{ row.typeName }}</mat-cell> </ng-container> <!-- Is Active? Column --> 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 6e0e7ea9..41ed9398 100644 --- a/overlord/src/app/account/account-list/account-list.component.ts +++ b/overlord/src/app/account/account-list/account-list.component.ts @@ -50,10 +50,7 @@ export class AccountListComponent implements OnInit, AfterViewInit { const data = value as { list: Account[]; accountTypes: AccountType[] }; this.accountTypes = data.accountTypes; data.list.forEach( - (x) => - (x.type = new AccountType({ - name: this.accountTypes.find((y) => y.id === x.type)?.name, - })), + (x) => (x.typeName = this.accountTypes.find((y) => y.id === x.type)?.name!), ); this.list = data.list; }); diff --git a/overlord/src/app/closing-stock/closing-stock.component.ts b/overlord/src/app/closing-stock/closing-stock.component.ts index c407ffe3..f8b72c32 100644 --- a/overlord/src/app/closing-stock/closing-stock.component.ts +++ b/overlord/src/app/closing-stock/closing-stock.component.ts @@ -124,7 +124,6 @@ export class ClosingStockComponent implements OnInit { ? undefined : new CostCentre({ id: array.controls[index].value.costCentre }); }); - console.log('getClosingStock', this.info); return this.info; } diff --git a/overlord/src/app/core/account.ts b/overlord/src/app/core/account.ts index 81a26283..1517edaa 100644 --- a/overlord/src/app/core/account.ts +++ b/overlord/src/app/core/account.ts @@ -1,11 +1,11 @@ -import { AccountType } from './account-type'; import { CostCentre } from './cost-centre'; export class Account { id: string | undefined; code: number; name: string; - type: AccountType | number; + type: number; + typeName: string; isActive: boolean; isReconcilable: boolean; isStarred: boolean; @@ -15,7 +15,8 @@ export class Account { public constructor(init?: Partial<Account>) { this.code = 0; this.name = ''; - this.type = new AccountType(); + this.type = 0; + this.typeName = ''; this.isActive = true; this.isReconcilable = false; this.isStarred = false; diff --git a/overlord/src/app/core/error-logger.service.ts b/overlord/src/app/core/error-logger.service.ts index 16a2bdf8..1bc41280 100644 --- a/overlord/src/app/core/error-logger.service.ts +++ b/overlord/src/app/core/error-logger.service.ts @@ -7,7 +7,6 @@ import { Observable } from 'rxjs/internal/Observable'; }) export class ErrorLoggerService { public static log(serviceName = 'error-logger', message: string) { - // eslint-disable-next-line no-console console.log(`${serviceName}Service: ${message}`); } @@ -18,7 +17,6 @@ export class ErrorLoggerService { * @param operation - name of the operation that failed * @param result - optional value to return as the observable result */ - // eslint-disable-next-line @typescript-eslint/no-unused-vars, class-methods-use-this public handleError<T>(serviceName = 'error-logger', operation = 'operation', result?: T) { return (error: unknown): Observable<T> => { ErrorLoggerService.log(serviceName, `${operation} failed: ${error}`); diff --git a/overlord/src/app/core/jwt.interceptor.ts b/overlord/src/app/core/jwt.interceptor.ts index 0f4529aa..940b7e53 100644 --- a/overlord/src/app/core/jwt.interceptor.ts +++ b/overlord/src/app/core/jwt.interceptor.ts @@ -22,7 +22,6 @@ export class JwtInterceptor implements HttpInterceptor { } const currentUser = this.authService.user; if (currentUser?.access_token) { - // eslint-disable-next-line no-param-reassign request = request.clone({ setHeaders: { Authorization: `Bearer ${currentUser.access_token}`, diff --git a/overlord/src/app/core/voucher.service.ts b/overlord/src/app/core/voucher.service.ts index 4fcd8bdb..9699879f 100644 --- a/overlord/src/app/core/voucher.service.ts +++ b/overlord/src/app/core/voucher.service.ts @@ -41,7 +41,6 @@ export class VoucherService { const endpoint = type.replace(/ /g, '-').toLowerCase(); let options = {}; if (account !== undefined && account !== null) { - // eslint-disable-next-line @typescript-eslint/dot-notation options = { params: new HttpParams().set('a', account) }; } return this.http diff --git a/overlord/src/app/employee-attendance/employee-attendance.component.ts b/overlord/src/app/employee-attendance/employee-attendance.component.ts index ca432961..88baa2e5 100644 --- a/overlord/src/app/employee-attendance/employee-attendance.component.ts +++ b/overlord/src/app/employee-attendance/employee-attendance.component.ts @@ -65,7 +65,7 @@ export class EmployeeAttendanceComponent implements OnInit, AfterViewInit { }); // Listen to Employee Value Changes this.employees = this.form.controls.employee.valueChanges.pipe( - map((x) => (x instanceof Employee ? x.name : x)), + map((x) => ((x as Employee).name !== undefined ? (x as Employee).name : (x as string))), map((x) => (x !== null && x.length >= 1 ? x : null)), debounceTime(150), distinctUntilChanged(), diff --git a/overlord/src/app/entries/entries.component.ts b/overlord/src/app/entries/entries.component.ts index 022a4b67..95b0ef3a 100644 --- a/overlord/src/app/entries/entries.component.ts +++ b/overlord/src/app/entries/entries.component.ts @@ -116,7 +116,6 @@ export class EntriesComponent implements OnInit { } togglePosted($event: MatRadioChange) { - console.log($event.value); this.posted = $event.value; if (this.posted === false) { this.issue = false; diff --git a/overlord/src/app/issue/issue-dialog.component.ts b/overlord/src/app/issue/issue-dialog.component.ts index cd9d27c9..2ebc8078 100644 --- a/overlord/src/app/issue/issue-dialog.component.ts +++ b/overlord/src/app/issue/issue-dialog.component.ts @@ -36,7 +36,7 @@ export class IssueDialogComponent implements OnInit { }); // Listen to Batch Autocomplete Change this.batches = this.form.controls.batch.valueChanges.pipe( - map((x) => (x instanceof Batch ? x.name : x)), + map((x) => ((x as Batch).name !== undefined ? (x as Batch).name : (x as string))), map((x) => (x !== null && x.length >= 1 ? x : '')), debounceTime(150), distinctUntilChanged(), diff --git a/overlord/src/app/issue/issue.component.ts b/overlord/src/app/issue/issue.component.ts index b896a471..75b9cf85 100644 --- a/overlord/src/app/issue/issue.component.ts +++ b/overlord/src/app/issue/issue.component.ts @@ -85,7 +85,7 @@ export class IssueComponent implements OnInit, AfterViewInit, OnDestroy { }); // Listen to Batch Autocomplete Change this.batches = this.form.controls.addRow.controls.batch.valueChanges.pipe( - map((x) => (x instanceof Batch ? x.name : x)), + map((x) => ((x as Batch).name !== undefined ? (x as Batch).name : (x as string))), map((x) => (x !== null && x.length >= 1 ? x : '')), debounceTime(150), distinctUntilChanged(), diff --git a/overlord/src/app/ledger/ledger.component.ts b/overlord/src/app/ledger/ledger.component.ts index 08c9d5b1..b98c7639 100644 --- a/overlord/src/app/ledger/ledger.component.ts +++ b/overlord/src/app/ledger/ledger.component.ts @@ -56,7 +56,7 @@ export class LedgerComponent implements OnInit, AfterViewInit { }); this.accounts = this.form.controls.account.valueChanges.pipe( - map((x) => (x instanceof Account ? x.name : x)), + map((x) => ((x as Account).name !== undefined ? (x as Account).name : (x as string))), map((x) => (x !== null && x.length >= 1 ? x : null)), debounceTime(150), distinctUntilChanged(), diff --git a/overlord/src/app/product-ledger/product-ledger.component.ts b/overlord/src/app/product-ledger/product-ledger.component.ts index 378443d7..63dff010 100644 --- a/overlord/src/app/product-ledger/product-ledger.component.ts +++ b/overlord/src/app/product-ledger/product-ledger.component.ts @@ -71,7 +71,7 @@ export class ProductLedgerComponent implements OnInit, AfterViewInit { }); this.products = this.form.controls.product.valueChanges.pipe( - map((x) => (x instanceof Product ? x.name : x)), + map((x) => ((x as Product).name !== undefined ? (x as Product).name : (x as string))), map((x) => (x !== null && x.length >= 1 ? x : null)), debounceTime(150), distinctUntilChanged(), diff --git a/overlord/src/app/purchase-return/purchase-return-dialog.component.ts b/overlord/src/app/purchase-return/purchase-return-dialog.component.ts index 5c8a4b73..9a43f811 100644 --- a/overlord/src/app/purchase-return/purchase-return-dialog.component.ts +++ b/overlord/src/app/purchase-return/purchase-return-dialog.component.ts @@ -36,7 +36,7 @@ export class PurchaseReturnDialogComponent implements OnInit { }); // Listen to Batch Autocomplete Change this.batches = this.form.controls.batch.valueChanges.pipe( - map((x) => (x instanceof Batch ? x.name : x)), + map((x) => ((x as Batch).name !== undefined ? (x as Batch).name : (x as string))), map((x) => (x !== null && x.length >= 1 ? x : '')), debounceTime(150), distinctUntilChanged(), diff --git a/overlord/src/app/purchase-return/purchase-return.component.ts b/overlord/src/app/purchase-return/purchase-return.component.ts index 4fd9d0ac..b265f469 100644 --- a/overlord/src/app/purchase-return/purchase-return.component.ts +++ b/overlord/src/app/purchase-return/purchase-return.component.ts @@ -85,7 +85,7 @@ export class PurchaseReturnComponent implements OnInit, AfterViewInit, OnDestroy }); // Listen to Account Autocomplete Change this.accounts = this.form.controls.account.valueChanges.pipe( - map((x) => (x instanceof Account ? x.name : x)), + map((x) => ((x as Account).name !== undefined ? (x as Account).name : (x as string))), map((x) => (x !== null && x.length >= 1 ? x : null)), debounceTime(150), distinctUntilChanged(), @@ -93,7 +93,7 @@ export class PurchaseReturnComponent implements OnInit, AfterViewInit, OnDestroy ); // Listen to Batch Autocomplete Change this.batches = this.form.controls.addRow.controls.batch.valueChanges.pipe( - map((x) => (x instanceof Batch ? x.name : x)), + map((x) => ((x as Batch).name !== undefined ? (x as Batch).name : (x as string))), map((x) => (x !== null && x.length >= 1 ? x : '')), debounceTime(150), distinctUntilChanged(), @@ -298,7 +298,7 @@ export class PurchaseReturnComponent implements OnInit, AfterViewInit, OnDestroy getVoucher(): Voucher { const formModel = this.form.value; this.voucher.date = moment(formModel.date).format('DD-MMM-YYYY'); - if (formModel.account instanceof Account) { + if (formModel.account !== null && typeof formModel.account !== 'string') { this.voucher.vendor = formModel.account; } this.voucher.narration = formModel.narration!; diff --git a/overlord/src/app/purchase/purchase-dialog.component.ts b/overlord/src/app/purchase/purchase-dialog.component.ts index 542bf1e5..6b79942e 100644 --- a/overlord/src/app/purchase/purchase-dialog.component.ts +++ b/overlord/src/app/purchase/purchase-dialog.component.ts @@ -45,7 +45,7 @@ export class PurchaseDialogComponent implements OnInit { }); // Listen to Product Autocomplete Change this.products = this.form.controls.product.valueChanges.pipe( - map((x) => (x instanceof ProductSku ? x.name : x)), + map((x) => ((x as ProductSku).name !== undefined ? (x as ProductSku).name : (x as string))), map((x) => (x !== null && x.length >= 1 ? x : null)), debounceTime(150), distinctUntilChanged(), diff --git a/overlord/src/app/purchase/purchase.component.ts b/overlord/src/app/purchase/purchase.component.ts index b5996e97..64e7e539 100644 --- a/overlord/src/app/purchase/purchase.component.ts +++ b/overlord/src/app/purchase/purchase.component.ts @@ -94,7 +94,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy { this.accBal = null; // Listen to Account Autocomplete Change this.accounts = this.form.controls.account.valueChanges.pipe( - map((x) => (x instanceof Account ? x.name : x)), + map((x) => ((x as Account).name !== undefined ? (x as Account).name : (x as string))), map((x) => (x !== null && x.length >= 1 ? x : null)), debounceTime(150), distinctUntilChanged(), @@ -329,7 +329,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy { getVoucher(): Voucher { const formModel = this.form.value; this.voucher.date = moment(formModel.date).format('DD-MMM-YYYY'); - if (formModel.account instanceof Account) { + if (formModel.account !== null && typeof formModel.account !== 'string') { this.voucher.vendor = formModel.account; } this.voucher.narration = formModel.narration!; diff --git a/overlord/src/app/rate-contract/rate-contract-detail/rate-contract-detail.component.ts b/overlord/src/app/rate-contract/rate-contract-detail/rate-contract-detail.component.ts index 00f742bc..636c0814 100644 --- a/overlord/src/app/rate-contract/rate-contract-detail/rate-contract-detail.component.ts +++ b/overlord/src/app/rate-contract/rate-contract-detail/rate-contract-detail.component.ts @@ -74,8 +74,7 @@ export class RateContractDetailComponent implements OnInit, AfterViewInit { narration: new FormControl('', { nonNullable: true }), }); this.accounts = this.form.controls.account.valueChanges.pipe( - map((x) => (x instanceof Account ? x.name : x)), - map((x) => (x !== null && x.length >= 1 ? x : null)), + map((x) => ((x as Account).name !== undefined ? (x as Account).name : (x as string))), map((x) => (x !== null && x.length >= 1 ? x : null)), debounceTime(150), distinctUntilChanged(), @@ -216,8 +215,8 @@ export class RateContractDetailComponent implements OnInit, AfterViewInit { this.item.date = moment(formModel.date).format('DD-MMM-YYYY'); this.item.validFrom = moment(formModel.validFrom).format('DD-MMM-YYYY'); this.item.validTill = moment(formModel.validTill).format('DD-MMM-YYYY'); - if (formModel.account instanceof Account) { - this.item.vendor = formModel.account; + if (formModel.account !== null && typeof formModel.account !== 'string') { + this.item.vendor = formModel.account!; } this.item.narration = formModel.narration!; return this.item; diff --git a/overlord/src/app/recipe/recipe-detail/recipe-detail.component.ts b/overlord/src/app/recipe/recipe-detail/recipe-detail.component.ts index 3de0e27b..01da5c75 100644 --- a/overlord/src/app/recipe/recipe-detail/recipe-detail.component.ts +++ b/overlord/src/app/recipe/recipe-detail/recipe-detail.component.ts @@ -80,7 +80,7 @@ export class RecipeDetailComponent implements OnInit, AfterViewInit { }); // Setup Product Autocomplete this.products = this.form.controls.product.valueChanges.pipe( - map((x) => (x instanceof ProductSku ? x.name : x)), + map((x) => ((x as ProductSku).name !== undefined ? (x as ProductSku).name : (x as string))), map((x) => (x !== null && x.length >= 1 ? x : null)), debounceTime(150), distinctUntilChanged(), 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 8c8f0fb6..17fb363e 100644 --- a/overlord/src/app/role/role-detail/role-detail.component.ts +++ b/overlord/src/app/role/role-detail/role-detail.component.ts @@ -42,9 +42,10 @@ export class RoleDetailComponent implements OnInit, AfterViewInit { ngOnInit() { this.route.data.subscribe((value) => { const data = value as { item: Role }; - this.item = data.item; + this.form.controls.name.setValue(this.item.name); + this.form.controls.permissions.reset(); this.item.permissions.forEach((x) => this.form.controls.permissions.push( new FormGroup({ diff --git a/overlord/src/app/shared/cookie.service.ts b/overlord/src/app/shared/cookie.service.ts index 8faac0da..dab5946f 100644 --- a/overlord/src/app/shared/cookie.service.ts +++ b/overlord/src/app/shared/cookie.service.ts @@ -4,7 +4,6 @@ import { Injectable } from '@angular/core'; providedIn: 'root', }) export class CookieService { - // eslint-disable-next-line class-methods-use-this public getCookie(name: string) { const ca: Array<string> = document.cookie.split(';'); const caLen: number = ca.length; @@ -24,7 +23,6 @@ export class CookieService { this.setCookie(name, '', -1); } - // eslint-disable-next-line class-methods-use-this public setCookie(name: string, value: string, expireDays: number, path: string = '') { const d: Date = new Date(); d.setTime(d.getTime() + expireDays * 24 * 60 * 60 * 1000); diff --git a/overlord/src/app/shared/image.service.ts b/overlord/src/app/shared/image.service.ts index c9f61354..8e10a114 100644 --- a/overlord/src/app/shared/image.service.ts +++ b/overlord/src/app/shared/image.service.ts @@ -9,7 +9,6 @@ import { Voucher } from '../core/voucher'; providedIn: 'root', }) export class ImageService { - // eslint-disable-next-line class-methods-use-this resizeImage(image: string, maxWidth: number, maxHeight: number) { const canvas = document.createElement('canvas'); const ctx = canvas.getContext('2d') as CanvasRenderingContext2D; diff --git a/overlord/src/app/shared/to-csv.service.ts b/overlord/src/app/shared/to-csv.service.ts index 01654fbb..cdf8a2b2 100644 --- a/overlord/src/app/shared/to-csv.service.ts +++ b/overlord/src/app/shared/to-csv.service.ts @@ -6,7 +6,6 @@ import { ToCsvType } from './to-csv-type'; providedIn: 'root', }) export class ToCsvService { - // eslint-disable-next-line class-methods-use-this toCsv(headers: { [display: string]: string }, data: unknown[]): string { const header = Object.keys(headers); const replacer = (key: string, value: string | number | null) => (value === null ? '' : value);