Skip to content
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

feat: migrate to platform files api in view expense page #2920

Merged
merged 29 commits into from
May 27, 2024
Merged
Changes from 13 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
552cd65
minor
Chethan-Fyle Apr 25, 2024
09cba8d
Merge branch 'master' into fyle-86cv7bcfq
Chethan-Fyle Apr 28, 2024
fa40e1d
Merge branch 'master' into fyle-86cv7bcfq
Chethan-Fyle Apr 29, 2024
0b678f4
minor
Chethan-Fyle Apr 29, 2024
4f33e4c
Merge branch 'master' into fyle-86cv7bcfq
Chethan-Fyle Apr 29, 2024
0835c29
minor
Chethan-Fyle Apr 29, 2024
978c828
minor
Chethan-Fyle Apr 30, 2024
81c065b
minor
Chethan-Fyle Apr 30, 2024
59fb5bd
Merge branch 'fyle-86cv7bcfq' into fyle-86cv5kvqp-2
Chethan-Fyle Apr 30, 2024
bd52292
Merge branch 'master' into fyle-86cv5kvqp-2
Chethan-Fyle Apr 30, 2024
c4c349b
Merge branch 'master' into fyle-86cv5kvqp-2
Chethan-Fyle May 6, 2024
18c9c2d
minor
Chethan-Fyle May 6, 2024
789f5ed
minor
Chethan-Fyle May 6, 2024
6df56eb
minor
Chethan-Fyle May 6, 2024
6735b4f
minor
Chethan-Fyle May 6, 2024
735a361
Merge branch 'master' into fyle-86cv5kvqp-2
Chethan-Fyle May 22, 2024
fd9934e
minor
Chethan-Fyle May 22, 2024
a198ebb
test: updated view expense page unit test to reflect files api migrat…
Chethan-Fyle May 22, 2024
8dc7bd8
Merge branch 'master' into fyle-86cv5kvqp-2
Chethan-Fyle May 23, 2024
d069258
Merge branch 'master' into fyle-86cv5kvqp-2
Chethan-Fyle May 23, 2024
4f7f1f4
minor
Chethan-Fyle May 23, 2024
3efa816
minor
Chethan-Fyle May 23, 2024
fc4f2e4
minor
Chethan-Fyle May 24, 2024
cc1cb5c
minor
Chethan-Fyle May 24, 2024
ee84885
minor
Chethan-Fyle May 24, 2024
81e0f32
minor
Chethan-Fyle May 24, 2024
ed1c434
minor
Chethan-Fyle May 24, 2024
db77503
minor
Chethan-Fyle May 27, 2024
a018b3b
Merge branch 'master' into fyle-86cv5kvqp-2
Chethan-Fyle May 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 33 additions & 17 deletions src/app/fyle/view-expense/view-expense.page.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Component, EventEmitter, ViewChild, ElementRef } from '@angular/core';
import { Observable, from, Subject, concat, noop, forkJoin } from 'rxjs';
import { Observable, from, Subject, concat, noop, forkJoin, of } from 'rxjs';
import { LoaderService } from 'src/app/core/services/loader.service';
import { TransactionService } from 'src/app/core/services/transaction.service';
import { ActivatedRoute, Router } from '@angular/router';
import { CustomInputsService } from 'src/app/core/services/custom-inputs.service';
import { switchMap, shareReplay, concatMap, map, finalize, reduce, takeUntil, take, filter } from 'rxjs/operators';

Check failure on line 7 in src/app/fyle/view-expense/view-expense.page.ts

View workflow job for this annotation

GitHub Actions / Run linters

'reduce' is defined but never used
import { StatusService } from 'src/app/core/services/status.service';
import { ReportService } from 'src/app/core/services/report.service';
import { FileService } from 'src/app/core/services/file.service';
Expand Down Expand Up @@ -35,6 +35,9 @@
import { AccountType } from 'src/app/core/models/platform/v1/account.model';
import { ExpenseState } from 'src/app/core/models/expense-state.enum';
import { TransactionStatusInfoPopoverComponent } from 'src/app/shared/components/transaction-status-info-popover/transaction-status-info-popover.component';
import { SpenderFileService } from 'src/app/core/services/platform/v1/spender/file.service';
import { ApproverFileService } from 'src/app/core/services/platform/v1/approver/file.service';
import { PlatformFileGenerateUrlsResponse } from 'src/app/core/models/platform/platform-file-generate-urls-response.model';

@Component({
selector: 'app-view-expense',
Expand Down Expand Up @@ -150,7 +153,9 @@
private categoriesService: CategoriesService,
private dependentFieldsService: DependentFieldsService,
private spenderExpensesService: SpenderExpensesService,
private approverExpensesService: ApproverExpensesService
private approverExpensesService: ApproverExpensesService,
private spenderFileService: SpenderFileService,
private approverFileService: ApproverFileService
) {}

get ExpenseView(): typeof ExpenseView {
Expand Down Expand Up @@ -411,22 +416,33 @@

const editExpenseAttachments = this.expense$.pipe(
take(1),
switchMap((expense) => from(expense.files)),
concatMap((fileObj) =>
this.fileService.downloadUrl(fileObj.id).pipe(
map((downloadUrl) => {
const details = this.fileService.getReceiptsDetails(fileObj.name, downloadUrl);
const fileObjWithDetails: FileObject = {
url: downloadUrl,
type: details.type,
thumbnail: details.thumbnail,
};
switchMap((expense) => {
if (expense.file_ids?.length > 0) {
if (this.view === ExpenseView.individual) {
return this.spenderFileService.generateUrlsBulk(expense.file_ids);
} else {
return this.approverFileService.generateUrlsBulk(expense.file_ids);
}
} else {
return of([]);
}
}),
map((response: PlatformFileGenerateUrlsResponse[]) => {
const files = response.filter((file) => file.content_type !== 'text/html');
const fileObjs = files.map((obj) => {
const details = this.fileService.getReceiptsDetails(obj.name, obj.download_url);

const fileObj: FileObject = {
url: obj.download_url,
type: details.type,
thumbnail: details.thumbnail,
};

return fileObj;
});

return fileObjWithDetails;
})
)
),
reduce((acc: FileObject[], curr) => acc.concat(curr), [])
return fileObjs;
})
);

this.attachments$ = editExpenseAttachments;
Expand Down
Loading