Instanceof operator was not working so changed the way of checking it

This commit is contained in:
Amritanshu Agrawal 2022-07-17 08:17:13 +05:30
parent 4072733dfe
commit dbdd00119a
27 changed files with 36 additions and 44 deletions

@ -9,14 +9,16 @@
tasks: tasks:
- name: Copy dockerfile - name: Copy dockerfile
synchronize: src=app dest=/tmp synchronize:
src: app
dest: "/tmp/{{ host_directory }}"
- name: Build brewman image - name: Build brewman image
docker_image: docker_image:
name: brewman:latest name: brewman:latest
build: build:
path: /tmp/app/ path: "/tmp/{{ host_directory }}/"
dockerfile: /tmp/app/Dockerfile dockerfile: "/tmp/{{ host_directory }}/Dockerfile"
pull: yes pull: yes
state: present state: present
source: build source: build

@ -56,6 +56,9 @@
"newlines-between": "always" "newlines-between": "always"
} }
], ],
"@typescript-eslint/no-explicit-any": [
"error"
],
"unused-imports/no-unused-imports": "error" "unused-imports/no-unused-imports": "error"
} }
}, },

@ -20,7 +20,7 @@ export class AccountDetailComponent implements OnInit, AfterViewInit {
form: FormGroup<{ form: FormGroup<{
code: FormControl<number | string>; code: FormControl<number | string>;
name: FormControl<string | null>; name: FormControl<string | null>;
type: FormControl<any>; type: FormControl<number>;
isActive: FormControl<boolean>; isActive: FormControl<boolean>;
isReconcilable: FormControl<boolean>; isReconcilable: FormControl<boolean>;
costCentre: FormControl<string | null>; costCentre: FormControl<string | null>;
@ -40,7 +40,7 @@ export class AccountDetailComponent implements OnInit, AfterViewInit {
this.form = new FormGroup({ this.form = new FormGroup({
code: new FormControl<string | number>({ value: 0, disabled: true }, { nonNullable: true }), code: new FormControl<string | number>({ value: 0, disabled: true }, { nonNullable: true }),
name: new FormControl<string | null>(null), name: new FormControl<string | null>(null),
type: new FormControl<any>(''), type: new FormControl<number>(0, { nonNullable: true }),
isActive: new FormControl<boolean>(true, { nonNullable: true }), isActive: new FormControl<boolean>(true, { nonNullable: true }),
isReconcilable: new FormControl<boolean>(false, { nonNullable: true }), isReconcilable: new FormControl<boolean>(false, { nonNullable: true }),
costCentre: new FormControl<string | null>(null), costCentre: new FormControl<string | null>(null),
@ -121,7 +121,7 @@ export class AccountDetailComponent implements OnInit, AfterViewInit {
getItem(): Account { getItem(): Account {
const formModel = this.form.value; const formModel = this.form.value;
this.item.name = formModel.name!; this.item.name = formModel.name!;
this.item.type = formModel.type; this.item.type = formModel.type!;
this.item.isActive = formModel.isActive!; this.item.isActive = formModel.isActive!;
this.item.isReconcilable = formModel.isReconcilable!; this.item.isReconcilable = formModel.isReconcilable!;
this.item.costCentre.id = formModel.costCentre!; this.item.costCentre.id = formModel.costCentre!;

@ -6,7 +6,6 @@ import { merge, Observable, of as observableOf } from 'rxjs';
import { map, tap } from 'rxjs/operators'; import { map, tap } from 'rxjs/operators';
import { Account } from '../../core/account'; import { Account } from '../../core/account';
import { AccountType } from '../../core/account-type';
/** Simple sort comparator for example ID/Name columns (for client-side sorting). */ /** Simple sort comparator for example ID/Name columns (for client-side sorting). */
const compare = (a: string | number | boolean, b: string | number | boolean, isAsc: boolean) => const compare = (a: string | number | boolean, b: string | number | boolean, isAsc: boolean) =>
@ -92,7 +91,7 @@ export class AccountListDataSource extends DataSource<Account> {
case 'name': case 'name':
return compare(a.name, b.name, isAsc); return compare(a.name, b.name, isAsc);
case 'type': case 'type':
return compare((a.type as AccountType).name, (b.type as AccountType).name, isAsc); return compare(a.typeName, b.typeName, isAsc);
case 'isActive': case 'isActive':
return compare(a.isActive, b.isActive, isAsc); return compare(a.isActive, b.isActive, isAsc);
case 'isReconcilable': case 'isReconcilable':

@ -42,7 +42,7 @@
<!-- Type Column --> <!-- Type Column -->
<ng-container matColumnDef="type"> <ng-container matColumnDef="type">
<mat-header-cell *matHeaderCellDef mat-sort-header>Type</mat-header-cell> <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> </ng-container>
<!-- Is Active? Column --> <!-- Is Active? Column -->

@ -50,10 +50,7 @@ export class AccountListComponent implements OnInit, AfterViewInit {
const data = value as { list: Account[]; accountTypes: AccountType[] }; const data = value as { list: Account[]; accountTypes: AccountType[] };
this.accountTypes = data.accountTypes; this.accountTypes = data.accountTypes;
data.list.forEach( data.list.forEach(
(x) => (x) => (x.typeName = this.accountTypes.find((y) => y.id === x.type)?.name!),
(x.type = new AccountType({
name: this.accountTypes.find((y) => y.id === x.type)?.name,
})),
); );
this.list = data.list; this.list = data.list;
}); });

@ -124,7 +124,6 @@ export class ClosingStockComponent implements OnInit {
? undefined ? undefined
: new CostCentre({ id: array.controls[index].value.costCentre }); : new CostCentre({ id: array.controls[index].value.costCentre });
}); });
console.log('getClosingStock', this.info);
return this.info; return this.info;
} }

@ -1,11 +1,11 @@
import { AccountType } from './account-type';
import { CostCentre } from './cost-centre'; import { CostCentre } from './cost-centre';
export class Account { export class Account {
id: string | undefined; id: string | undefined;
code: number; code: number;
name: string; name: string;
type: AccountType | number; type: number;
typeName: string;
isActive: boolean; isActive: boolean;
isReconcilable: boolean; isReconcilable: boolean;
isStarred: boolean; isStarred: boolean;
@ -15,7 +15,8 @@ export class Account {
public constructor(init?: Partial<Account>) { public constructor(init?: Partial<Account>) {
this.code = 0; this.code = 0;
this.name = ''; this.name = '';
this.type = new AccountType(); this.type = 0;
this.typeName = '';
this.isActive = true; this.isActive = true;
this.isReconcilable = false; this.isReconcilable = false;
this.isStarred = false; this.isStarred = false;

@ -7,7 +7,6 @@ import { Observable } from 'rxjs/internal/Observable';
}) })
export class ErrorLoggerService { export class ErrorLoggerService {
public static log(serviceName = 'error-logger', message: string) { public static log(serviceName = 'error-logger', message: string) {
// eslint-disable-next-line no-console
console.log(`${serviceName}Service: ${message}`); console.log(`${serviceName}Service: ${message}`);
} }
@ -18,7 +17,6 @@ export class ErrorLoggerService {
* @param operation - name of the operation that failed * @param operation - name of the operation that failed
* @param result - optional value to return as the observable result * @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) { public handleError<T>(serviceName = 'error-logger', operation = 'operation', result?: T) {
return (error: unknown): Observable<T> => { return (error: unknown): Observable<T> => {
ErrorLoggerService.log(serviceName, `${operation} failed: ${error}`); ErrorLoggerService.log(serviceName, `${operation} failed: ${error}`);

@ -22,7 +22,6 @@ export class JwtInterceptor implements HttpInterceptor {
} }
const currentUser = this.authService.user; const currentUser = this.authService.user;
if (currentUser?.access_token) { if (currentUser?.access_token) {
// eslint-disable-next-line no-param-reassign
request = request.clone({ request = request.clone({
setHeaders: { setHeaders: {
Authorization: `Bearer ${currentUser.access_token}`, Authorization: `Bearer ${currentUser.access_token}`,

@ -41,7 +41,6 @@ export class VoucherService {
const endpoint = type.replace(/ /g, '-').toLowerCase(); const endpoint = type.replace(/ /g, '-').toLowerCase();
let options = {}; let options = {};
if (account !== undefined && account !== null) { if (account !== undefined && account !== null) {
// eslint-disable-next-line @typescript-eslint/dot-notation
options = { params: new HttpParams().set('a', account) }; options = { params: new HttpParams().set('a', account) };
} }
return this.http return this.http

@ -65,7 +65,7 @@ export class EmployeeAttendanceComponent implements OnInit, AfterViewInit {
}); });
// Listen to Employee Value Changes // Listen to Employee Value Changes
this.employees = this.form.controls.employee.valueChanges.pipe( 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)), map((x) => (x !== null && x.length >= 1 ? x : null)),
debounceTime(150), debounceTime(150),
distinctUntilChanged(), distinctUntilChanged(),

@ -116,7 +116,6 @@ export class EntriesComponent implements OnInit {
} }
togglePosted($event: MatRadioChange) { togglePosted($event: MatRadioChange) {
console.log($event.value);
this.posted = $event.value; this.posted = $event.value;
if (this.posted === false) { if (this.posted === false) {
this.issue = false; this.issue = false;

@ -36,7 +36,7 @@ export class IssueDialogComponent implements OnInit {
}); });
// Listen to Batch Autocomplete Change // Listen to Batch Autocomplete Change
this.batches = this.form.controls.batch.valueChanges.pipe( 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 : '')), map((x) => (x !== null && x.length >= 1 ? x : '')),
debounceTime(150), debounceTime(150),
distinctUntilChanged(), distinctUntilChanged(),

@ -85,7 +85,7 @@ export class IssueComponent implements OnInit, AfterViewInit, OnDestroy {
}); });
// Listen to Batch Autocomplete Change // Listen to Batch Autocomplete Change
this.batches = this.form.controls.addRow.controls.batch.valueChanges.pipe( 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 : '')), map((x) => (x !== null && x.length >= 1 ? x : '')),
debounceTime(150), debounceTime(150),
distinctUntilChanged(), distinctUntilChanged(),

@ -56,7 +56,7 @@ export class LedgerComponent implements OnInit, AfterViewInit {
}); });
this.accounts = this.form.controls.account.valueChanges.pipe( 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)), map((x) => (x !== null && x.length >= 1 ? x : null)),
debounceTime(150), debounceTime(150),
distinctUntilChanged(), distinctUntilChanged(),

@ -71,7 +71,7 @@ export class ProductLedgerComponent implements OnInit, AfterViewInit {
}); });
this.products = this.form.controls.product.valueChanges.pipe( 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)), map((x) => (x !== null && x.length >= 1 ? x : null)),
debounceTime(150), debounceTime(150),
distinctUntilChanged(), distinctUntilChanged(),

@ -36,7 +36,7 @@ export class PurchaseReturnDialogComponent implements OnInit {
}); });
// Listen to Batch Autocomplete Change // Listen to Batch Autocomplete Change
this.batches = this.form.controls.batch.valueChanges.pipe( 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 : '')), map((x) => (x !== null && x.length >= 1 ? x : '')),
debounceTime(150), debounceTime(150),
distinctUntilChanged(), distinctUntilChanged(),

@ -85,7 +85,7 @@ export class PurchaseReturnComponent implements OnInit, AfterViewInit, OnDestroy
}); });
// Listen to Account Autocomplete Change // Listen to Account Autocomplete Change
this.accounts = this.form.controls.account.valueChanges.pipe( 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)), map((x) => (x !== null && x.length >= 1 ? x : null)),
debounceTime(150), debounceTime(150),
distinctUntilChanged(), distinctUntilChanged(),
@ -93,7 +93,7 @@ export class PurchaseReturnComponent implements OnInit, AfterViewInit, OnDestroy
); );
// Listen to Batch Autocomplete Change // Listen to Batch Autocomplete Change
this.batches = this.form.controls.addRow.controls.batch.valueChanges.pipe( 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 : '')), map((x) => (x !== null && x.length >= 1 ? x : '')),
debounceTime(150), debounceTime(150),
distinctUntilChanged(), distinctUntilChanged(),
@ -298,7 +298,7 @@ export class PurchaseReturnComponent implements OnInit, AfterViewInit, OnDestroy
getVoucher(): Voucher { getVoucher(): Voucher {
const formModel = this.form.value; const formModel = this.form.value;
this.voucher.date = moment(formModel.date).format('DD-MMM-YYYY'); 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.vendor = formModel.account;
} }
this.voucher.narration = formModel.narration!; this.voucher.narration = formModel.narration!;

@ -45,7 +45,7 @@ export class PurchaseDialogComponent implements OnInit {
}); });
// Listen to Product Autocomplete Change // Listen to Product Autocomplete Change
this.products = this.form.controls.product.valueChanges.pipe( 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)), map((x) => (x !== null && x.length >= 1 ? x : null)),
debounceTime(150), debounceTime(150),
distinctUntilChanged(), distinctUntilChanged(),

@ -94,7 +94,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
this.accBal = null; this.accBal = null;
// Listen to Account Autocomplete Change // Listen to Account Autocomplete Change
this.accounts = this.form.controls.account.valueChanges.pipe( 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)), map((x) => (x !== null && x.length >= 1 ? x : null)),
debounceTime(150), debounceTime(150),
distinctUntilChanged(), distinctUntilChanged(),
@ -329,7 +329,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
getVoucher(): Voucher { getVoucher(): Voucher {
const formModel = this.form.value; const formModel = this.form.value;
this.voucher.date = moment(formModel.date).format('DD-MMM-YYYY'); 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.vendor = formModel.account;
} }
this.voucher.narration = formModel.narration!; this.voucher.narration = formModel.narration!;

@ -74,8 +74,7 @@ export class RateContractDetailComponent implements OnInit, AfterViewInit {
narration: new FormControl('', { nonNullable: true }), narration: new FormControl('', { nonNullable: true }),
}); });
this.accounts = this.form.controls.account.valueChanges.pipe( 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)),
map((x) => (x !== null && x.length >= 1 ? x : null)), map((x) => (x !== null && x.length >= 1 ? x : null)),
debounceTime(150), debounceTime(150),
distinctUntilChanged(), distinctUntilChanged(),
@ -216,8 +215,8 @@ export class RateContractDetailComponent implements OnInit, AfterViewInit {
this.item.date = moment(formModel.date).format('DD-MMM-YYYY'); this.item.date = moment(formModel.date).format('DD-MMM-YYYY');
this.item.validFrom = moment(formModel.validFrom).format('DD-MMM-YYYY'); this.item.validFrom = moment(formModel.validFrom).format('DD-MMM-YYYY');
this.item.validTill = moment(formModel.validTill).format('DD-MMM-YYYY'); this.item.validTill = moment(formModel.validTill).format('DD-MMM-YYYY');
if (formModel.account instanceof Account) { if (formModel.account !== null && typeof formModel.account !== 'string') {
this.item.vendor = formModel.account; this.item.vendor = formModel.account!;
} }
this.item.narration = formModel.narration!; this.item.narration = formModel.narration!;
return this.item; return this.item;

@ -80,7 +80,7 @@ export class RecipeDetailComponent implements OnInit, AfterViewInit {
}); });
// Setup Product Autocomplete // Setup Product Autocomplete
this.products = this.form.controls.product.valueChanges.pipe( 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)), map((x) => (x !== null && x.length >= 1 ? x : null)),
debounceTime(150), debounceTime(150),
distinctUntilChanged(), distinctUntilChanged(),

@ -42,9 +42,10 @@ export class RoleDetailComponent implements OnInit, AfterViewInit {
ngOnInit() { ngOnInit() {
this.route.data.subscribe((value) => { this.route.data.subscribe((value) => {
const data = value as { item: Role }; const data = value as { item: Role };
this.item = data.item; this.item = data.item;
this.form.controls.name.setValue(this.item.name); this.form.controls.name.setValue(this.item.name);
this.form.controls.permissions.reset();
this.item.permissions.forEach((x) => this.item.permissions.forEach((x) =>
this.form.controls.permissions.push( this.form.controls.permissions.push(
new FormGroup({ new FormGroup({

@ -4,7 +4,6 @@ import { Injectable } from '@angular/core';
providedIn: 'root', providedIn: 'root',
}) })
export class CookieService { export class CookieService {
// eslint-disable-next-line class-methods-use-this
public getCookie(name: string) { public getCookie(name: string) {
const ca: Array<string> = document.cookie.split(';'); const ca: Array<string> = document.cookie.split(';');
const caLen: number = ca.length; const caLen: number = ca.length;
@ -24,7 +23,6 @@ export class CookieService {
this.setCookie(name, '', -1); this.setCookie(name, '', -1);
} }
// eslint-disable-next-line class-methods-use-this
public setCookie(name: string, value: string, expireDays: number, path: string = '') { public setCookie(name: string, value: string, expireDays: number, path: string = '') {
const d: Date = new Date(); const d: Date = new Date();
d.setTime(d.getTime() + expireDays * 24 * 60 * 60 * 1000); d.setTime(d.getTime() + expireDays * 24 * 60 * 60 * 1000);

@ -9,7 +9,6 @@ import { Voucher } from '../core/voucher';
providedIn: 'root', providedIn: 'root',
}) })
export class ImageService { export class ImageService {
// eslint-disable-next-line class-methods-use-this
resizeImage(image: string, maxWidth: number, maxHeight: number) { resizeImage(image: string, maxWidth: number, maxHeight: number) {
const canvas = document.createElement('canvas'); const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d') as CanvasRenderingContext2D; const ctx = canvas.getContext('2d') as CanvasRenderingContext2D;

@ -6,7 +6,6 @@ import { ToCsvType } from './to-csv-type';
providedIn: 'root', providedIn: 'root',
}) })
export class ToCsvService { export class ToCsvService {
// eslint-disable-next-line class-methods-use-this
toCsv(headers: { [display: string]: string }, data: unknown[]): string { toCsv(headers: { [display: string]: string }, data: unknown[]): string {
const header = Object.keys(headers); const header = Object.keys(headers);
const replacer = (key: string, value: string | number | null) => (value === null ? '' : value); const replacer = (key: string, value: string | number | null) => (value === null ? '' : value);