-
Notifications
You must be signed in to change notification settings - Fork 0
fix: qbd direct team testing fixes #1095
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -211,6 +211,26 @@ export class QbdDirectExportSettingsComponent implements OnInit{ | |
| }); | ||
| } | ||
|
|
||
| defaultAccountsPayableAccountWatcher() { | ||
| this.exportSettingsForm.controls.employeeMapping.valueChanges.subscribe((employeeMapping) => { | ||
| if (employeeMapping === EmployeeFieldMapping.EMPLOYEE) { | ||
| if (this.exportSettingsForm.controls.nameInJE.value === EmployeeFieldMapping.EMPLOYEE && this.exportSettingsForm.controls.defaultCCCAccountsPayableAccountName.value.detail.account_type === 'AccountsPayable') { | ||
| this.exportSettingsForm.controls.defaultCCCAccountsPayableAccountName.patchValue(null); | ||
| } else if (this.exportSettingsForm.controls.defaultReimbursableAccountsPayableAccountName.value.detail.account_type === 'AccountsPayable') { | ||
| this.exportSettingsForm.controls.defaultReimbursableAccountsPayableAccountName.patchValue(null); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| defaultCCCAccountsPayableAccountWatcher() { | ||
| this.exportSettingsForm.controls.nameInJE.valueChanges.subscribe((nameInJE) => { | ||
| if (nameInJE === EmployeeFieldMapping.EMPLOYEE && this.exportSettingsForm.controls.employeeMapping.value === EmployeeFieldMapping.EMPLOYEE && this.exportSettingsForm.controls.defaultCCCAccountsPayableAccountName.value.detail.account_type === 'AccountsPayable') { | ||
| this.exportSettingsForm.controls.defaultCCCAccountsPayableAccountName.patchValue(null); | ||
| } | ||
| }); | ||
| } | ||
|
Comment on lines
+246
to
+252
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Improve error handling and code readability Similar to the previous method, this one needs improvements in error handling and null safety. Consider this safer implementation: defaultCCCAccountsPayableAccountWatcher() {
- this.exportSettingsForm.controls.nameInJE.valueChanges.subscribe((nameInJE) => {
- if (nameInJE === EmployeeFieldMapping.EMPLOYEE && this.exportSettingsForm.controls.employeeMapping.value === EmployeeFieldMapping.EMPLOYEE && this.exportSettingsForm.controls.defaultCCCAccountsPayableAccountName.value.detail.account_type === 'AccountsPayable') {
- this.exportSettingsForm.controls.defaultCCCAccountsPayableAccountName.patchValue(null);
+ this.exportSettingsForm.controls.nameInJE.valueChanges.subscribe({
+ next: (nameInJE) => {
+ const isEmployeeMapping = this.exportSettingsForm.controls.employeeMapping.value === EmployeeFieldMapping.EMPLOYEE;
+ const cccAccount = this.exportSettingsForm.controls.defaultCCCAccountsPayableAccountName.value?.detail;
+
+ if (nameInJE === EmployeeFieldMapping.EMPLOYEE &&
+ isEmployeeMapping &&
+ cccAccount?.account_type === QbdDirectAccountType.ACCOUNTS_PAYABLE) {
+ this.exportSettingsForm.controls.defaultCCCAccountsPayableAccountName.patchValue(null);
+ }
+ },
+ error: (error) => {
+ console.error('Error in nameInJE subscription:', error);
}
});
}
|
||
|
|
||
| destinationOptionsWatcher(detailAccountType: string[], destinationOptions: QbdDirectDestinationAttribute[]): DestinationAttribute[] { | ||
| return destinationOptions.filter((account: QbdDirectDestinationAttribute) => detailAccountType.includes(account.detail.account_type)); | ||
| } | ||
|
|
@@ -224,6 +244,10 @@ export class QbdDirectExportSettingsComponent implements OnInit{ | |
| this.reimbursableExpenseGroupWatcher(); | ||
|
|
||
| this.cccExpenseGroupWatcher(); | ||
|
|
||
| this.defaultAccountsPayableAccountWatcher(); | ||
|
|
||
| this.defaultCCCAccountsPayableAccountWatcher(); | ||
|
Comment on lines
+289
to
+292
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Prevent memory leaks and improve watcher organization The watchers are correctly integrated, but there are two concerns:
Consider these improvements:
private subscriptions: Subscription[] = [];
private exportsettingsWatcher(): void {
// Group related watchers
// Credit card related
this.subscriptions.push(this.cccExportTypeWatcher());
this.subscriptions.push(this.cccExpenseGroupWatcher());
this.subscriptions.push(this.defaultCCCAccountsPayableAccountWatcher());
// Employee mapping related
this.subscriptions.push(this.employeeMappingWatcher());
this.subscriptions.push(this.defaultAccountsPayableAccountWatcher());
// Reimbursable related
this.subscriptions.push(this.reimbursableExpenseGroupWatcher());
}
ngOnDestroy() {
this.subscriptions.forEach(subscription => subscription.unsubscribe());
}
defaultAccountsPayableAccountWatcher(): Subscription {
return this.exportSettingsForm.controls.employeeMapping.valueChanges.subscribe({
// ... existing implementation
});
} |
||
| } | ||
|
|
||
| private setupCCCExpenseGroupingDateOptions(): void { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add null checks and improve code robustness
The method has several potential issues that should be addressed:
value.detailwhich could cause runtime errorsConsider this safer implementation:
defaultAccountsPayableAccountWatcher() { - this.exportSettingsForm.controls.employeeMapping.valueChanges.subscribe((employeeMapping) => { + this.exportSettingsForm.controls.employeeMapping.valueChanges.subscribe({ + next: (employeeMapping) => { if (employeeMapping === EmployeeFieldMapping.EMPLOYEE) { - if (this.exportSettingsForm.controls.nameInJE.value === EmployeeFieldMapping.EMPLOYEE && this.exportSettingsForm.controls.defaultCCCAccountsPayableAccountName.value.detail.account_type === 'AccountsPayable') { + const cccAccount = this.exportSettingsForm.controls.defaultCCCAccountsPayableAccountName.value?.detail; + const reimbursableAccount = this.exportSettingsForm.controls.defaultReimbursableAccountsPayableAccountName.value?.detail; + + if (this.exportSettingsForm.controls.nameInJE.value === EmployeeFieldMapping.EMPLOYEE && + cccAccount?.account_type === QbdDirectAccountType.ACCOUNTS_PAYABLE) { this.exportSettingsForm.controls.defaultCCCAccountsPayableAccountName.patchValue(null); - } else if (this.exportSettingsForm.controls.defaultReimbursableAccountsPayableAccountName.value.detail.account_type === 'AccountsPayable') { + } else if (reimbursableAccount?.account_type === QbdDirectAccountType.ACCOUNTS_PAYABLE) { this.exportSettingsForm.controls.defaultReimbursableAccountsPayableAccountName.patchValue(null); } } + }, + error: (error) => { + console.error('Error in employeeMapping subscription:', error); + } }); }Also, consider adding an enum for account types: