Switched on the @typescript-eslint/no-non-null-assertion rule in eslint.
Fixed the errors it threw up.
This commit is contained in:
@ -44,23 +44,23 @@ export class ProductDetailDialogComponent implements OnInit {
|
||||
|
||||
accept(): void {
|
||||
const formValue = this.form.value;
|
||||
const fraction = formValue.fraction!;
|
||||
const fraction = formValue.fraction ?? 0;
|
||||
if (fraction < 1) {
|
||||
return;
|
||||
}
|
||||
const productYield = formValue.productYield!;
|
||||
const productYield = formValue.productYield ?? 0;
|
||||
if (productYield < 0 || productYield > 1) {
|
||||
return;
|
||||
}
|
||||
const costPrice = formValue.costPrice!;
|
||||
const costPrice = formValue.costPrice ?? 0;
|
||||
if (costPrice < 0) {
|
||||
return;
|
||||
}
|
||||
const salePrice = formValue.salePrice!;
|
||||
const salePrice = formValue.salePrice ?? 0;
|
||||
if (salePrice < 0) {
|
||||
return;
|
||||
}
|
||||
this.data.item.units = formValue.units!;
|
||||
this.data.item.units = formValue.units ?? '';
|
||||
this.data.item.fraction = fraction;
|
||||
this.data.item.productYield = productYield;
|
||||
this.data.item.costPrice = costPrice;
|
||||
|
||||
@ -85,7 +85,7 @@ export class ProductDetailComponent implements OnInit, AfterViewInit {
|
||||
this.form.setValue({
|
||||
code: this.item.code || '(Auto)',
|
||||
name: this.item.name,
|
||||
fractionUnits: this.item.fractionUnits!,
|
||||
fractionUnits: this.item.fractionUnits ?? '',
|
||||
addRow: {
|
||||
units: '',
|
||||
fraction: '',
|
||||
@ -96,7 +96,7 @@ export class ProductDetailComponent implements OnInit, AfterViewInit {
|
||||
isPurchased: this.item.isPurchased,
|
||||
isSold: this.item.isSold,
|
||||
isActive: this.item.isActive,
|
||||
productGroup: this.item.productGroup ? this.item.productGroup.id! : '',
|
||||
productGroup: this.item.productGroup ? this.item.productGroup.id ?? '' : '',
|
||||
});
|
||||
}
|
||||
|
||||
@ -109,30 +109,33 @@ export class ProductDetailComponent implements OnInit, AfterViewInit {
|
||||
}
|
||||
|
||||
addRow() {
|
||||
const formValue = this.form.value.addRow!;
|
||||
const fraction = +formValue.fraction!;
|
||||
const formValue = this.form.value.addRow;
|
||||
if (formValue === undefined) {
|
||||
return;
|
||||
}
|
||||
const fraction = +(formValue.fraction ?? '0');
|
||||
if (fraction < 1) {
|
||||
this.toaster.show('Danger', 'Fraction has to be >= 1');
|
||||
return;
|
||||
}
|
||||
const productYield = +formValue.productYield!;
|
||||
const productYield = +(formValue.productYield ?? '0');
|
||||
if (productYield < 0 || productYield > 1) {
|
||||
this.toaster.show('Danger', 'Product Yield has to be > 0 and <= 1');
|
||||
return;
|
||||
}
|
||||
const costPrice = +formValue.costPrice!;
|
||||
const costPrice = +(formValue.costPrice ?? '0');
|
||||
if (costPrice < 0) {
|
||||
this.toaster.show('Danger', 'Price has to be >= 0');
|
||||
return;
|
||||
}
|
||||
const salePrice = +formValue.salePrice!;
|
||||
const salePrice = +(formValue.salePrice ?? '0');
|
||||
if (salePrice < 0) {
|
||||
this.toaster.show('Danger', 'Sale Price has to be >= 0');
|
||||
return;
|
||||
}
|
||||
this.item.skus.push(
|
||||
new StockKeepingUnit({
|
||||
units: formValue.units!,
|
||||
units: formValue.units ?? '',
|
||||
fraction,
|
||||
productYield,
|
||||
costPrice,
|
||||
@ -212,15 +215,15 @@ export class ProductDetailComponent implements OnInit, AfterViewInit {
|
||||
|
||||
getItem(): Product {
|
||||
const formModel = this.form.value;
|
||||
this.item.name = formModel.name!;
|
||||
this.item.fractionUnits = formModel.fractionUnits!;
|
||||
this.item.isPurchased = formModel.isPurchased!;
|
||||
this.item.isSold = formModel.isSold!;
|
||||
this.item.isActive = formModel.isActive!;
|
||||
this.item.name = formModel.name ?? '';
|
||||
this.item.fractionUnits = formModel.fractionUnits ?? '';
|
||||
this.item.isPurchased = formModel.isPurchased ?? true;
|
||||
this.item.isSold = formModel.isSold ?? false;
|
||||
this.item.isActive = formModel.isActive ?? true;
|
||||
if (this.item.productGroup === null || this.item.productGroup === undefined) {
|
||||
this.item.productGroup = new ProductGroup();
|
||||
}
|
||||
this.item.productGroup.id = formModel.productGroup!;
|
||||
this.item.productGroup.id = formModel.productGroup ?? '';
|
||||
return this.item;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user