diff --git a/src/app/core/mock-data/filter.data.ts b/src/app/core/mock-data/filter.data.ts index fef05aebd8..9df92855cb 100644 --- a/src/app/core/mock-data/filter.data.ts +++ b/src/app/core/mock-data/filter.data.ts @@ -2,23 +2,9 @@ import deepFreeze from 'deep-freeze-strict'; import { FilterOptionType } from 'src/app/shared/components/fy-filters/filter-option-type.enum'; import { FilterOptions } from 'src/app/shared/components/fy-filters/filter-options.interface'; +import { PersonalCardFilter } from '../models/personal-card-filters.model'; -type Filter = Partial<{ - amount: number; - createdOn: Partial<{ - name?: string; - customDateStart?: Date; - customDateEnd?: Date; - }>; - updatedOn: Partial<{ - name?: string; - customDateStart?: Date; - customDateEnd?: Date; - }>; - transactionType: string; -}>; - -export const filterData1: Filter = deepFreeze({ +export const filterData1: Partial = deepFreeze({ createdOn: { name: 'custom', customDateStart: new Date('2023-02-20T00:00:00.000Z'), diff --git a/src/app/core/models/filter-query-params.model.ts b/src/app/core/models/filter-query-params.model.ts index db725c0304..98fa1d9346 100644 --- a/src/app/core/models/filter-query-params.model.ts +++ b/src/app/core/models/filter-query-params.model.ts @@ -1,8 +1,10 @@ export interface FilterQueryParams { - or?: string[]; + or?: string[] | string; tx_report_id?: string; corporate_credit_card_account_number?: string; tx_num_files?: string; and?: string; tx_state?: string; + btxn_status?: string; + ba_id?: string; } diff --git a/src/app/core/models/personal-card-date-filter.model.ts b/src/app/core/models/personal-card-date-filter.model.ts new file mode 100644 index 0000000000..b0d431b52c --- /dev/null +++ b/src/app/core/models/personal-card-date-filter.model.ts @@ -0,0 +1,5 @@ +export interface PersonalCardDateFilter { + name?: string; + customDateStart?: Date; + customDateEnd?: Date; +} diff --git a/src/app/core/models/personal-card-filters.model.ts b/src/app/core/models/personal-card-filters.model.ts index e9afe22966..f8a7dba7a8 100644 --- a/src/app/core/models/personal-card-filters.model.ts +++ b/src/app/core/models/personal-card-filters.model.ts @@ -1,14 +1,8 @@ +import { PersonalCardDateFilter } from './personal-card-date-filter.model'; + export interface PersonalCardFilter { - amount?: number; - createdOn?: { - name?: string; - customDateStart?: Date; - customDateEnd?: Date; - }; - updatedOn?: { - name?: string; - customDateStart?: Date; - customDateEnd?: Date; - }; - transactionType?: string; + amount: number; + createdOn: PersonalCardDateFilter; + updatedOn: PersonalCardDateFilter; + transactionType: string; } diff --git a/src/app/core/models/platform/personal-cards-date-params.model.ts b/src/app/core/models/platform/personal-cards-date-params.model.ts new file mode 100644 index 0000000000..794453098f --- /dev/null +++ b/src/app/core/models/platform/personal-cards-date-params.model.ts @@ -0,0 +1,11 @@ +export interface PersonalCardsDateParams { + pageNumber: number; + queryParams: { + ba_id?: string; + btxn_status?: string; + or?: string; + }; + sortParam: string; + sortDir: string; + searchString: string; +} diff --git a/src/app/core/models/platform/v1/expenses-query-params.model.ts b/src/app/core/models/platform/v1/expenses-query-params.model.ts index 81eebdcc19..31fdaffd86 100644 --- a/src/app/core/models/platform/v1/expenses-query-params.model.ts +++ b/src/app/core/models/platform/v1/expenses-query-params.model.ts @@ -3,6 +3,7 @@ import { APIQueryParams } from './query-params.model'; export interface ExpensesQueryParams extends APIQueryParams { report_id?: string; state?: string; + split_group_id?: string; searchString?: string; queryParams?: Record; } diff --git a/src/app/core/services/personal-cards.service.spec.ts b/src/app/core/services/personal-cards.service.spec.ts index 8ba34d4bfc..afcc624b0f 100644 --- a/src/app/core/services/personal-cards.service.spec.ts +++ b/src/app/core/services/personal-cards.service.spec.ts @@ -282,8 +282,8 @@ describe('PersonalCardsService', () => { const filters = { createdOn: { name: 'custom', - customDateStart: '2023-02-21T00:00:00.000Z', - customDateEnd: '2023-02-23T00:00:00.000Z', + customDateStart: new Date('2023-02-21T00:00:00.000Z'), + customDateEnd: new Date('2023-02-23T00:00:00.000Z'), }, }; @@ -785,9 +785,9 @@ describe('PersonalCardsService', () => { const filters = { updatedOn: { - name: DateFilters.lastMonth, - customDateStart: '2023-02-21T00:00:00.000Z', - customDateEnd: '2023-02-23T00:00:00.000Z', + name: DateFilters.lastMonth as string, + customDateStart: new Date('2023-02-21T00:00:00.000Z'), + customDateEnd: new Date('2023-02-23T00:00:00.000Z'), }, }; @@ -814,22 +814,6 @@ describe('PersonalCardsService', () => { }); }); - it('getExpenseDetails(): should get expense details', (done) => { - apiV2Service.get.and.returnValue(of(etxncData)); - - const txnSplitGroupID = 'txOJVaaPxo9O'; - - personalCardsService.getExpenseDetails(txnSplitGroupID).subscribe((res) => { - expect(res).toEqual(etxncData.data[0]); - expect(apiV2Service.get).toHaveBeenCalledOnceWith('/expenses', { - params: { - tx_split_group_id: `eq.${txnSplitGroupID}`, - }, - }); - done(); - }); - }); - it('fetchTransactions(): should fetch transactions', (done) => { expenseAggregationService.post.and.returnValue(of(apiPersonalCardTxnsRes)); const accountId = 'baccLesaRlyvLY'; diff --git a/src/app/core/services/personal-cards.service.ts b/src/app/core/services/personal-cards.service.ts index 5116f05adf..0e9950baea 100644 --- a/src/app/core/services/personal-cards.service.ts +++ b/src/app/core/services/personal-cards.service.ts @@ -15,16 +15,8 @@ import { FilterPill } from 'src/app/shared/components/fy-filter-pills/filter-pil import * as dayjs from 'dayjs'; import { ApiV2Response } from '../models/api-v2.model'; import { PersonalCardTxn } from '../models/personal_card_txn.model'; - -type matchExpenseResponse = Partial<{ - external_expense_id: string; - id: string; - transaction_split_group_id: string; -}>; - -type QueryParam = { ba_id?: string; btxn_status?: string; or?: string }; - -type Params = { pageNumber: number; queryParams: QueryParam; sortParam: string; sortDir: string; searchString: string }; +import { PersonalCardDateFilter } from '../models/personal-card-date-filter.model'; +import { SortFiltersParams } from '../models/sort-filters-params.model'; @Injectable({ providedIn: 'root', @@ -48,7 +40,7 @@ export class PersonalCardsService { } getToken(): Observable { - return this.expenseAggregationService.get('/yodlee/personal/access_token'); + return this.expenseAggregationService.get('/yodlee/personal/access_token') as Observable; } htmlFormUrl(url: string, accessToken: string): string { @@ -68,7 +60,7 @@ export class PersonalCardsService { return this.expenseAggregationService.post('/yodlee/personal/bank_accounts', { aggregator: 'yodlee', request_ids: requestIds, - }); + }) as Observable; } getLinkedAccountsCount(): Observable { @@ -91,7 +83,7 @@ export class PersonalCardsService { } deleteAccount(accountId: string): Observable { - return this.expenseAggregationService.delete('/bank_accounts/' + accountId); + return this.expenseAggregationService.delete('/bank_accounts/' + accountId) as Observable; } getBankTransactions( @@ -129,17 +121,14 @@ export class PersonalCardsService { return this.getMatchedExpenses(amount, txnDate).pipe(map((res) => res.length)); } - getExpenseDetails(transactionSplitGroupId: string): Observable { - return this.apiv2Service - .get('/expenses', { - params: { - tx_split_group_id: `eq.${transactionSplitGroupId}`, - }, - }) - .pipe(map((res) => res.data[0])); - } - - matchExpense(transactionSplitGroupId: string, externalExpenseId: string): Observable { + matchExpense( + transactionSplitGroupId: string, + externalExpenseId: string + ): Observable<{ + external_expense_id?: string; + id: string; + transaction_split_group_id: string; + }> { return this.apiService.post('/transactions/external_expense/match', { transaction_split_group_id: transactionSplitGroupId, external_expense_id: externalExpenseId, @@ -158,23 +147,26 @@ export class PersonalCardsService { fetchTransactions(accountId: string): Observable> { return this.expenseAggregationService.post(`/bank_accounts/${accountId}/sync`, { owner_type: 'org_user', - }); + }) as Observable>; } hideTransactions(txnIds: string[]): Observable { return this.expenseAggregationService.post('/bank_transactions/hide/bulk', { bank_transaction_ids: txnIds, - }); + }) as Observable; } - unmatchExpense(transactionSplitGroupId: string, externalExpenseId: string) { + unmatchExpense(transactionSplitGroupId: string, externalExpenseId: string): Observable { return this.apiService.post('/transactions/external_expense/unmatch', { transaction_split_group_id: transactionSplitGroupId, external_expense_id: externalExpenseId, }); } - generateDateParams(data: { range: string; endDate?: string; startDate?: string }, currentParams: Partial) { + generateDateParams( + data: { range: string; endDate?: string; startDate?: string }, + currentParams: Partial + ): Partial { if (data.range === 'This Month') { const thisMonth = this.dateService.getThisMonthRange(); currentParams.queryParams.or = `(and(btxn_transaction_dt.gte.${thisMonth.from.toISOString()},btxn_transaction_dt.lt.${thisMonth.to.toISOString()}))`; @@ -209,8 +201,8 @@ export class PersonalCardsService { return currentParams; } - convertFilters(selectedFilters: SelectedFilters[]): PersonalCardFilter { - const generatedFilters: PersonalCardFilter = {}; + convertFilters(selectedFilters: SelectedFilters[]): Partial { + const generatedFilters: PersonalCardFilter = {} as PersonalCardFilter; const createdOnDateFilter = selectedFilters.find((filter) => filter.name === 'Created On'); if (createdOnDateFilter) { generatedFilters.createdOn = { name: createdOnDateFilter.value }; @@ -238,27 +230,29 @@ export class PersonalCardsService { return generatedFilters; } - generateSelectedFilters(filter: PersonalCardFilter): SelectedFilters[] { + generateSelectedFilters(filter: Partial): SelectedFilters[] { const generatedFilters: SelectedFilters[] = []; if (filter?.updatedOn) { + const dateFilter = filter; generatedFilters.push({ name: 'Updated On', - value: filter.updatedOn.name, + value: dateFilter.updatedOn.name, associatedData: { - startDate: filter.updatedOn.customDateStart, - endDate: filter.updatedOn.customDateEnd, + startDate: dateFilter.updatedOn.customDateStart, + endDate: dateFilter.updatedOn.customDateEnd, }, }); } if (filter?.createdOn) { + const dateFilter = filter; generatedFilters.push({ name: 'Created On', - value: filter.createdOn.name, + value: dateFilter.createdOn.name, associatedData: { - startDate: filter.createdOn.customDateStart, - endDate: filter.createdOn.customDateEnd, + startDate: dateFilter.createdOn.customDateStart, + endDate: dateFilter.createdOn.customDateEnd, }, }); } @@ -273,31 +267,32 @@ export class PersonalCardsService { return generatedFilters; } - generateTxnDateParams(newQueryParams, filters, type) { - let queryType; + generateTxnDateParams(newQueryParams: { or: string[] }, filters: Partial, type: string): void { + let queryType: string; if (type === 'createdOn') { queryType = 'btxn_created_at'; } else { queryType = 'btxn_updated_at'; } if (filters[type]) { - filters[type].customDateStart = filters[type].customDateStart && new Date(filters[type].customDateStart); - filters[type].customDateEnd = filters[type].customDateEnd && new Date(filters[type].customDateEnd); - if (filters[type].name === DateFilters.thisMonth) { + const dateFilter = filters[type] as PersonalCardDateFilter; + dateFilter.customDateStart = dateFilter.customDateStart && new Date(dateFilter.customDateStart); + dateFilter.customDateEnd = dateFilter.customDateEnd && new Date(dateFilter.customDateEnd); + if (dateFilter.name === DateFilters.thisMonth) { const thisMonth = this.dateService.getThisMonthRange(); newQueryParams.or.push( `(and(${queryType}.gte.${thisMonth.from.toISOString()},${queryType}.lt.${thisMonth.to.toISOString()}))` ); } - if (filters[type].name === DateFilters.thisWeek) { + if (dateFilter.name === DateFilters.thisWeek) { const thisWeek = this.dateService.getThisWeekRange(); newQueryParams.or.push( `(and(${queryType}.gte.${thisWeek.from.toISOString()},${queryType}.lt.${thisWeek.to.toISOString()}))` ); } - if (filters[type].name === DateFilters.lastMonth) { + if (dateFilter.name === DateFilters.lastMonth) { const lastMonth = this.dateService.getLastMonthRange(); newQueryParams.or.push( `(and(${queryType}.gte.${lastMonth.from.toISOString()},${queryType}.lt.${lastMonth.to.toISOString()}))` @@ -310,18 +305,19 @@ export class PersonalCardsService { generateCustomDateParams( newQueryParams: { ba_id?: string; btxn_status?: string; or?: string[] }, - filters: PersonalCardFilter, + filters: Partial, type: string, queryType: string - ) { - if (filters[type].name === DateFilters.custom) { - const startDate = filters[type].customDateStart?.toISOString(); - const endDate = filters[type].customDateEnd?.toISOString(); - if (filters[type].customDateStart && filters[type].customDateEnd) { + ): void { + const dateFilter = filters[type] as PersonalCardDateFilter; + if (dateFilter.name === DateFilters.custom) { + const startDate = dateFilter.customDateStart?.toISOString(); + const endDate = dateFilter.customDateEnd?.toISOString(); + if (dateFilter.customDateStart && dateFilter.customDateEnd) { newQueryParams.or.push(`(and(${queryType}.gte.${startDate},${queryType}.lt.${endDate}))`); - } else if (filters[type].customDateStart) { + } else if (dateFilter.customDateStart) { newQueryParams.or.push(`(and(${queryType}.gte.${startDate}))`); - } else if (filters[type].customDateEnd) { + } else if (dateFilter.customDateEnd) { newQueryParams.or.push(`(and(${queryType}.lt.${endDate}))`); } } @@ -329,9 +325,9 @@ export class PersonalCardsService { generateCreditParams( newQueryParams: { ba_id?: string; btxn_status?: string; or?: string[] }, - filters: PersonalCardFilter - ) { - const transactionTypeMap = { + filters: Partial + ): void { + const transactionTypeMap: { [key: string]: string } = { credit: '(btxn_transaction_type.in.(credit))', debit: '(btxn_transaction_type.in.(debit))', }; @@ -340,7 +336,7 @@ export class PersonalCardsService { } } - generateFilterPills(filters: PersonalCardFilter) { + generateFilterPills(filters: Partial): FilterPill[] { const filterPills: FilterPill[] = []; if (filters?.createdOn) { @@ -358,7 +354,7 @@ export class PersonalCardsService { return filterPills; } - private generateUpdatedOnCustomDatePill(filters: PersonalCardFilter, filterPills: FilterPill[]) { + private generateUpdatedOnCustomDatePill(filters: Partial, filterPills: FilterPill[]): void { const startDate = filters.updatedOn.customDateStart && dayjs(filters.updatedOn.customDateStart).format('YYYY-MM-D'); const endDate = filters.updatedOn.customDateEnd && dayjs(filters.updatedOn.customDateEnd).format('YYYY-MM-D'); @@ -383,7 +379,7 @@ export class PersonalCardsService { } } - private generateCreditTrasactionsFilterPills(filters, filterPills: FilterPill[]) { + private generateCreditTrasactionsFilterPills(filters: Partial, filterPills: FilterPill[]): void { if (filters.transactionType === 'Credit') { filterPills.push({ label: 'Transactions Type', @@ -401,7 +397,7 @@ export class PersonalCardsService { } } - private generateCreatedOnCustomDatePill(filters: PersonalCardFilter, filterPills: FilterPill[]) { + private generateCreatedOnCustomDatePill(filters: Partial, filterPills: FilterPill[]): void { const startDate = filters.createdOn.customDateStart && dayjs(filters.createdOn.customDateStart).format('YYYY-MM-D'); const endDate = filters.createdOn.customDateEnd && dayjs(filters.createdOn.customDateEnd).format('YYYY-MM-D'); @@ -426,8 +422,9 @@ export class PersonalCardsService { } } - private generateDateFilterPills(type, filters, filterPills: FilterPill[]) { - if (filters[type].name === DateFilters.thisWeek) { + private generateDateFilterPills(type: string, filters: Partial, filterPills: FilterPill[]): void { + const dateFilter = filters[type] as PersonalCardDateFilter; + if (dateFilter.name === DateFilters.thisWeek) { filterPills.push({ label: 'Created On', type: 'date', @@ -435,7 +432,7 @@ export class PersonalCardsService { }); } - if (filters[type].name === DateFilters.thisMonth) { + if (dateFilter.name === DateFilters.thisMonth) { filterPills.push({ label: 'Created On', type: 'date', @@ -443,7 +440,7 @@ export class PersonalCardsService { }); } - if (filters[type].name === DateFilters.all) { + if (dateFilter.name === DateFilters.all) { filterPills.push({ label: 'Created On', type: 'date', @@ -451,7 +448,7 @@ export class PersonalCardsService { }); } - if (filters[type].name === DateFilters.lastMonth) { + if (dateFilter.name === DateFilters.lastMonth) { filterPills.push({ label: 'Created On', type: 'date', @@ -459,7 +456,7 @@ export class PersonalCardsService { }); } - if (filters[type].name === DateFilters.custom) { + if (dateFilter.name === DateFilters.custom) { if (type === 'createdOn') { this.generateCreatedOnCustomDatePill(filters, filterPills); } diff --git a/src/app/core/services/transaction.service.spec.ts b/src/app/core/services/transaction.service.spec.ts index 6326dc3e0e..5e02d38157 100644 --- a/src/app/core/services/transaction.service.spec.ts +++ b/src/app/core/services/transaction.service.spec.ts @@ -60,7 +60,6 @@ import { cloneDeep } from 'lodash'; import { expensesCacheBuster$ } from '../cache-buster/expense-cache-buster'; import { ExpensesService } from './platform/v1/spender/expenses.service'; import { expenseData } from '../mock-data/platform/v1/expense.data'; -import { LaunchDarklyService } from './launch-darkly.service'; describe('TransactionService', () => { let transactionService: TransactionService; @@ -85,9 +84,7 @@ describe('TransactionService', () => { beforeEach(() => { const networkServiceSpy = jasmine.createSpyObj('NetworkService', ['isOnline']); const storageServiceSpy = jasmine.createSpyObj('StorageService', ['get', 'set']); - const authServiceSpy = jasmine.createSpyObj('AuthService', ['getEou']); const apiServiceSpy = jasmine.createSpyObj('ApiService', ['get', 'post', 'delete']); - const apiV2ServiceSpy = jasmine.createSpyObj('ApiV2Service', ['get', 'getStats']); const dataTransformServiceSpy = jasmine.createSpyObj('DataTransformService', ['unflatten']); const dateServiceSpy = jasmine.createSpyObj('DateService', [ 'fixDates', @@ -111,27 +108,14 @@ describe('TransactionService', () => { const orgSettingsServiceSpy = jasmine.createSpyObj('OrgSettingsService', ['get']); const accountsServiceSpy = jasmine.createSpyObj('AccountsService', ['getEMyAccounts']); const expensesServiceSpy = jasmine.createSpyObj('ExpensesService', ['attachReceiptsToExpense']); - const ldServiceSpy = jasmine.createSpyObj('LaunchDarklyService', ['getImmediate']); TestBed.configureTestingModule({ providers: [ TransactionService, - { - provide: LaunchDarklyService, - useValue: ldServiceSpy, - }, { provide: ApiService, useValue: apiServiceSpy, }, - { - provide: ApiV2Service, - useValue: apiV2ServiceSpy, - }, - { - provide: AuthService, - useValue: authServiceSpy, - }, { provide: DataTransformService, useValue: dataTransformServiceSpy, @@ -198,9 +182,7 @@ describe('TransactionService', () => { transactionService = TestBed.inject(TransactionService); networkService = TestBed.inject(NetworkService) as jasmine.SpyObj; storageService = TestBed.inject(StorageService) as jasmine.SpyObj; - authService = TestBed.inject(AuthService) as jasmine.SpyObj; apiService = TestBed.inject(ApiService) as jasmine.SpyObj; - apiV2Service = TestBed.inject(ApiV2Service) as jasmine.SpyObj; dataTransformService = TestBed.inject(DataTransformService) as jasmine.SpyObj; dateService = TestBed.inject(DateService) as jasmine.SpyObj; orgUserSettingsService = TestBed.inject(OrgUserSettingsService) as jasmine.SpyObj; @@ -847,117 +829,6 @@ describe('TransactionService', () => { }); }); - it('getMyExpenses(): should return my expenses with order', (done) => { - authService.getEou.and.resolveTo(eouRes2); - apiV2Service.get.and.returnValue(of(expenseV2Data)); - dateService.fixDatesV2.and.returnValue(expenseV2Data.data[0]); - - const params = { - offset: 0, - limit: 1, - queryParams: { - or: [], - tx_report_id: 'is.null', - tx_state: 'in.(COMPLETE,DRAFT)', - }, - order: 'tx_txn_dt.desc', - }; - - transactionService.getMyExpenses(params).subscribe((res) => { - expect(res).toEqual(expenseV2Data); - expect(apiV2Service.get).toHaveBeenCalledOnceWith('/expenses', { - params: { - offset: params.offset, - limit: params.limit, - order: `${params.order || 'tx_txn_dt.desc'},tx_created_at.desc,tx_id.desc`, - tx_org_user_id: 'eq.' + eouRes2.ou.id, - ...params.queryParams, - }, - }); - expect(authService.getEou).toHaveBeenCalledTimes(1); - expect(dateService.fixDatesV2).toHaveBeenCalledOnceWith(res.data[0]); - done(); - }); - }); - - it('getMyExpenses(): should return my expenses without order using default date order', (done) => { - authService.getEou.and.resolveTo(eouRes2); - apiV2Service.get.and.returnValue(of(expenseV2Data)); - dateService.fixDatesV2.and.returnValue(expenseV2Data.data[0]); - - const params2 = { - offset: 0, - limit: 1, - queryParams: { - or: [], - tx_report_id: 'is.null', - tx_state: 'in.(COMPLETE,DRAFT)', - }, - }; - - transactionService.getMyExpenses(params2).subscribe((res) => { - expect(res).toEqual(expenseV2Data); - expect(apiV2Service.get).toHaveBeenCalledOnceWith('/expenses', { - params: { - offset: params2.offset, - limit: params2.limit, - // eslint-disable-next-line @typescript-eslint/dot-notation - order: `${params2['order'] || 'tx_txn_dt.desc'},tx_created_at.desc,tx_id.desc`, - tx_org_user_id: 'eq.' + eouRes2.ou.id, - ...params2.queryParams, - }, - }); - expect(authService.getEou).toHaveBeenCalledTimes(1); - expect(dateService.fixDatesV2).toHaveBeenCalledOnceWith(res.data[0]); - done(); - }); - }); - - it('getMyExpensesCount(): should return my expenses count', (done) => { - spyOn(transactionService, 'getMyExpenses').and.returnValue(of(expenseV2Data)); - - const params = { - tx_report_id: 'is.null', - tx_state: 'in.(COMPLETE,DRAFT)', - }; - - transactionService.getMyExpensesCount(params).subscribe((res) => { - expect(res).toEqual(expenseV2Data.count); - expect(transactionService.getMyExpenses).toHaveBeenCalledOnceWith({ - offset: 0, - limit: 1, - queryParams: params, - }); - done(); - }); - }); - - it('getAllExpenses(): should return all expenses', (done) => { - spyOn(transactionService, 'getMyExpensesCount').and.returnValue(of(2)); - spyOn(transactionService, 'getMyExpenses').and.returnValue(of(expenseV2DataMultiple)); - - const params = { - queryParams: { - tx_report_id: 'is.null', - tx_state: 'in.(COMPLETE)', - order: 'tx_txn_dt.desc', - or: ['(tx_policy_amount.is.null,tx_policy_amount.gt.0.0001)'], - }, - }; - - transactionService.getAllExpenses(params).subscribe((res) => { - expect(res).toEqual(expenseV2DataMultiple.data); - expect(transactionService.getMyExpensesCount).toHaveBeenCalledOnceWith(params.queryParams); - expect(transactionService.getMyExpenses).toHaveBeenCalledOnceWith({ - offset: 0, - limit: 2, - queryParams: params.queryParams, - order: undefined, - }); - done(); - }); - }); - it('unmatchCCCExpense(): should unmatch ccc expense', (done) => { spenderPlatformV1ApiService.post.and.returnValue(of(unmatchCCCExpenseResponseData)); diff --git a/src/app/core/services/transaction.service.ts b/src/app/core/services/transaction.service.ts index 8afe1b45db..98d1ac90cb 100644 --- a/src/app/core/services/transaction.service.ts +++ b/src/app/core/services/transaction.service.ts @@ -4,8 +4,6 @@ import { DateService } from './date.service'; import { map, switchMap, concatMap, reduce, tap } from 'rxjs/operators'; import { StorageService } from './storage.service'; import { from, Observable, range, forkJoin, of } from 'rxjs'; -import { ApiV2Service } from './api-v2.service'; -import { AuthService } from './auth.service'; import { OrgUserSettingsService } from './org-user-settings.service'; import { TimezoneService } from 'src/app/core/services/timezone.service'; import { UtilityService } from 'src/app/core/services/utility.service'; @@ -22,8 +20,6 @@ import { AccountsService } from './accounts.service'; import { SpenderPlatformV1ApiService } from './spender-platform-v1-api.service'; import { PlatformPolicyExpense } from '../models/platform/platform-policy-expense.model'; import { ExpensePolicy } from '../models/platform/platform-expense-policy.model'; -import { EtxnParams } from '../models/etxn-params.model'; -import { ApiV2Response } from '../models/v2/api-v2-response.model'; import { Transaction } from '../models/v1/transaction.model'; import { FileObject } from '../models/file-obj.model'; import { UnflattenedTransaction } from '../models/unflattened-transaction.model'; @@ -40,7 +36,6 @@ import { CorporateCardTransactionRes } from '../models/platform/v1/corporate-car import { ExpenseFilters } from '../models/expense-filters.model'; import { ExpensesService } from './platform/v1/spender/expenses.service'; import { expensesCacheBuster$ } from '../cache-buster/expense-cache-buster'; -import { LaunchDarklyService } from './launch-darkly.service'; import { FilterState } from '../enums/filter-state.enum'; import { PaymentMode } from '../models/payment-mode.model'; @@ -54,9 +49,7 @@ export class TransactionService { @Inject(PAGINATION_SIZE) private paginationSize: number, private storageService: StorageService, private apiService: ApiService, - private apiV2Service: ApiV2Service, private dateService: DateService, - private authService: AuthService, private orgUserSettingsService: OrgUserSettingsService, private timezoneService: TimezoneService, private utilityService: UtilityService, @@ -65,8 +58,7 @@ export class TransactionService { private paymentModesService: PaymentModesService, private orgSettingsService: OrgSettingsService, private accountsService: AccountsService, - private expensesService: ExpensesService, - private ldService: LaunchDarklyService + private expensesService: ExpensesService ) { expensesCacheBuster$.subscribe(() => { if (this.clearTaskCache) { @@ -92,71 +84,6 @@ export class TransactionService { ); } - @Cacheable({ - cacheBusterObserver: expensesCacheBuster$, - }) - - // TODO: Remove/Update method once we remove older my-expenses-page completely - getMyExpenses( - config: Partial<{ offset: number; limit: number; order: string; queryParams: EtxnParams }> = { - offset: 0, - limit: 10, - queryParams: {}, - } - ): Observable> { - return from(this.authService.getEou()).pipe( - switchMap((eou) => - this.apiV2Service.get('/expenses', { - params: { - offset: config.offset, - limit: config.limit, - order: `${config.order || 'tx_txn_dt.desc'},tx_created_at.desc,tx_id.desc`, - tx_org_user_id: 'eq.' + eou.ou.id, - ...config.queryParams, - }, - }) - ), - map( - (res) => - res as { - count: number; - data: Expense[]; - limit: number; - offset: number; - url: string; - } - ), - map((res) => ({ - ...res, - data: res.data.map((datum: Expense) => this.dateService.fixDatesV2(datum)), - })) - ); - } - - @Cacheable({ - cacheBusterObserver: expensesCacheBuster$, - }) - - // TODO: Remove/Update method once we remove older my-expenses-page completely - getAllExpenses(config: Partial<{ order: string; queryParams: EtxnParams }>): Observable { - return this.getMyExpensesCount(config.queryParams).pipe( - switchMap((count) => { - count = count > this.paginationSize ? count / this.paginationSize : 1; - return range(0, count); - }), - concatMap((page) => - this.getMyExpenses({ - offset: this.paginationSize * page, - limit: this.paginationSize, - queryParams: config.queryParams, - order: config.order, - }) - ), - map((res) => res.data), - reduce((acc, curr) => acc.concat(curr), [] as Expense[]) - ); - } - @Cacheable({ cacheBusterObserver: expensesCacheBuster$, }) @@ -278,15 +205,6 @@ export class TransactionService { ); } - // TODO: Remove/Update method once we remove older my-expenses-page completely - getMyExpensesCount(queryParams: EtxnParams): Observable { - return this.getMyExpenses({ - offset: 0, - limit: 1, - queryParams, - }).pipe(map((res) => res.count)); - } - checkMandatoryFields(platformPolicyExpense: PlatformPolicyExpense): Observable { const payload = { data: platformPolicyExpense, @@ -487,7 +405,7 @@ export class TransactionService { if (stateOrFilter.length > 0) { let combinedStateOrFilter = stateOrFilter.reduce((param1, param2) => `${param1}, ${param2}`); combinedStateOrFilter = `(${combinedStateOrFilter})`; - newQueryParamsCopy.or.push(combinedStateOrFilter); + (newQueryParamsCopy.or as string[]).push(combinedStateOrFilter); } return newQueryParamsCopy; @@ -528,11 +446,11 @@ export class TransactionService { const newQueryParamsCopy = cloneDeep(newQueryParams); if (filters.splitExpense) { if (filters.splitExpense === 'YES') { - newQueryParamsCopy.or.push('(tx_is_split_expense.eq.true)'); + (newQueryParamsCopy.or as string[]).push('(tx_is_split_expense.eq.true)'); } if (filters.splitExpense === 'NO') { - newQueryParamsCopy.or.push('(tx_is_split_expense.eq.false)'); + (newQueryParamsCopy.or as string[]).push('(tx_is_split_expense.eq.false)'); } } @@ -572,7 +490,7 @@ export class TransactionService { if (typeOrFilter.length > 0) { let combinedTypeOrFilter = typeOrFilter.reduce((param1, param2) => `${param1}, ${param2}`); combinedTypeOrFilter = `(${combinedTypeOrFilter})`; - newQueryParamsCopy.or.push(combinedTypeOrFilter); + (newQueryParamsCopy.or as string[]).push(combinedTypeOrFilter); } return newQueryParamsCopy; diff --git a/src/app/fyle/my-create-report/my-create-report.page.spec.ts b/src/app/fyle/my-create-report/my-create-report.page.spec.ts index 73eae509bc..2812aa54b6 100644 --- a/src/app/fyle/my-create-report/my-create-report.page.spec.ts +++ b/src/app/fyle/my-create-report/my-create-report.page.spec.ts @@ -403,7 +403,6 @@ describe('MyCreateReportPage', () => { it('ionViewWillEnter(): should setup expenses', fakeAsync(() => { loaderService.showLoader.and.resolveTo(); loaderService.hideLoader.and.resolveTo(); - transactionService.getAllExpenses.and.returnValue(of(cloneDeep(selectedExpenses))); expensesService.getAllExpenses.and.returnValue(of(readyToReportExpensesData)); orgSettingsService.get.and.returnValue(of(orgSettingsPendingRestrictions)); spyOn(component, 'getReportTitle').and.returnValue(null); @@ -432,7 +431,6 @@ describe('MyCreateReportPage', () => { beforeEach(() => { loaderService.showLoader.and.resolveTo(); loaderService.hideLoader.and.resolveTo(); - transactionService.getAllExpenses.and.returnValue(of(cloneDeep(selectedExpenses))); const mockSelectedExpense = cloneDeep(readyToReportExpensesData); mockSelectedExpense[0].matched_corporate_card_transaction_ids = []; mockSelectedExpense[1].matched_corporate_card_transactions[0].status = ExpenseTransactionStatus.PENDING; diff --git a/src/app/fyle/my-expenses/my-expenses.page.spec.ts b/src/app/fyle/my-expenses/my-expenses.page.spec.ts index 3c946345a5..4f7ce7f288 100644 --- a/src/app/fyle/my-expenses/my-expenses.page.spec.ts +++ b/src/app/fyle/my-expenses/my-expenses.page.spec.ts @@ -774,24 +774,6 @@ describe('MyExpensesPage', () => { expect(component.acc).toEqual(apiExpenses1); })); - it('should not call getMyExpenses if count is less than (params.pageNumber - 1) * 10', fakeAsync(() => { - transactionService.getMyExpensesCount.and.returnValue(of(0)); - component.ionViewWillEnter(); - expect(inputElement.value).toEqual(''); - inputElement.value = 'example'; - inputElement.dispatchEvent(new Event('keyup')); - tick(500); - - expect(expensesService.getExpensesCount).toHaveBeenCalledTimes(5); - expect(expensesService.getExpensesCount).toHaveBeenCalledWith({ - report_id: 'is.null', - state: 'in.(COMPLETE,DRAFT)', - }); - expect(component.clusterDomain).toEqual(apiAuthRes.cluster_domain); - expect(transactionService.getMyExpenses).not.toHaveBeenCalled(); - expect(component.acc).toEqual(apiExpenses1); - })); - it('should call getMyExpenseCount with order if sortDir and sortParam are defined', fakeAsync(() => { component.ionViewWillEnter(); component.loadExpenses$.next({ diff --git a/src/app/fyle/personal-cards-matched-expenses/expense-preview/expense-preview.component.html b/src/app/fyle/personal-cards-matched-expenses/expense-preview/expense-preview.component.html index d68ef2a83e..9c0842919a 100644 --- a/src/app/fyle/personal-cards-matched-expenses/expense-preview/expense-preview.component.html +++ b/src/app/fyle/personal-cards-matched-expenses/expense-preview/expense-preview.component.html @@ -24,7 +24,7 @@ @@ -34,7 +34,7 @@
- {{ expenseDetails.tx_amount | currency : expenseDetails.tx_currency : 'symbol-narrow' }} + {{ expenseDetails.amount | currency : expenseDetails.currency : 'symbol-narrow' }}
@@ -44,7 +44,7 @@
- {{ expenseDetails.tx_created_at | date : 'MMM dd, YYYY' }} + {{ expenseDetails.created_at | date : 'MMM dd, YYYY' }}
@@ -54,7 +54,7 @@
- {{ expenseDetails.tx_txn_dt | date : 'MMM dd, YYYY' }} + {{ expenseDetails.spent_at | date : 'MMM dd, YYYY' }}
@@ -64,8 +64,8 @@
- {{ expenseDetails.tx_vendor }} - - + {{ expenseDetails.merchant }} + -
@@ -75,7 +75,7 @@
- {{ expenseDetails.tx_org_category }} + {{ expenseDetails.category?.name }}
@@ -95,7 +95,7 @@
- Not Attached - Attached diff --git a/src/app/fyle/personal-cards-matched-expenses/expense-preview/expense-preview.component.spec.ts b/src/app/fyle/personal-cards-matched-expenses/expense-preview/expense-preview.component.spec.ts index 7c00b966e1..a85cae1e58 100644 --- a/src/app/fyle/personal-cards-matched-expenses/expense-preview/expense-preview.component.spec.ts +++ b/src/app/fyle/personal-cards-matched-expenses/expense-preview/expense-preview.component.spec.ts @@ -11,8 +11,9 @@ import { MatIconModule } from '@angular/material/icon'; import { MatIconTestingModule } from '@angular/material/icon/testing'; import { ExpensePreviewShimmerComponent } from '../expense-preview-shimmer/expense-preview-shimmer.component'; import { of } from 'rxjs'; -import { etxncData } from 'src/app/core/mock-data/expense.data'; import { ToastMessageComponent } from 'src/app/shared/components/toast-message/toast-message.component'; +import { ExpensesService } from 'src/app/core/services/platform/v1/spender/expenses.service'; +import { apiExpenses1 } from 'src/app/core/mock-data/platform/v1/expense.data'; describe('ExpensePreviewComponent', () => { let component: ExpensePreviewComponent; @@ -24,6 +25,7 @@ describe('ExpensePreviewComponent', () => { let snackbarProperties: jasmine.SpyObj; let platform: jasmine.SpyObj; let trackingService: jasmine.SpyObj; + let expensesService: jasmine.SpyObj; beforeEach(waitForAsync(() => { const modalControllerSpy = jasmine.createSpyObj('ModalController', ['dismiss']); @@ -40,7 +42,7 @@ describe('ExpensePreviewComponent', () => { 'oldExpensematchedFromPersonalCard', 'unmatchedExpensesFromPersonalCard', ]); - + const expensesServiceSpy = jasmine.createSpyObj('ExpensesService', ['getExpenses']); TestBed.configureTestingModule({ declarations: [ExpensePreviewComponent, ExpensePreviewShimmerComponent], imports: [IonicModule.forRoot(), MatIconModule, MatIconTestingModule, FormsModule, MatSnackBarModule], @@ -52,6 +54,7 @@ describe('ExpensePreviewComponent', () => { { provide: PersonalCardsService, useValue: personalCardsServiceSpy }, { provide: Platform, useValue: platformSpy }, { provide: TrackingService, useValue: trackingServiceSpy }, + { provide: ExpensesService, useValue: expensesServiceSpy }, ], }).compileComponents(); @@ -61,45 +64,46 @@ describe('ExpensePreviewComponent', () => { personalCardsService = TestBed.inject(PersonalCardsService) as jasmine.SpyObj; platform = TestBed.inject(Platform) as jasmine.SpyObj; trackingService = TestBed.inject(TrackingService) as jasmine.SpyObj; + expensesService = TestBed.inject(ExpensesService) as jasmine.SpyObj; snackbarProperties = TestBed.inject(SnackbarPropertiesService) as jasmine.SpyObj; fixture = TestBed.createComponent(ExpensePreviewComponent); component = fixture.componentInstance; - const expense = { id: 'txOJVaaPxo9O' }; - component.expenseId = expense; + component.expenseId = 'txOJVaaPxo9O'; fixture.detectChanges(); })); it('should create', () => { expect(component).toBeTruthy(); }); + describe('onInit():', () => { it('should set isIos to true if the platform is iOS', () => { platform.is.and.returnValue(true); component.ngOnInit(); - expect(component.isIos).toBe(true); + expect(component.isIos).toBeTrue(); }); it('should set isIos to false if the platform is not iOS', () => { platform.is.and.returnValue(false); component.ngOnInit(); - expect(component.isIos).toBe(false); + expect(component.isIos).toBeFalse(); }); }); it('ionViewWillEnter(): should get personal card expense details', (done) => { - personalCardsService.getExpenseDetails.and.returnValue(of(etxncData.data[0])); + expensesService.getExpenses.and.returnValue(of(apiExpenses1)); component.ionViewWillEnter(); component.expenseDetails$.subscribe((result) => { - expect(result).toEqual(etxncData.data[0]); - expect(personalCardsService.getExpenseDetails).toHaveBeenCalledOnceWith(component.expenseId); + expect(result).toEqual(apiExpenses1[0]); + expect(expensesService.getExpenses).toHaveBeenCalledOnceWith({ split_group_id: `eq.${component.expenseId}` }); done(); }); }); it('editExpense(): should navigate to the add-edit-expense page and edit expense', () => { - const modalControllerDismissSpy = modalController.dismiss.and.returnValue(Promise.resolve(true)); + const modalControllerDismissSpy = modalController.dismiss.and.resolveTo(true); component.editExpense(); expect(router.navigate).toHaveBeenCalledOnceWith([ '/', @@ -111,7 +115,7 @@ describe('ExpensePreviewComponent', () => { }); it('closeModal(): should dismiss the modal', () => { - const modalControllerDismissSpy = modalController.dismiss.and.returnValue(Promise.resolve(true)); + const modalControllerDismissSpy = modalController.dismiss.and.resolveTo(true); component.closeModal(); expect(modalControllerDismissSpy).toHaveBeenCalledTimes(1); }); diff --git a/src/app/fyle/personal-cards-matched-expenses/expense-preview/expense-preview.component.ts b/src/app/fyle/personal-cards-matched-expenses/expense-preview/expense-preview.component.ts index 948a490e9f..00718d5db0 100644 --- a/src/app/fyle/personal-cards-matched-expenses/expense-preview/expense-preview.component.ts +++ b/src/app/fyle/personal-cards-matched-expenses/expense-preview/expense-preview.component.ts @@ -1,12 +1,15 @@ import { Component, Input, OnInit } from '@angular/core'; import { Router } from '@angular/router'; import { ModalController, Platform } from '@ionic/angular'; -import { finalize } from 'rxjs/operators'; +import { finalize, map } from 'rxjs/operators'; import { PersonalCardsService } from 'src/app/core/services/personal-cards.service'; import { MatSnackBar } from '@angular/material/snack-bar'; import { SnackbarPropertiesService } from 'src/app/core/services/snackbar-properties.service'; import { ToastMessageComponent } from 'src/app/shared/components/toast-message/toast-message.component'; import { TrackingService } from 'src/app/core/services/tracking.service'; +import { ExpensesService } from 'src/app/core/services/platform/v1/spender/expenses.service'; +import { Observable } from 'rxjs'; +import { Expense } from 'src/app/core/models/platform/v1/expense.model'; @Component({ selector: 'app-expense-preview', @@ -14,13 +17,13 @@ import { TrackingService } from 'src/app/core/services/tracking.service'; styleUrls: ['./expense-preview.component.scss'], }) export class ExpensePreviewComponent implements OnInit { - @Input() expenseId; + @Input() expenseId: string; - @Input() card; + @Input() card: string; - @Input() cardTxnId; + @Input() cardTxnId: string; - expenseDetails$; + expenseDetails$: Observable; loading = false; @@ -37,22 +40,27 @@ export class ExpensePreviewComponent implements OnInit { private matSnackBar: MatSnackBar, private snackbarProperties: SnackbarPropertiesService, private platform: Platform, - private trackingService: TrackingService + private trackingService: TrackingService, + private expensesService: ExpensesService ) {} ngOnInit(): void { this.isIos = this.platform.is('ios'); } - ionViewWillEnter() { - this.expenseDetails$ = this.personalCardsService.getExpenseDetails(this.expenseId); + ionViewWillEnter(): void { + const params = { + split_group_id: `eq.${this.expenseId}`, + }; + + this.expenseDetails$ = this.expensesService.getExpenses(params).pipe(map((res) => res[0])); } - closeModal() { + closeModal(): void { this.modalController.dismiss(); } - matchExpense() { + matchExpense(): void { this.loading = true; this.personalCardsService .matchExpense(this.expenseId, this.cardTxnId) @@ -68,7 +76,7 @@ export class ExpensePreviewComponent implements OnInit { }); } - unmatchExpense() { + unmatchExpense(): void { this.unMatching = true; this.personalCardsService .unmatchExpense(this.expenseId, this.cardTxnId) @@ -86,7 +94,7 @@ export class ExpensePreviewComponent implements OnInit { }); } - editExpense() { + editExpense(): void { this.modalController.dismiss(); this.router.navigate([ '/', diff --git a/src/app/fyle/personal-cards-matched-expenses/personal-cards-matched-expenses.page.ts b/src/app/fyle/personal-cards-matched-expenses/personal-cards-matched-expenses.page.ts index 6bf788ec64..e5b1e35436 100644 --- a/src/app/fyle/personal-cards-matched-expenses/personal-cards-matched-expenses.page.ts +++ b/src/app/fyle/personal-cards-matched-expenses/personal-cards-matched-expenses.page.ts @@ -1,4 +1,4 @@ -import { Component, OnInit } from '@angular/core'; +import { Component } from '@angular/core'; import { HeaderState } from '../../shared/components/fy-header/header-state.enum'; import { PersonalCardsService } from 'src/app/core/services/personal-cards.service'; import { Router } from '@angular/router'; @@ -6,17 +6,18 @@ import { ModalController } from '@ionic/angular'; import { ExpensePreviewComponent } from './expense-preview/expense-preview.component'; import { ModalPropertiesService } from 'src/app/core/services/modal-properties.service'; import * as dayjs from 'dayjs'; +import { PersonalCardTxn } from 'src/app/core/models/personal_card_txn.model'; @Component({ selector: 'app-personal-cards-matched-expenses', templateUrl: './personal-cards-matched-expenses.page.html', styleUrls: ['./personal-cards-matched-expenses.page.scss'], }) -export class PersonalCardsMatchedExpensesPage implements OnInit { +export class PersonalCardsMatchedExpensesPage { headerState: HeaderState = HeaderState.base; navigateBack = true; - txnDetails: any = {}; + txnDetails: PersonalCardTxn; matchedExpenses$; @@ -26,17 +27,15 @@ export class PersonalCardsMatchedExpensesPage implements OnInit { private modalController: ModalController, private modalProperties: ModalPropertiesService ) { - this.txnDetails = this.router.getCurrentNavigation().extras.state.txnDetails; + this.txnDetails = this.router.getCurrentNavigation().extras.state.txnDetails as PersonalCardTxn; } - ngOnInit() {} - - ionViewWillEnter() { + ionViewWillEnter(): void { const txnDate = dayjs(this.txnDetails.btxn_transaction_dt).format('YYYY-MM-DD'); this.matchedExpenses$ = this.personalCardsService.getMatchedExpenses(this.txnDetails.btxn_amount, txnDate); } - createExpense() { + createExpense(): void { this.router.navigate([ '/', 'enterprise', @@ -45,7 +44,7 @@ export class PersonalCardsMatchedExpensesPage implements OnInit { ]); } - async openExpensePreview(expenseId) { + async openExpensePreview(expenseId: string): Promise { const expenseDetailsModal = await this.modalController.create({ component: ExpensePreviewComponent, componentProps: { diff --git a/src/app/fyle/personal-cards/personal-cards.page.spec.ts b/src/app/fyle/personal-cards/personal-cards.page.spec.ts index e897750072..7087842dd7 100644 --- a/src/app/fyle/personal-cards/personal-cards.page.spec.ts +++ b/src/app/fyle/personal-cards/personal-cards.page.spec.ts @@ -40,6 +40,7 @@ import { SnackbarPropertiesService } from '../../core/services/snackbar-properti import { ExpensePreviewComponent } from '../personal-cards-matched-expenses/expense-preview/expense-preview.component'; import { DateRangeModalComponent } from './date-range-modal/date-range-modal.component'; import { PersonalCardsPage } from './personal-cards.page'; +import { PersonalCardFilter } from 'src/app/core/models/personal-card-filters.model'; describe('PersonalCardsPage', () => { let component: PersonalCardsPage; @@ -264,7 +265,7 @@ describe('PersonalCardsPage', () => { data: { icon: 'check-square-fill', showCloseButton: false, - message: message, + message, }, duration: 3000, }; @@ -295,7 +296,7 @@ describe('PersonalCardsPage', () => { data: { icon: 'check-square-fill', showCloseButton: false, - message: message, + message, }, duration: 3000, }; @@ -815,7 +816,7 @@ describe('PersonalCardsPage', () => { }); modalController.create.and.resolveTo(modalSpy); personalCardsService.generateSelectedFilters.and.returnValue(selectedFilters1); - personalCardsService.convertFilters.and.returnValue({}); + personalCardsService.convertFilters.and.returnValue({} as PersonalCardFilter); spyOn(component, 'addNewFiltersToParams').and.returnValue(tasksQueryParamsWithFiltersData3); personalCardsService.generateFilterPills.and.returnValue(creditTxnFilterPill); spyOn(component.loadData$, 'next'); diff --git a/src/app/fyle/personal-cards/personal-cards.page.ts b/src/app/fyle/personal-cards/personal-cards.page.ts index 5befa73b2e..999cc64afa 100644 --- a/src/app/fyle/personal-cards/personal-cards.page.ts +++ b/src/app/fyle/personal-cards/personal-cards.page.ts @@ -46,7 +46,6 @@ import { SnackbarPropertiesService } from 'src/app/core/services/snackbar-proper import { TrackingService } from 'src/app/core/services/tracking.service'; import { ExpensePreviewComponent } from '../personal-cards-matched-expenses/expense-preview/expense-preview.component'; import { MatCheckboxChange } from '@angular/material/checkbox'; -import { GetTasksQueryParamsWithFilters } from 'src/app/core/models/get-tasks-query-params-with-filters.model'; import { DateFilters } from 'src/app/shared/components/fy-filters/date-filters.enum'; import { FilterOptionType } from 'src/app/shared/components/fy-filters/filter-option-type.enum'; import { FilterOptions } from 'src/app/shared/components/fy-filters/filter-options.interface'; @@ -54,22 +53,11 @@ import { FyFiltersComponent } from 'src/app/shared/components/fy-filters/fy-filt import { SelectedFilters } from 'src/app/shared/components/fy-filters/selected-filters.interface'; import { Expense } from 'src/app/core/models/expense.model'; import { ToastMessageComponent } from 'src/app/shared/components/toast-message/toast-message.component'; +import { SortFiltersParams } from 'src/app/core/models/sort-filters-params.model'; +import { PersonalCardFilter } from 'src/app/core/models/personal-card-filters.model'; // eslint-disable-next-line custom-rules/prefer-semantic-extension-name -type Filters = Partial<{ - amount: number; - createdOn: Partial<{ - name?: string; - customDateStart?: Date; - customDateEnd?: Date; - }>; - updatedOn: Partial<{ - name?: string; - customDateStart?: Date; - customDateEnd?: Date; - }>; - transactionType: string; -}>; +type Filters = Partial; @Component({ selector: 'app-personal-cards', @@ -89,15 +77,7 @@ export class PersonalCardsPage implements OnInit, AfterViewInit { loadCardData$: BehaviorSubject<{}> = new BehaviorSubject({}); - loadData$: BehaviorSubject< - Partial<{ - pageNumber: number; - queryParams: Record; - sortParam: string; - sortDir: string; - searchString: string; - }> - > = new BehaviorSubject({ + loadData$: BehaviorSubject> = new BehaviorSubject({ pageNumber: 1, }); @@ -666,11 +646,11 @@ export class PersonalCardsPage implements OnInit, AfterViewInit { }, 500); } - addNewFiltersToParams(): Partial { + addNewFiltersToParams(): Partial { const currentParams = this.loadData$.getValue(); currentParams.pageNumber = 1; - const newQueryParams: Record = { + const newQueryParams: { or: string[]; btxn_status?: string; ba_id?: string } = { or: [], }; newQueryParams.btxn_status = `in.(${this.selectedTrasactionType})`; @@ -741,7 +721,7 @@ export class PersonalCardsPage implements OnInit, AfterViewInit { } clearFilters(): void { - this.filters = {}; + this.filters = {} as PersonalCardFilter; this.currentPageNumber = 1; const params = this.addNewFiltersToParams(); this.loadData$.next(params);