From 552cd65f0b625ff55b6f65f81a231be33b11794b Mon Sep 17 00:00:00 2001 From: Chethan Date: Thu, 25 Apr 2024 15:59:23 +0530 Subject: [PATCH 1/4] minor --- src/app/core/services/file.service.ts | 30 ++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/app/core/services/file.service.ts b/src/app/core/services/file.service.ts index bd3fb4ffde..c3754f1f9a 100644 --- a/src/app/core/services/file.service.ts +++ b/src/app/core/services/file.service.ts @@ -7,12 +7,20 @@ import { FileObject } from '../models/file-obj.model'; import { ReceiptInfo } from '../models/receipt-info.model'; import heic2any from 'heic2any'; import { DateService } from './date.service'; +import { SpenderPlatformV1ApiService } from './spender-platform-v1-api.service'; +import { PlatformFile } from '../models/platform/platform-file.model'; +import { PlatformFilePostRequestPayload } from '../models/platform/platform-file-post-request-payload.model'; +import { PlatformFileGenerateUrlsResponse } from '../models/platform/platform-file-generate-urls-response.model'; @Injectable({ providedIn: 'root', }) export class FileService { - constructor(private apiService: ApiService, private dateService: DateService) {} + constructor( + private apiService: ApiService, + private spenderPlatformV1ApiService: SpenderPlatformV1ApiService, + private dateService: DateService + ) {} downloadUrl(fileId: string): Observable { return this.apiService.post('/files/' + fileId + '/download_url').pipe(map((res) => res.url)); @@ -188,4 +196,24 @@ export class FileService { } return receiptInfo; } + + createFile(payload: PlatformFilePostRequestPayload): Observable { + return this.spenderPlatformV1ApiService.post('/files', payload); + } + + createFilesBulk(payload: PlatformFilePostRequestPayload[]): Observable { + return this.spenderPlatformV1ApiService.post('/files/bulk', payload); + } + + generateUrls(payload: { id: string }): Observable { + return this.spenderPlatformV1ApiService.post('/files/generate_urls', payload); + } + + generateUrlsBulk(payload: { id: string }[]): Observable { + return this.spenderPlatformV1ApiService.post('/files/generate_urls', payload); + } + + downloadFile(id: string) { + return this.spenderPlatformV1ApiService.get('/files/download?id=' + id); + } } From 0b678f44c9d37bb87b983d9ec4c0652f4a390e74 Mon Sep 17 00:00:00 2001 From: Chethan Date: Mon, 29 Apr 2024 22:02:10 +0530 Subject: [PATCH 2/4] minor --- src/app/core/services/file.service.ts | 30 +----------- .../platform/v1/approver/file.service.spec.ts | 16 +++++++ .../platform/v1/approver/file.service.ts | 48 +++++++++++++++++++ .../platform/v1/spender/file.service.spec.ts | 16 +++++++ .../platform/v1/spender/file.service.ts | 48 +++++++++++++++++++ 5 files changed, 129 insertions(+), 29 deletions(-) create mode 100644 src/app/core/services/platform/v1/approver/file.service.spec.ts create mode 100644 src/app/core/services/platform/v1/approver/file.service.ts create mode 100644 src/app/core/services/platform/v1/spender/file.service.spec.ts create mode 100644 src/app/core/services/platform/v1/spender/file.service.ts diff --git a/src/app/core/services/file.service.ts b/src/app/core/services/file.service.ts index c3754f1f9a..bd3fb4ffde 100644 --- a/src/app/core/services/file.service.ts +++ b/src/app/core/services/file.service.ts @@ -7,20 +7,12 @@ import { FileObject } from '../models/file-obj.model'; import { ReceiptInfo } from '../models/receipt-info.model'; import heic2any from 'heic2any'; import { DateService } from './date.service'; -import { SpenderPlatformV1ApiService } from './spender-platform-v1-api.service'; -import { PlatformFile } from '../models/platform/platform-file.model'; -import { PlatformFilePostRequestPayload } from '../models/platform/platform-file-post-request-payload.model'; -import { PlatformFileGenerateUrlsResponse } from '../models/platform/platform-file-generate-urls-response.model'; @Injectable({ providedIn: 'root', }) export class FileService { - constructor( - private apiService: ApiService, - private spenderPlatformV1ApiService: SpenderPlatformV1ApiService, - private dateService: DateService - ) {} + constructor(private apiService: ApiService, private dateService: DateService) {} downloadUrl(fileId: string): Observable { return this.apiService.post('/files/' + fileId + '/download_url').pipe(map((res) => res.url)); @@ -196,24 +188,4 @@ export class FileService { } return receiptInfo; } - - createFile(payload: PlatformFilePostRequestPayload): Observable { - return this.spenderPlatformV1ApiService.post('/files', payload); - } - - createFilesBulk(payload: PlatformFilePostRequestPayload[]): Observable { - return this.spenderPlatformV1ApiService.post('/files/bulk', payload); - } - - generateUrls(payload: { id: string }): Observable { - return this.spenderPlatformV1ApiService.post('/files/generate_urls', payload); - } - - generateUrlsBulk(payload: { id: string }[]): Observable { - return this.spenderPlatformV1ApiService.post('/files/generate_urls', payload); - } - - downloadFile(id: string) { - return this.spenderPlatformV1ApiService.get('/files/download?id=' + id); - } } diff --git a/src/app/core/services/platform/v1/approver/file.service.spec.ts b/src/app/core/services/platform/v1/approver/file.service.spec.ts new file mode 100644 index 0000000000..16c34a6d86 --- /dev/null +++ b/src/app/core/services/platform/v1/approver/file.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { ApproverFileService } from './file.service'; + +describe('ApproverFileService', () => { + let service: ApproverFileService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(ApproverFileService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/core/services/platform/v1/approver/file.service.ts b/src/app/core/services/platform/v1/approver/file.service.ts new file mode 100644 index 0000000000..70e7868a0e --- /dev/null +++ b/src/app/core/services/platform/v1/approver/file.service.ts @@ -0,0 +1,48 @@ +import { Injectable } from '@angular/core'; +import { Observable, map } from 'rxjs'; +import { PlatformFileGenerateUrlsResponse } from 'src/app/core/models/platform/platform-file-generate-urls-response.model'; +import { PlatformFilePostRequestPayload } from 'src/app/core/models/platform/platform-file-post-request-payload.model'; +import { PlatformFile } from 'src/app/core/models/platform/platform-file.model'; +import { PlatformApiResponse } from 'src/app/core/models/platform/platform-api-response.model'; +import { ApproverPlatformApiService } from '../../../approver-platform-api.service'; + +@Injectable({ + providedIn: 'root', +}) +export class ApproverFileService { + constructor(private approverPlatformApiService: ApproverPlatformApiService) {} + + createFile(payload: PlatformFilePostRequestPayload): Observable { + return this.approverPlatformApiService + .post>('/files', payload) + .pipe(map((response) => response.data)); + } + + createFilesBulk(payload: PlatformFilePostRequestPayload[]): Observable { + return this.approverPlatformApiService + .post>('/files/bulk', payload) + .pipe(map((response) => response.data)); + } + + generateUrls(id: string): Observable { + const payload = { + data: { id }, + }; + return this.approverPlatformApiService + .post>('/files/generate_urls', payload) + .pipe(map((response) => response.data)); + } + + generateUrlsBulk(fileIds: string[]): Observable { + const payload = { + data: fileIds.map((id) => ({ id })), + }; + return this.approverPlatformApiService + .post>('/files/generate_urls/bulk', payload) + .pipe(map((response) => response.data)); + } + + downloadFile(id: string) { + return this.approverPlatformApiService.get('/files/download?id=' + id); + } +} diff --git a/src/app/core/services/platform/v1/spender/file.service.spec.ts b/src/app/core/services/platform/v1/spender/file.service.spec.ts new file mode 100644 index 0000000000..0ea809b622 --- /dev/null +++ b/src/app/core/services/platform/v1/spender/file.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { SpenderFileService } from './file.service'; + +describe('SpenderFileService', () => { + let service: SpenderFileService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(SpenderFileService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/core/services/platform/v1/spender/file.service.ts b/src/app/core/services/platform/v1/spender/file.service.ts new file mode 100644 index 0000000000..c7af93bc40 --- /dev/null +++ b/src/app/core/services/platform/v1/spender/file.service.ts @@ -0,0 +1,48 @@ +import { Injectable } from '@angular/core'; +import { Observable, map } from 'rxjs'; +import { PlatformFileGenerateUrlsResponse } from 'src/app/core/models/platform/platform-file-generate-urls-response.model'; +import { PlatformFilePostRequestPayload } from 'src/app/core/models/platform/platform-file-post-request-payload.model'; +import { PlatformFile } from 'src/app/core/models/platform/platform-file.model'; +import { SpenderPlatformV1ApiService } from '../../../spender-platform-v1-api.service'; +import { PlatformApiResponse } from 'src/app/core/models/platform/platform-api-response.model'; + +@Injectable({ + providedIn: 'root', +}) +export class SpenderFileService { + constructor(private spenderPlatformV1ApiService: SpenderPlatformV1ApiService) {} + + createFile(payload: PlatformFilePostRequestPayload): Observable { + return this.spenderPlatformV1ApiService + .post>('/files', payload) + .pipe(map((response) => response.data)); + } + + createFilesBulk(payload: PlatformFilePostRequestPayload[]): Observable { + return this.spenderPlatformV1ApiService + .post>('/files/bulk', payload) + .pipe(map((response) => response.data)); + } + + generateUrls(id: string): Observable { + const payload = { + data: { id }, + }; + return this.spenderPlatformV1ApiService + .post>('/files/generate_urls', payload) + .pipe(map((response) => response.data)); + } + + generateUrlsBulk(fileIds: string[]): Observable { + const payload = { + data: fileIds.map((id) => ({ id })), + }; + return this.spenderPlatformV1ApiService + .post>('/files/generate_urls/bulk', payload) + .pipe(map((response) => response.data)); + } + + downloadFile(id: string) { + return this.spenderPlatformV1ApiService.get('/files/download?id=' + id); + } +} From 978c82832fa6e06576df8d4fb30656772093a5ed Mon Sep 17 00:00:00 2001 From: Chethan Date: Tue, 30 Apr 2024 12:51:33 +0530 Subject: [PATCH 3/4] minor --- src/app/core/services/platform/v1/approver/file.service.ts | 2 +- src/app/core/services/platform/v1/spender/file.service.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/core/services/platform/v1/approver/file.service.ts b/src/app/core/services/platform/v1/approver/file.service.ts index 70e7868a0e..0c07ae4164 100644 --- a/src/app/core/services/platform/v1/approver/file.service.ts +++ b/src/app/core/services/platform/v1/approver/file.service.ts @@ -42,7 +42,7 @@ export class ApproverFileService { .pipe(map((response) => response.data)); } - downloadFile(id: string) { + downloadFile(id: string): {} { return this.approverPlatformApiService.get('/files/download?id=' + id); } } diff --git a/src/app/core/services/platform/v1/spender/file.service.ts b/src/app/core/services/platform/v1/spender/file.service.ts index c7af93bc40..9dcad5634e 100644 --- a/src/app/core/services/platform/v1/spender/file.service.ts +++ b/src/app/core/services/platform/v1/spender/file.service.ts @@ -42,7 +42,7 @@ export class SpenderFileService { .pipe(map((response) => response.data)); } - downloadFile(id: string) { + downloadFile(id: string): {} { return this.spenderPlatformV1ApiService.get('/files/download?id=' + id); } } From 81c065b0423ffaba794829cc9265a5fbbac9c2c0 Mon Sep 17 00:00:00 2001 From: Chethan Date: Tue, 30 Apr 2024 14:29:46 +0530 Subject: [PATCH 4/4] minor --- .../platform/v1/approver/file.service.spec.ts | 16 ++++++++++++++-- .../platform/v1/spender/file.service.spec.ts | 16 ++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/app/core/services/platform/v1/approver/file.service.spec.ts b/src/app/core/services/platform/v1/approver/file.service.spec.ts index 16c34a6d86..497dbcfe2d 100644 --- a/src/app/core/services/platform/v1/approver/file.service.spec.ts +++ b/src/app/core/services/platform/v1/approver/file.service.spec.ts @@ -1,13 +1,25 @@ import { TestBed } from '@angular/core/testing'; - import { ApproverFileService } from './file.service'; +import { ApproverPlatformApiService } from '../../../approver-platform-api.service'; describe('ApproverFileService', () => { let service: ApproverFileService; + let approverPlatformApiService: jasmine.SpyObj; beforeEach(() => { - TestBed.configureTestingModule({}); + const approverPlatformApiServiceSpy = jasmine.createSpyObj('ApproverPlatformApiService', ['get', 'post']); + TestBed.configureTestingModule({ + providers: [ + { + provide: ApproverPlatformApiService, + useValue: approverPlatformApiServiceSpy, + }, + ], + }); service = TestBed.inject(ApproverFileService); + approverPlatformApiService = TestBed.inject( + ApproverPlatformApiService + ) as jasmine.SpyObj; }); it('should be created', () => { diff --git a/src/app/core/services/platform/v1/spender/file.service.spec.ts b/src/app/core/services/platform/v1/spender/file.service.spec.ts index 0ea809b622..7ea52382b3 100644 --- a/src/app/core/services/platform/v1/spender/file.service.spec.ts +++ b/src/app/core/services/platform/v1/spender/file.service.spec.ts @@ -1,13 +1,25 @@ import { TestBed } from '@angular/core/testing'; - import { SpenderFileService } from './file.service'; +import { SpenderPlatformV1ApiService } from '../../../spender-platform-v1-api.service'; describe('SpenderFileService', () => { let service: SpenderFileService; + let spenderPlatformV1ApiService: jasmine.SpyObj; beforeEach(() => { - TestBed.configureTestingModule({}); + const spenderPlatformV1ApiServiceSpy = jasmine.createSpyObj('SpenderPlatformV1ApiService', ['get', 'post']); + TestBed.configureTestingModule({ + providers: [ + { + provide: SpenderPlatformV1ApiService, + useValue: spenderPlatformV1ApiServiceSpy, + }, + ], + }); service = TestBed.inject(SpenderFileService); + spenderPlatformV1ApiService = TestBed.inject( + SpenderPlatformV1ApiService + ) as jasmine.SpyObj; }); it('should be created', () => {