build: Use prettier for typescript

Stop ignoring .ts files in prettier and fix existing issues.
This commit is contained in:
Ralph Hopman
2025-01-15 11:59:30 +00:00
committed by Adam Saghy
parent 9d6cf1514a
commit cac1d11ad7
1812 changed files with 22516 additions and 16862 deletions
@@ -13,7 +13,6 @@ import { AccountingService } from '../accounting.service';
*/
@Injectable()
export class AccountingRuleResolver implements Resolve<Object> {
/**
* @param {AccountingService} accountingService Accounting service.
*/
@@ -27,5 +26,4 @@ export class AccountingRuleResolver implements Resolve<Object> {
const id = route.paramMap.get('id');
return this.accountingService.getAccountingRule(id);
}
}
@@ -13,7 +13,6 @@ import { AccountingService } from '../accounting.service';
*/
@Injectable()
export class AccountingRulesTemplateResolver implements Resolve<Object> {
/**
* @param {AccountingService} accountingService Accounting service.
*/
@@ -26,5 +25,4 @@ export class AccountingRulesTemplateResolver implements Resolve<Object> {
resolve(): Observable<any> {
return this.accountingService.getAccountingRulesTemplate();
}
}
@@ -8,9 +8,8 @@ describe('AccountingRulesComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ AccountingRulesComponent ]
})
.compileComponents();
declarations: [AccountingRulesComponent]
}).compileComponents();
}));
beforeEach(() => {
@@ -14,11 +14,17 @@ import { ActivatedRoute } from '@angular/router';
styleUrls: ['./accounting-rules.component.scss']
})
export class AccountingRulesComponent implements OnInit {
/** Accounting rule data. */
accountingRuleData: any;
/** Columns to be displayed in accounting rules table. */
displayedColumns: string[] = ['name', 'officeName', 'debitTags', 'debitAccount', 'creditTags', 'creditAccount'];
displayedColumns: string[] = [
'name',
'officeName',
'debitTags',
'debitAccount',
'creditTags',
'creditAccount'
];
/** Data source for accounting rules table. */
dataSource: MatTableDataSource<any>;
@@ -49,16 +55,23 @@ export class AccountingRulesComponent implements OnInit {
*/
setAccountingRules() {
this.accountingRuleData.forEach((accountingRule: any) => {
accountingRule.debitTags = accountingRule.debitTags ? accountingRule.debitTags.map((debitTag: any) => debitTag.tag.name).join(', ') : '';
accountingRule.creditTags = accountingRule.creditTags ? accountingRule.creditTags.map((creditTag: any) => creditTag.tag.name).join(', ') : '';
accountingRule.debitTags = accountingRule.debitTags
? accountingRule.debitTags.map((debitTag: any) => debitTag.tag.name).join(', ')
: '';
accountingRule.creditTags = accountingRule.creditTags
? accountingRule.creditTags.map((creditTag: any) => creditTag.tag.name).join(', ')
: '';
});
this.dataSource = new MatTableDataSource(this.accountingRuleData);
this.dataSource.paginator = this.paginator;
this.dataSource.sortingDataAccessor = (accountingRule: any, property: any) => {
switch (property) {
case 'debitAccount': return accountingRule.debitAccounts[0].name;
case 'creditAccount': return accountingRule.creditAccounts[0].name;
default: return accountingRule[property];
case 'debitAccount':
return accountingRule.debitAccounts[0].name;
case 'creditAccount':
return accountingRule.creditAccounts[0].name;
default:
return accountingRule[property];
}
};
this.dataSource.sort = this.sort;
@@ -71,5 +84,4 @@ export class AccountingRulesComponent implements OnInit {
applyFilter(filterValue: string) {
this.dataSource.filter = filterValue.trim().toLowerCase();
}
}
@@ -13,7 +13,6 @@ import { AccountingService } from '../accounting.service';
*/
@Injectable()
export class AccountingRulesResolver implements Resolve<Object> {
/**
* @param {AccountingService} accountingService Accounting service.
*/
@@ -26,5 +25,4 @@ export class AccountingRulesResolver implements Resolve<Object> {
resolve(): Observable<any> {
return this.accountingService.getAccountingRules();
}
}
@@ -8,9 +8,8 @@ describe('CreateRuleComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ CreateRuleComponent ]
})
.compileComponents();
declarations: [CreateRuleComponent]
}).compileComponents();
}));
beforeEach(() => {
@@ -18,7 +18,6 @@ import { oneOfTheFieldsIsRequiredValidator } from '../one-of-the-fields-is-requi
styleUrls: ['./create-rule.component.scss']
})
export class CreateRuleComponent implements OnInit {
/** Accounting rule form. */
accountingRuleForm: UntypedFormGroup;
/** Office data. */
@@ -37,10 +36,12 @@ export class CreateRuleComponent implements OnInit {
* @param {ActivatedRoute} route Activated Route.
* @param {Router} router Router for navigation.
*/
constructor(private formBuilder: UntypedFormBuilder,
private accountingService: AccountingService,
private route: ActivatedRoute,
private router: Router) {
constructor(
private formBuilder: UntypedFormBuilder,
private accountingService: AccountingService,
private route: ActivatedRoute,
private router: Router
) {
this.route.data.subscribe((data: { accountingRulesTemplate: any }) => {
this.officeData = data.accountingRulesTemplate.allowedOffices;
this.glAccountData = data.accountingRulesTemplate.allowedAccounts;
@@ -61,19 +62,28 @@ export class CreateRuleComponent implements OnInit {
* Creates accounting rule form.
*/
createAccountingRuleForm() {
this.accountingRuleForm = this.formBuilder.group({
'name': ['', Validators.required],
'officeId': ['', Validators.required],
'debitRuleType': ['fixedAccount'],
'accountToDebit': [''],
'debitTags': [''],
'allowMultipleDebitEntries': [''],
'creditRuleType': ['fixedAccount'],
'accountToCredit': [''],
'creditTags': [''],
'allowMultipleCreditEntries': [''],
'description': ['']
}, { validator: oneOfTheFieldsIsRequiredValidator });
this.accountingRuleForm = this.formBuilder.group(
{
name: [
'',
Validators.required
],
officeId: [
'',
Validators.required
],
debitRuleType: ['fixedAccount'],
accountToDebit: [''],
debitTags: [''],
allowMultipleDebitEntries: [''],
creditRuleType: ['fixedAccount'],
accountToCredit: [''],
creditTags: [''],
allowMultipleCreditEntries: [''],
description: ['']
},
{ validator: oneOfTheFieldsIsRequiredValidator }
);
}
/**
@@ -121,8 +131,13 @@ export class CreateRuleComponent implements OnInit {
delete accountingRule.debitRuleType;
delete accountingRule.creditRuleType;
this.accountingService.createAccountingRule(accountingRule).subscribe((response: any) => {
this.router.navigate(['../view', response.resourceId], { relativeTo: this.route });
this.router.navigate(
[
'../view',
response.resourceId
],
{ relativeTo: this.route }
);
});
}
}
@@ -8,9 +8,8 @@ describe('EditRuleComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ EditRuleComponent ]
})
.compileComponents();
declarations: [EditRuleComponent]
}).compileComponents();
}));
beforeEach(() => {
@@ -18,7 +18,6 @@ import { oneOfTheFieldsIsRequiredValidator } from '../one-of-the-fields-is-requi
styleUrls: ['./edit-rule.component.scss']
})
export class EditRuleComponent implements OnInit {
/** Accounting rule form. */
accountingRuleForm: UntypedFormGroup;
/** Accounting rule. */
@@ -39,20 +38,19 @@ export class EditRuleComponent implements OnInit {
* @param {ActivatedRoute} route Activated Route.
* @param {Router} router Router for navigation.
*/
constructor(private formBuilder: UntypedFormBuilder,
private accountingService: AccountingService,
private route: ActivatedRoute,
private router: Router) {
this.route.data.subscribe((data: {
accountingRulesTemplate: any,
accountingRule: any
}) => {
this.officeData = data.accountingRulesTemplate.allowedOffices;
this.glAccountData = data.accountingRulesTemplate.allowedAccounts;
this.debitTagData = data.accountingRulesTemplate.allowedDebitTagOptions;
this.creditTagData = data.accountingRulesTemplate.allowedCreditTagOptions;
this.accountingRule = data.accountingRule;
});
constructor(
private formBuilder: UntypedFormBuilder,
private accountingService: AccountingService,
private route: ActivatedRoute,
private router: Router
) {
this.route.data.subscribe((data: { accountingRulesTemplate: any; accountingRule: any }) => {
this.officeData = data.accountingRulesTemplate.allowedOffices;
this.glAccountData = data.accountingRulesTemplate.allowedAccounts;
this.debitTagData = data.accountingRulesTemplate.allowedDebitTagOptions;
this.creditTagData = data.accountingRulesTemplate.allowedCreditTagOptions;
this.accountingRule = data.accountingRule;
});
}
/**
@@ -67,26 +65,35 @@ export class EditRuleComponent implements OnInit {
* Creates accounting rule form.
*/
createAccountingRuleForm() {
this.accountingRuleForm = this.formBuilder.group({
'name': [this.accountingRule.name, Validators.required],
'officeId': [this.accountingRule.officeId, Validators.required],
'debitRuleType': [''],
'accountToDebit': [''],
'debitTags': [''],
'allowMultipleDebitEntries': [''],
'creditRuleType': [''],
'accountToCredit': [''],
'creditTags': [''],
'allowMultipleCreditEntries': [''],
'description': [this.accountingRule.description]
}, { validator: oneOfTheFieldsIsRequiredValidator });
this.accountingRuleForm = this.formBuilder.group(
{
name: [
this.accountingRule.name,
Validators.required
],
officeId: [
this.accountingRule.officeId,
Validators.required
],
debitRuleType: [''],
accountToDebit: [''],
debitTags: [''],
allowMultipleDebitEntries: [''],
creditRuleType: [''],
accountToCredit: [''],
creditTags: [''],
allowMultipleCreditEntries: [''],
description: [this.accountingRule.description]
},
{ validator: oneOfTheFieldsIsRequiredValidator }
);
}
/**
* Sets accounting rule form for selected accounting rule type.
*/
setAccountingRulesForm() {
this.accountingRuleForm.get('debitRuleType').valueChanges.subscribe(debitRuleType => {
this.accountingRuleForm.get('debitRuleType').valueChanges.subscribe((debitRuleType) => {
if (debitRuleType === 'fixedAccount') {
this.accountingRuleForm.get('debitTags').reset();
this.accountingRuleForm.get('allowMultipleDebitEntries').reset();
@@ -95,7 +102,7 @@ export class EditRuleComponent implements OnInit {
this.accountingRuleForm.get('allowMultipleDebitEntries').setValue(false);
}
});
this.accountingRuleForm.get('creditRuleType').valueChanges.subscribe(creditRuleType => {
this.accountingRuleForm.get('creditRuleType').valueChanges.subscribe((creditRuleType) => {
if (creditRuleType === 'fixedAccount') {
this.accountingRuleForm.get('creditTags').reset();
this.accountingRuleForm.get('allowMultipleCreditEntries').reset();
@@ -110,7 +117,9 @@ export class EditRuleComponent implements OnInit {
this.accountingRuleForm.get('accountToDebit').setValue(this.accountingRule.debitAccounts[0].id);
} else {
this.accountingRuleForm.get('debitRuleType').setValue('listOfAccounts');
this.accountingRuleForm.get('debitTags').setValue(this.accountingRule.debitTags.map((debitTag: any) => debitTag.tag.id));
this.accountingRuleForm
.get('debitTags')
.setValue(this.accountingRule.debitTags.map((debitTag: any) => debitTag.tag.id));
this.accountingRuleForm.get('allowMultipleDebitEntries').setValue(this.accountingRule.allowMultipleDebitEntries);
}
@@ -119,8 +128,12 @@ export class EditRuleComponent implements OnInit {
this.accountingRuleForm.get('accountToCredit').setValue(this.accountingRule.creditAccounts[0].id);
} else {
this.accountingRuleForm.get('creditRuleType').setValue('listOfAccounts');
this.accountingRuleForm.get('creditTags').setValue(this.accountingRule.creditTags.map((creditTag: any) => creditTag.tag.id));
this.accountingRuleForm.get('allowMultipleCreditEntries').setValue(this.accountingRule.allowMultipleCreditEntries);
this.accountingRuleForm
.get('creditTags')
.setValue(this.accountingRule.creditTags.map((creditTag: any) => creditTag.tag.id));
this.accountingRuleForm
.get('allowMultipleCreditEntries')
.setValue(this.accountingRule.allowMultipleCreditEntries);
}
}
@@ -145,8 +158,13 @@ export class EditRuleComponent implements OnInit {
delete accountingRule.debitRuleType;
delete accountingRule.creditRuleType;
this.accountingService.updateAccountingRule(this.accountingRule.id, accountingRule).subscribe((response: any) => {
this.router.navigate(['../../', response.resourceId], { relativeTo: this.route });
this.router.navigate(
[
'../../',
response.resourceId
],
{ relativeTo: this.route }
);
});
}
}
@@ -2,10 +2,12 @@
import { UntypedFormGroup, ValidatorFn, ValidationErrors } from '@angular/forms';
/** Validates that one of the fields for debit or credit is filled for a given accounting rule type. */
export const oneOfTheFieldsIsRequiredValidator: ValidatorFn = (accountingRuleForm: UntypedFormGroup): ValidationErrors | null => {
export const oneOfTheFieldsIsRequiredValidator: ValidatorFn = (
accountingRuleForm: UntypedFormGroup
): ValidationErrors | null => {
const accountToDebit = accountingRuleForm.controls.accountToDebit.value;
const debitTags = accountingRuleForm.controls.debitTags.value;
const accountToCredit = accountingRuleForm.controls.accountToCredit.value;
const creditTags = accountingRuleForm.controls.creditTags.value;
return ((accountToDebit || debitTags) && (accountToCredit || creditTags)) ? null : { 'error': true };
return (accountToDebit || debitTags) && (accountToCredit || creditTags) ? null : { error: true };
};
@@ -8,9 +8,8 @@ describe('ViewRuleComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ViewRuleComponent ]
})
.compileComponents();
declarations: [ViewRuleComponent]
}).compileComponents();
}));
beforeEach(() => {
@@ -18,7 +18,6 @@ import { DeleteDialogComponent } from '../../../shared/delete-dialog/delete-dial
styleUrls: ['./view-rule.component.scss']
})
export class ViewRuleComponent {
/** Accounting rule. */
accountingRule: any;
@@ -29,10 +28,12 @@ export class ViewRuleComponent {
* @param {Router} router Router for navigation.
* @param {MatDialog} dialog Dialog reference.
*/
constructor(private accountingService: AccountingService,
private route: ActivatedRoute,
private router: Router,
public dialog: MatDialog) {
constructor(
private accountingService: AccountingService,
private route: ActivatedRoute,
private router: Router,
public dialog: MatDialog
) {
this.route.data.subscribe((data: { accountingRule: any }) => {
this.accountingRule = data.accountingRule;
});
@@ -47,12 +48,10 @@ export class ViewRuleComponent {
});
deleteAccountingRuleDialogRef.afterClosed().subscribe((response: any) => {
if (response.delete) {
this.accountingService.deleteAccountingRule(this.accountingRule.id)
.subscribe(() => {
this.router.navigate(['/accounting/accounting-rules']);
});
this.accountingService.deleteAccountingRule(this.accountingRule.id).subscribe(() => {
this.router.navigate(['/accounting/accounting-rules']);
});
}
});
}
}