From 9f70ec291744b89771fe4a696350f75b7f175d16 Mon Sep 17 00:00:00 2001 From: Amritanshu <git@tanshu.com> Date: Sun, 17 Jul 2022 09:17:20 +0530 Subject: [PATCH] Switched on the @typescript-eslint/no-non-null-assertion rule in eslint. Fixed the errors it threw up. --- overlord/.eslintrc.json | 3 +- .../account-detail.component.ts | 12 +++---- .../account-list/account-list.component.ts | 2 +- .../app/attendance/attendance.component.ts | 10 +++--- .../client-detail/client-detail.component.ts | 4 +-- .../closing-stock/closing-stock.component.ts | 4 +-- .../cost-centre-detail.component.ts | 2 +- .../employee-attendance.component.ts | 10 +++--- .../employee-benefits.component.ts | 11 ++++--- .../employee-functions.component.ts | 18 ++++++----- .../employee-detail.component.ts | 20 ++++++------ overlord/src/app/entries/entries.component.ts | 2 +- .../src/app/incentive/incentive.component.ts | 4 +-- overlord/src/app/issue/issue.component.ts | 15 +++++---- .../app/journal/journal-dialog.component.ts | 2 +- overlord/src/app/journal/journal.component.ts | 9 ++++-- overlord/src/app/payment/payment.component.ts | 6 ++-- .../product-group-detail.component.ts | 2 +- .../product-detail-dialog.component.ts | 10 +++--- .../product-detail.component.ts | 31 ++++++++++--------- .../purchase-return.component.ts | 7 +++-- .../src/app/purchase/purchase.component.ts | 7 +++-- .../rate-contract-detail.component.ts | 11 ++++--- overlord/src/app/receipt/receipt.component.ts | 6 ++-- .../recipe-detail/recipe-detail.component.ts | 13 +++++--- overlord/src/app/recipe/recipe.service.ts | 2 +- .../role/role-detail/role-detail.component.ts | 4 +-- .../src/app/settings/settings.component.ts | 20 ++++++------ .../user/user-detail/user-detail.component.ts | 8 ++--- 29 files changed, 144 insertions(+), 111 deletions(-) diff --git a/overlord/.eslintrc.json b/overlord/.eslintrc.json index aa476315..1685e316 100644 --- a/overlord/.eslintrc.json +++ b/overlord/.eslintrc.json @@ -16,7 +16,8 @@ }, "extends": [ "plugin:@angular-eslint/recommended", - "plugin:@angular-eslint/template/process-inline-templates" + "plugin:@angular-eslint/template/process-inline-templates", + "plugin:@angular-eslint/recommended--extra" ], "plugins": [ "import", 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 1c20f18f..46f1edd5 100644 --- a/overlord/src/app/account/account-detail/account-detail.component.ts +++ b/overlord/src/app/account/account-detail/account-detail.component.ts @@ -69,7 +69,7 @@ export class AccountDetailComponent implements OnInit, AfterViewInit { type: this.item.type, isActive: this.item.isActive, isReconcilable: this.item.isReconcilable, - costCentre: this.item.costCentre.id!, + costCentre: this.item.costCentre.id ?? '', }); } @@ -120,11 +120,11 @@ 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.isActive = formModel.isActive!; - this.item.isReconcilable = formModel.isReconcilable!; - this.item.costCentre.id = formModel.costCentre!; + this.item.name = formModel.name ?? ''; + this.item.type = formModel.type ?? 0; + this.item.isActive = formModel.isActive ?? true; + this.item.isReconcilable = formModel.isReconcilable ?? false; + this.item.costCentre.id = formModel.costCentre ?? ''; return this.item; } } 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 41ed9398..16701eff 100644 --- a/overlord/src/app/account/account-list/account-list.component.ts +++ b/overlord/src/app/account/account-list/account-list.component.ts @@ -50,7 +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.typeName = 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/attendance/attendance.component.ts b/overlord/src/app/attendance/attendance.component.ts index 2ba8580a..233b30c2 100644 --- a/overlord/src/app/attendance/attendance.component.ts +++ b/overlord/src/app/attendance/attendance.component.ts @@ -96,10 +96,12 @@ export class AttendanceComponent implements OnInit { getAttendance(): Attendance { const formModel = this.form.value; this.info.date = moment(formModel.date).format('DD-MMM-YYYY'); - const array = this.form.controls.attendances!; - this.info.body.forEach((item, index) => { - item.attendanceType.id = array.controls[index].value.attendanceType!; - }); + const array = this.form.controls.attendances; + if (array) { + this.info.body.forEach((item, index) => { + item.attendanceType.id = array.controls[index].value.attendanceType ?? 0; + }); + } return this.info; } } 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 c2237cd6..ec310a8c 100644 --- a/overlord/src/app/client/client-detail/client-detail.component.ts +++ b/overlord/src/app/client/client-detail/client-detail.component.ts @@ -107,8 +107,8 @@ export class ClientDetailComponent implements OnInit, AfterViewInit { getItem(): Client { const formModel = this.form.value; - this.item.name = formModel.name!; - this.item.enabled = formModel.enabled!; + this.item.name = formModel.name ?? ''; + this.item.enabled = formModel.enabled ?? false; this.item.otp = formModel.otp || undefined; return this.item; } diff --git a/overlord/src/app/closing-stock/closing-stock.component.ts b/overlord/src/app/closing-stock/closing-stock.component.ts index f8b72c32..2e97d041 100644 --- a/overlord/src/app/closing-stock/closing-stock.component.ts +++ b/overlord/src/app/closing-stock/closing-stock.component.ts @@ -118,7 +118,7 @@ export class ClosingStockComponent implements OnInit { this.info.date = moment(formModel.date).format('DD-MMM-YYYY'); const array = this.form.controls.stocks; this.info.items.forEach((item, index) => { - item.physical = +array.controls[index].value.physical!; + item.physical = +(array.controls[index].value.physical ?? ''); item.costCentre = array.controls[index].value.costCentre == null ? undefined @@ -132,7 +132,7 @@ export class ClosingStockComponent implements OnInit { return new ClosingStock({ date: moment(formModel.date).format('DD-MMM-YYYY'), - costCentre: new CostCentre({ id: formModel.costCentre! }), + costCentre: new CostCentre({ id: formModel.costCentre ?? '' }), }); } 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 59536631..e5485901 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 @@ -67,7 +67,7 @@ export class CostCentreDetailComponent implements OnInit, AfterViewInit { getItem(): CostCentre { const formModel = this.form.value; - this.item.name = formModel.name!; + this.item.name = formModel.name ?? ''; return this.item; } } diff --git a/overlord/src/app/employee-attendance/employee-attendance.component.ts b/overlord/src/app/employee-attendance/employee-attendance.component.ts index 88baa2e5..0868e047 100644 --- a/overlord/src/app/employee-attendance/employee-attendance.component.ts +++ b/overlord/src/app/employee-attendance/employee-attendance.component.ts @@ -145,10 +145,12 @@ export class EmployeeAttendanceComponent implements OnInit, AfterViewInit { const formValue = this.form.value; this.info.startDate = moment(formValue.startDate).format('DD-MMM-YYYY'); this.info.finishDate = moment(formValue.finishDate).format('DD-MMM-YYYY'); - const array = this.form.value.attendances!; - this.info.body.forEach((item, index) => { - item.attendanceType.id = array[index].attendanceType!; - }); + const array = this.form.value.attendances; + if (array) { + this.info.body.forEach((item, index) => { + item.attendanceType.id = array[index].attendanceType ?? 0; + }); + } return this.info; } } diff --git a/overlord/src/app/employee-benefits/employee-benefits.component.ts b/overlord/src/app/employee-benefits/employee-benefits.component.ts index 15b027d7..bf667fde 100644 --- a/overlord/src/app/employee-benefits/employee-benefits.component.ts +++ b/overlord/src/app/employee-benefits/employee-benefits.component.ts @@ -151,10 +151,13 @@ export class EmployeeBenefitsComponent implements OnInit, AfterViewInit { return; } - const formValue = this.form.value.addRow!; - const grossSalary = +formValue.grossSalary!; - const daysWorked = +formValue.daysWorked!; - const date = this.form.value.date!; + const formValue = this.form.value.addRow; + if (formValue === undefined) { + return; + } + const grossSalary = +(formValue.grossSalary ?? '0'); + const daysWorked = +(formValue.daysWorked ?? '0'); + const date = this.form.value.date ?? new Date(); const daysInMonth = moment(date).daysInMonth(); const esi = EmployeeBenefitsComponent.getEsi(grossSalary, daysWorked, daysInMonth); const pf = EmployeeBenefitsComponent.getPf(grossSalary, daysWorked, daysInMonth); diff --git a/overlord/src/app/employee-functions/employee-functions.component.ts b/overlord/src/app/employee-functions/employee-functions.component.ts index d7357b88..d0b4a532 100644 --- a/overlord/src/app/employee-functions/employee-functions.component.ts +++ b/overlord/src/app/employee-functions/employee-functions.component.ts @@ -50,14 +50,14 @@ export class EmployeeFunctionsComponent { } chosenYearHandler(normalizedYear: Moment) { - const ctrlValue = this.creditSalaryForm.value.date!; + const ctrlValue = this.creditSalaryForm.value.date ?? moment(); ctrlValue.year(normalizedYear.year()); ctrlValue.date(ctrlValue.daysInMonth()); this.creditSalaryForm.setValue({ date: ctrlValue }); } chosenMonthHandler(normlizedMonth: Moment, datepicker: MatDatepicker<Moment>) { - const ctrlValue = this.creditSalaryForm.value.date!; + const ctrlValue = this.creditSalaryForm.value.date ?? moment(); ctrlValue.month(normlizedMonth.month()); ctrlValue.date(ctrlValue.daysInMonth()); this.creditSalaryForm.setValue({ date: ctrlValue }); @@ -65,7 +65,7 @@ export class EmployeeFunctionsComponent { } creditSalary() { - const date = this.creditSalaryForm.value.date!.format('DD-MMM-YYYY'); + const date = (this.creditSalaryForm.value.date ?? moment()).format('DD-MMM-YYYY'); if (!date) { this.toaster.show('Danger', 'Please choose a valid date.'); return; @@ -81,8 +81,10 @@ export class EmployeeFunctionsComponent { } attendanceRecordUrl() { - const startDate = this.attendanceRecordForm.value.startDate!.format('DD-MMM-YYYY'); - const finishDate = this.attendanceRecordForm.value.finishDate!.format('DD-MMM-YYYY'); + const startDate = (this.attendanceRecordForm.value.startDate ?? moment()).format('DD-MMM-YYYY'); + const finishDate = (this.attendanceRecordForm.value.finishDate ?? moment()).format( + 'DD-MMM-YYYY', + ); if (!startDate || !finishDate) { // this.toaster.show('Danger', 'Please choose a start and finish date.'); return ''; @@ -91,8 +93,10 @@ export class EmployeeFunctionsComponent { } fingerPrintUrl() { - const startDate = this.attendanceRecordForm.value.startDate!.format('DD-MMM-YYYY'); - const finishDate = this.attendanceRecordForm.value.finishDate!.format('DD-MMM-YYYY'); + const startDate = (this.attendanceRecordForm.value.startDate ?? moment()).format('DD-MMM-YYYY'); + const finishDate = (this.attendanceRecordForm.value.finishDate ?? moment()).format( + 'DD-MMM-YYYY', + ); if (!startDate || !finishDate) { // this.toaster.show('Danger', 'Please choose a start and finish date.'); return ''; 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 17a2ed50..1b07fa51 100644 --- a/overlord/src/app/employee/employee-detail/employee-detail.component.ts +++ b/overlord/src/app/employee/employee-detail/employee-detail.component.ts @@ -74,7 +74,7 @@ export class EmployeeDetailComponent implements OnInit, AfterViewInit { salary: this.item.salary || '', points: this.item.points || '', isActive: this.item.isActive, - costCentre: this.item.costCentre.id!, + costCentre: this.item.costCentre.id ?? '', joiningDate: this.item.joiningDate ? moment(this.item.joiningDate, 'DD-MMM-YYYY').toDate() : new Date(), @@ -130,17 +130,17 @@ export class EmployeeDetailComponent implements OnInit, AfterViewInit { } getItem(): Employee { - const formModel = this.form.value; - this.item.name = formModel.name!; - this.item.designation = formModel.designation!; - this.item.salary = +formModel.salary!; - this.item.points = +formModel.points!; - this.item.isActive = formModel.isActive!; - this.item.costCentre.id = formModel.costCentre!; - this.item.joiningDate = moment(formModel.joiningDate).format('DD-MMM-YYYY'); + const formValue = this.form.value; + this.item.name = formValue.name ?? ''; + this.item.designation = formValue.designation ?? ''; + this.item.salary = +(formValue.salary ?? '0'); + this.item.points = +(formValue.points ?? '0'); + this.item.isActive = formValue.isActive ?? true; + this.item.costCentre.id = formValue.costCentre ?? ''; + this.item.joiningDate = moment(formValue.joiningDate).format('DD-MMM-YYYY'); this.item.leavingDate = this.item.isActive ? null - : moment(formModel.leavingDate).format('DD-MMM-YYYY'); + : moment(formValue.leavingDate).format('DD-MMM-YYYY'); return this.item; } } diff --git a/overlord/src/app/entries/entries.component.ts b/overlord/src/app/entries/entries.component.ts index 95b0ef3a..7f29287c 100644 --- a/overlord/src/app/entries/entries.component.ts +++ b/overlord/src/app/entries/entries.component.ts @@ -37,7 +37,7 @@ export class EntriesComponent implements OnInit { ]; posted: boolean | null = null; - issue: boolean = false; + issue = false; constructor(private route: ActivatedRoute, private router: Router) { this.form = new FormGroup({ startDate: new FormControl(new Date(), { nonNullable: true }), diff --git a/overlord/src/app/incentive/incentive.component.ts b/overlord/src/app/incentive/incentive.component.ts index 21319f93..53f4c4af 100644 --- a/overlord/src/app/incentive/incentive.component.ts +++ b/overlord/src/app/incentive/incentive.component.ts @@ -108,7 +108,7 @@ export class IncentiveComponent implements OnInit { } change(row: Incentive, i: number) { - row.points = this.form.controls.incentives.controls[i].value.points!; + row.points = this.form.controls.incentives.controls[i].value.points ?? 0; this.form.controls.incentives.controls[i].setValue({ points: row.points }); } @@ -168,7 +168,7 @@ export class IncentiveComponent implements OnInit { const array = this.form.controls.incentives; this.voucher.incentives.forEach((item, index) => { - item.points = array.controls[index].value.points!; + item.points = array.controls[index].value.points ?? 0; }); return this.voucher; } diff --git a/overlord/src/app/issue/issue.component.ts b/overlord/src/app/issue/issue.component.ts index 75b9cf85..944c8711 100644 --- a/overlord/src/app/issue/issue.component.ts +++ b/overlord/src/app/issue/issue.component.ts @@ -147,8 +147,8 @@ export class IssueComponent implements OnInit, AfterViewInit, OnDestroy { this.voucher = voucher; this.form.setValue({ date: moment(this.voucher.date, 'DD-MMM-YYYY').toDate(), - source: (this.voucher.source as CostCentre).id!, - destination: (this.voucher.destination as CostCentre).id!, + source: (this.voucher.source as CostCentre).id ?? '', + destination: (this.voucher.destination as CostCentre).id ?? '', amount: Math.abs(this.voucher.inventories.map((x) => x.amount).reduce((p, c) => p + c, 0)), addRow: { batch: '', @@ -169,7 +169,10 @@ export class IssueComponent implements OnInit, AfterViewInit, OnDestroy { } addRow() { - const formValue = this.form.value.addRow!; + const formValue = this.form.value.addRow; + if (formValue === undefined) { + return; + } const quantity = this.math.parseAmount(formValue.quantity, 2); const isConsumption = this.form.value.source === '7b845f95-dfef-fa4a-897c-f0baf15284a3'; if (this.batch === null || quantity <= 0) { @@ -288,9 +291,9 @@ export class IssueComponent implements OnInit, AfterViewInit, OnDestroy { getVoucher(): Voucher { const formModel = this.form.value; this.voucher.date = moment(formModel.date).format('DD-MMM-YYYY'); - (this.voucher.source as CostCentre).id = formModel.source!; - (this.voucher.destination as CostCentre).id = formModel.destination!; - this.voucher.narration = formModel.narration!; + (this.voucher.source as CostCentre).id = formModel.source ?? ''; + (this.voucher.destination as CostCentre).id = formModel.destination ?? ''; + this.voucher.narration = formModel.narration ?? ''; return this.voucher; } diff --git a/overlord/src/app/journal/journal-dialog.component.ts b/overlord/src/app/journal/journal-dialog.component.ts index 6080314b..cb8d4338 100644 --- a/overlord/src/app/journal/journal-dialog.component.ts +++ b/overlord/src/app/journal/journal-dialog.component.ts @@ -71,7 +71,7 @@ export class JournalDialogComponent implements OnInit { accept(): void { const formValue = this.form.value; - const amount = this.math.journalAmount(formValue.amount, formValue.debit!); + const amount = this.math.journalAmount(formValue.amount, formValue.debit ?? 1); this.data.journal.debit = amount.debit; this.data.journal.account = this.account; this.data.journal.amount = amount.amount; diff --git a/overlord/src/app/journal/journal.component.ts b/overlord/src/app/journal/journal.component.ts index b1bb8859..50524280 100644 --- a/overlord/src/app/journal/journal.component.ts +++ b/overlord/src/app/journal/journal.component.ts @@ -165,8 +165,11 @@ export class JournalComponent implements OnInit, AfterViewInit, OnDestroy { } addRow() { - const formValue = this.form.value.addRow!; - const amount = this.math.journalAmount(formValue.amount!, formValue.debit!); + const formValue = this.form.value.addRow; + if (formValue === undefined) { + return; + } + const amount = this.math.journalAmount(formValue.amount, formValue.debit ?? 1); if (this.account === null || amount.amount === 0) { return; } @@ -292,7 +295,7 @@ export class JournalComponent implements OnInit, AfterViewInit, OnDestroy { getVoucher(): Voucher { const formModel = this.form.value; this.voucher.date = moment(formModel.date).format('DD-MMM-YYYY'); - this.voucher.narration = formModel.narration!; + this.voucher.narration = formModel.narration ?? ''; return this.voucher; } diff --git a/overlord/src/app/payment/payment.component.ts b/overlord/src/app/payment/payment.component.ts index bef887cf..ce69ba32 100644 --- a/overlord/src/app/payment/payment.component.ts +++ b/overlord/src/app/payment/payment.component.ts @@ -159,7 +159,7 @@ export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy { [this.paymentJournal] = this.voucher.journals.filter((x) => x.debit === -1); this.form.setValue({ date: moment(this.voucher.date, 'DD-MMM-YYYY').toDate(), - paymentAccount: this.paymentJournal.account.id!, + paymentAccount: this.paymentJournal.account.id ?? '', paymentAmount: this.paymentJournal.amount, addRow: { account: '', @@ -180,7 +180,7 @@ export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy { } addRow() { - const amount = this.math.parseAmount(this.form.value.addRow?.amount!, 2); + const amount = this.math.parseAmount(this.form.value.addRow?.amount ?? '0', 2); const debit = 1; if (this.account === null || amount <= 0) { return; @@ -305,7 +305,7 @@ export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy { const formModel = this.form.value; this.voucher.date = moment(formModel.date).format('DD-MMM-YYYY'); this.paymentJournal.account.id = formModel.paymentAccount; - this.voucher.narration = formModel.narration!; + this.voucher.narration = formModel.narration ?? ''; return this.voucher; } 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 ad1fab08..5a902844 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 @@ -67,7 +67,7 @@ export class ProductGroupDetailComponent implements OnInit, AfterViewInit { getItem(): ProductGroup { const formModel = this.form.value; - this.item.name = formModel.name!; + this.item.name = formModel.name ?? ''; return this.item; } } diff --git a/overlord/src/app/product/product-detail/product-detail-dialog.component.ts b/overlord/src/app/product/product-detail/product-detail-dialog.component.ts index 3786648e..af34ea1a 100644 --- a/overlord/src/app/product/product-detail/product-detail-dialog.component.ts +++ b/overlord/src/app/product/product-detail/product-detail-dialog.component.ts @@ -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; 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 71a3bf55..885ef8e3 100644 --- a/overlord/src/app/product/product-detail/product-detail.component.ts +++ b/overlord/src/app/product/product-detail/product-detail.component.ts @@ -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; } } diff --git a/overlord/src/app/purchase-return/purchase-return.component.ts b/overlord/src/app/purchase-return/purchase-return.component.ts index b265f469..9b7e00ab 100644 --- a/overlord/src/app/purchase-return/purchase-return.component.ts +++ b/overlord/src/app/purchase-return/purchase-return.component.ts @@ -182,7 +182,10 @@ export class PurchaseReturnComponent implements OnInit, AfterViewInit, OnDestroy } addRow() { - const formValue = this.form.value.addRow!; + const formValue = this.form.value.addRow; + if (formValue === undefined) { + return; + } const quantity = this.math.parseAmount(formValue.quantity, 2); if (this.batch === null || quantity <= 0 || this.batch.quantityRemaining < quantity) { return; @@ -301,7 +304,7 @@ export class PurchaseReturnComponent implements OnInit, AfterViewInit, OnDestroy if (formModel.account !== null && typeof formModel.account !== 'string') { this.voucher.vendor = formModel.account; } - this.voucher.narration = formModel.narration!; + this.voucher.narration = formModel.narration ?? ''; return this.voucher; } diff --git a/overlord/src/app/purchase/purchase.component.ts b/overlord/src/app/purchase/purchase.component.ts index 64e7e539..81853488 100644 --- a/overlord/src/app/purchase/purchase.component.ts +++ b/overlord/src/app/purchase/purchase.component.ts @@ -201,7 +201,10 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy { } addRow() { - const formValue = this.form.value.addRow!; + const formValue = this.form.value.addRow; + if (formValue === undefined) { + return; + } const quantity = this.math.parseAmount(formValue.quantity, 2); if (this.product === null || quantity <= 0) { return; @@ -332,7 +335,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy { if (formModel.account !== null && typeof formModel.account !== 'string') { this.voucher.vendor = formModel.account; } - this.voucher.narration = formModel.narration!; + this.voucher.narration = formModel.narration ?? ''; return this.voucher; } 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 636c0814..21dfda61 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 @@ -122,7 +122,10 @@ export class RateContractDetailComponent implements OnInit, AfterViewInit { } addRow() { - const formValue = this.form.value.addRow!; + const formValue = this.form.value.addRow; + if (formValue === undefined) { + return; + } const price = this.math.parseAmount(formValue.price, 2); if (this.product === null || price <= 0) { return; @@ -215,10 +218,10 @@ 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 !== null && typeof formModel.account !== 'string') { - this.item.vendor = formModel.account!; + if (formModel.account && typeof formModel.account !== 'string') { + this.item.vendor = formModel.account; } - this.item.narration = formModel.narration!; + this.item.narration = formModel.narration ?? ''; return this.item; } } diff --git a/overlord/src/app/receipt/receipt.component.ts b/overlord/src/app/receipt/receipt.component.ts index 464f9666..08b8494d 100644 --- a/overlord/src/app/receipt/receipt.component.ts +++ b/overlord/src/app/receipt/receipt.component.ts @@ -158,7 +158,7 @@ export class ReceiptComponent implements OnInit, AfterViewInit, OnDestroy { [this.receiptJournal] = this.voucher.journals.filter((x) => x.debit === 1); this.form.setValue({ date: moment(this.voucher.date, 'DD-MMM-YYYY').toDate(), - receiptAccount: this.receiptJournal.account.id!, + receiptAccount: this.receiptJournal.account.id ?? '', receiptAmount: this.receiptJournal.amount, addRow: { account: '', @@ -179,7 +179,7 @@ export class ReceiptComponent implements OnInit, AfterViewInit, OnDestroy { } addRow() { - const amount = this.math.parseAmount(this.form.value.addRow?.amount!, 2); + const amount = this.math.parseAmount(this.form.value.addRow?.amount ?? '0', 2); const debit = -1; if (this.account === null || amount <= 0) { return; @@ -304,7 +304,7 @@ export class ReceiptComponent implements OnInit, AfterViewInit, OnDestroy { const formModel = this.form.value; this.voucher.date = moment(formModel.date).format('DD-MMM-YYYY'); this.receiptJournal.account.id = formModel.receiptAccount; - this.voucher.narration = formModel.narration!; + this.voucher.narration = formModel.narration ?? ''; return this.voucher; } 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 01da5c75..08917222 100644 --- a/overlord/src/app/recipe/recipe-detail/recipe-detail.component.ts +++ b/overlord/src/app/recipe/recipe-detail/recipe-detail.component.ts @@ -157,7 +157,10 @@ export class RecipeDetailComponent implements OnInit, AfterViewInit { } addRow() { - const formValue = this.form.value.addRow!; + const formValue = this.form.value.addRow; + if (formValue === undefined) { + return; + } const quantity = this.math.parseAmount(formValue.quantity, 2); const rate = this.math.parseAmount(formValue.rate, 2); if (this.ingredient === null || quantity <= 0 || rate <= 0) { @@ -198,7 +201,7 @@ export class RecipeDetailComponent implements OnInit, AfterViewInit { 2, ); this.form.controls.costPrice.setValue(`${costPrice}`); - const salePrice = this.math.parseAmount(this.form.value.salePrice!, 2); + const salePrice = this.math.parseAmount(this.form.value.salePrice ?? '0', 2); if (salePrice < 0) { return; } @@ -252,9 +255,9 @@ export class RecipeDetailComponent implements OnInit, AfterViewInit { const formModel = this.form.value; this.item.validFrom = moment(formModel.validFrom).format('DD-MMM-YYYY'); this.item.validTill = moment(formModel.validTill).format('DD-MMM-YYYY'); - this.item.recipeYield = this.math.parseAmount(formModel.recipeYield!, 2); - this.item.salePrice = this.math.parseAmount(formModel.salePrice!, 2); - this.item.costPrice = this.math.parseAmount(formModel.costPrice!, 2); + this.item.recipeYield = this.math.parseAmount(formModel.recipeYield ?? '1', 2); + this.item.salePrice = this.math.parseAmount(formModel.salePrice ?? '0', 2); + this.item.costPrice = this.math.parseAmount(formModel.costPrice ?? '0', 2); return this.item; } } diff --git a/overlord/src/app/recipe/recipe.service.ts b/overlord/src/app/recipe/recipe.service.ts index 0e0182aa..e3af4bf8 100644 --- a/overlord/src/app/recipe/recipe.service.ts +++ b/overlord/src/app/recipe/recipe.service.ts @@ -58,7 +58,7 @@ export class RecipeService { startDate: string | null, finishDate: string | null, ): Observable<ProductSku> { - const getUrl: string = `${url}/ingredient-details/${id}`; + const getUrl = `${url}/ingredient-details/${id}`; const options = { params: new HttpParams(), }; 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 17fb363e..a91f34cd 100644 --- a/overlord/src/app/role/role-detail/role-detail.component.ts +++ b/overlord/src/app/role/role-detail/role-detail.component.ts @@ -103,10 +103,10 @@ export class RoleDetailComponent implements OnInit, AfterViewInit { getItem(): Role { const formModel = this.form.value; - this.item.name = formModel.name!; + this.item.name = formModel.name ?? ''; const array = this.form.controls.permissions; this.item.permissions.forEach((item, index) => { - item.enabled = array.controls[index].value.permission!; + item.enabled = array.controls[index].value.permission ?? false; }); return this.item; } diff --git a/overlord/src/app/settings/settings.component.ts b/overlord/src/app/settings/settings.component.ts index 92aea03b..df22849d 100644 --- a/overlord/src/app/settings/settings.component.ts +++ b/overlord/src/app/settings/settings.component.ts @@ -44,10 +44,10 @@ export class SettingsComponent implements OnInit { }>; lockInformation: LockInfo[]; - lockOlder: boolean = false; - olderRolling: boolean = false; - lockNewer: boolean = false; - newerRolling: boolean = false; + lockOlder = false; + olderRolling = false; + lockNewer = false; + newerRolling = false; rebaseDataForm: FormGroup<{ date: FormControl<moment.Moment>; @@ -149,15 +149,15 @@ export class SettingsComponent implements OnInit { saveLock() { const item = new LockInfo(); if (this.lockOlder && this.olderRolling) { - item.start.days = +this.lockInfoForm.value.olderDays!; + item.start.days = this.lockInfoForm.value.olderDays ?? 0; } else if (this.lockOlder && !this.olderRolling) { - item.start.date = this.lockInfoForm.value.olderDate!.format('DD-MMM-YYYY'); + item.start.date = (this.lockInfoForm.value.olderDate ?? moment()).format('DD-MMM-YYYY'); } if (this.lockNewer && this.newerRolling) { - item.finish.days = +this.lockInfoForm.value.newerDays!; + item.finish.days = this.lockInfoForm.value.newerDays ?? 0; } if (this.lockNewer && !this.newerRolling) { - item.finish.date = this.lockInfoForm.value.newerDate!.format('DD-MMM-YYYY'); + item.finish.date = (this.lockInfoForm.value.newerDate ?? moment()).format('DD-MMM-YYYY'); } const atArray = this.lockInfoForm.controls.accountTypes; this.accountTypes.forEach((at, index) => { @@ -182,7 +182,7 @@ export class SettingsComponent implements OnInit { if (validTill) { item.validTill = moment(validTill).format('DD-MMM-YYYY'); } - item.index = +this.lockInfoForm.value.index!; + item.index = this.lockInfoForm.value.index ?? 0; this.ser.setLockInformation(item).subscribe( (result) => { @@ -202,7 +202,7 @@ export class SettingsComponent implements OnInit { } confirmRebase(): void { - const rebaseDate = this.rebaseDataForm.value.date!.format('DD-MMM-YYYY'); + const rebaseDate = (this.rebaseDataForm.value.date ?? moment()).format('DD-MMM-YYYY'); const dialogRef = this.dialog.open(ConfirmDialogComponent, { width: '250px', data: { 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 acfd4679..0b680925 100644 --- a/overlord/src/app/user/user-detail/user-detail.component.ts +++ b/overlord/src/app/user/user-detail/user-detail.component.ts @@ -126,12 +126,12 @@ export class UserDetailComponent implements OnInit, AfterViewInit { getItem(): User { const formModel = this.form.value; - this.item.name = formModel.name!; - this.item.password = formModel.password!; - this.item.lockedOut = formModel.lockedOut!; + this.item.name = formModel.name ?? ''; + this.item.password = formModel.password ?? ''; + this.item.lockedOut = formModel.lockedOut ?? true; const array = this.form.controls.roles; this.item.roles.forEach((item, index) => { - item.enabled = array.controls[index].value.role!; + item.enabled = array.controls[index].value.role ?? false; }); return this.item; }