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..497dbcfe2d --- /dev/null +++ b/src/app/core/services/platform/v1/approver/file.service.spec.ts @@ -0,0 +1,28 @@ +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(() => { + 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', () => { + 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..0c07ae4164 --- /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..7ea52382b3 --- /dev/null +++ b/src/app/core/services/platform/v1/spender/file.service.spec.ts @@ -0,0 +1,28 @@ +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(() => { + 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', () => { + 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..9dcad5634e --- /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); + } +}