Skip to content

Commit

Permalink
fix: standardize custom fields for policy check (#3324)
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunaj5 committed Dec 11, 2024
1 parent 1810aa4 commit 61fcbd3
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 7 deletions.
7 changes: 3 additions & 4 deletions src/app/fyle/add-edit-expense/add-edit-expense.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3518,14 +3518,13 @@ export class AddEditExpensePage implements OnInit {
const isAdvanceWalletEnabled = res.orgSettings?.advances?.advance_wallets_enabled;
let customProperties = res.customProperties;
customProperties = customProperties.map((customProperty) => {
if (!customProperty.value) {
this.customFieldsService.setDefaultValue(customProperty, customProperty.type);
}
if (customProperty.type === 'DATE') {
customProperty.value = customProperty.value
? this.dateService.getUTCDate(new Date(customProperty.value as string))
: null;
} else if (customProperty.type === 'LOCATION' && !customProperty.value) {
customProperty.value = {};
} else if (customProperty.type === 'BOOLEAN' && !customProperty.value) {
customProperty.value = false;
}
return customProperty;
});
Expand Down
5 changes: 4 additions & 1 deletion src/app/fyle/add-edit-expense/add-edit-expense.setup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ describe('AddEditExpensePage', () => {
'addExpenses',
]);
const customInputsServiceSpy = jasmine.createSpyObj('CustomInputsService', ['getAll', 'filterByCategory']);
const customFieldsServiceSpy = jasmine.createSpyObj('CustomFieldsService', ['standardizeCustomFields']);
const customFieldsServiceSpy = jasmine.createSpyObj('CustomFieldsService', [
'standardizeCustomFields',
'setDefaultValue',
]);
const transactionServiceSpy = jasmine.createSpyObj('TransactionService', [
'delete',
'getRemoveCardExpenseDialogBody',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ describe('AddEditMileagePage', () => {
const advanceWalletsServiceSpy = jasmine.createSpyObj('AdvanceWalletsService', ['getAllAdvanceWallets']);
const spenderServiceSpy = jasmine.createSpyObj('SpenderService', ['get', 'post']);
const customInputsServiceSpy = jasmine.createSpyObj('CustomInputsService', ['getAll', 'filterByCategory']);
const customFieldsServiceSpy = jasmine.createSpyObj('CustomFieldsService', ['standardizeCustomFields']);
const customFieldsServiceSpy = jasmine.createSpyObj('CustomFieldsService', [
'standardizeCustomFields',
'setDefaultValue',
]);
const transactionServiceSpy = jasmine.createSpyObj('TransactionService', [
'delete',
'getRemoveCardExpenseDialogBody',
Expand Down
3 changes: 3 additions & 0 deletions src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2415,6 +2415,9 @@ export class AddEditMileagePage implements OnInit {
const formValue = this.getFormValues();
let customProperties = res.customProperties;
customProperties = customProperties?.map((customProperty) => {
if (!customProperty.value) {
this.customFieldsService.setDefaultValue(customProperty, customProperty.type);
}
if (customProperty.type === 'DATE') {
customProperty.value =
customProperty.value && this.dateService.getUTCDate(new Date(customProperty.value as string));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ describe('AddEditPerDiemPage', () => {
]);
const perDiemServiceSpy = jasmine.createSpyObj('PerDiemService', ['getRates', 'getAllowedPerDiems']);
const customInputsServiceSpy = jasmine.createSpyObj('CustomInputsService', ['getAll', 'filterByCategory']);
const customFieldsServiceSpy = jasmine.createSpyObj('CustomFieldsService', ['standardizeCustomFields']);
const customFieldsServiceSpy = jasmine.createSpyObj('CustomFieldsService', [
'standardizeCustomFields',
'setDefaultValue',
]);
const currencyServiceSpy = jasmine.createSpyObj('CurrencyService', [
'getHomeCurrency',
'getAmountWithCurrencyFraction',
Expand Down
3 changes: 3 additions & 0 deletions src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1697,6 +1697,9 @@ export class AddEditPerDiemPage implements OnInit {
const isAdvanceWalletEnabled = res.orgSettings?.advances?.advance_wallets_enabled;
let customProperties = res.customProperties;
customProperties = customProperties.map((customProperty) => {
if (!customProperty.value) {
this.customFieldsService.setDefaultValue(customProperty, customProperty.type);
}
if (customProperty.type === 'DATE') {
customProperty.value =
customProperty.value && this.dateService.getUTCDate(new Date(customProperty.value as string));
Expand Down

0 comments on commit 61fcbd3

Please sign in to comment.