Switched on the @typescript-eslint/no-non-null-assertion rule in eslint.

Fixed the errors it threw up.
This commit is contained in:
Amritanshu Agrawal 2022-07-17 09:17:20 +05:30
parent c76696e022
commit 9f70ec2917
29 changed files with 144 additions and 111 deletions

View File

@ -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",

View File

@ -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;
}
}

View File

@ -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;
});

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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 ?? '' }),
});
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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);

View File

@ -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 '';

View File

@ -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;
}
}

View File

@ -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 }),

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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(),
};

View File

@ -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;
}

View File

@ -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: {

View File

@ -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;
}