diff --git a/frontend/app/components/api/api-v3/hal-resources/attachment-collection-resource.service.ts b/frontend/app/components/api/api-v3/hal-resources/attachment-collection-resource.service.ts index 8a40c97d2c..23ba7fab23 100644 --- a/frontend/app/components/api/api-v3/hal-resources/attachment-collection-resource.service.ts +++ b/frontend/app/components/api/api-v3/hal-resources/attachment-collection-resource.service.ts @@ -31,7 +31,7 @@ import {CollectionResource} from './collection-resource.service'; import {HalResource} from './hal-resource.service'; import { OpenProjectFileUploadService, - UploadFile + UploadFile, UploadResult } from '../../op-file-upload/op-file-upload.service'; import IPromise = angular.IPromise; @@ -41,7 +41,7 @@ export class AttachmentCollectionResource extends CollectionResource { /** * Upload the given files to the $href property of this resource. */ - public upload(files: UploadFile[]): IPromise { + public upload(files: UploadFile[]): UploadResult { return opFileUpload.upload(this.$href, files); } } diff --git a/frontend/app/components/api/op-file-upload/op-file-upload.service.test.ts b/frontend/app/components/api/op-file-upload/op-file-upload.service.test.ts index e54f902f13..0a19b5edb0 100644 --- a/frontend/app/components/api/op-file-upload/op-file-upload.service.test.ts +++ b/frontend/app/components/api/op-file-upload/op-file-upload.service.test.ts @@ -80,8 +80,12 @@ describe('opFileUpload service', () => { })); }); - it('should return a resolved promise', () => { - expect(result).to.eventually.be.fulfilled; + it('should return a result object that contains each upload in an array', () => { + expect(result.uploads).to.have.length(files.length); + }); + + it('should return a resolved promise that is the summary of the uploads', () => { + expect(result.upload).to.eventually.be.fulfilled; }); }); }); diff --git a/frontend/app/components/api/op-file-upload/op-file-upload.service.ts b/frontend/app/components/api/op-file-upload/op-file-upload.service.ts index 5547d6e2e7..51c6758d8d 100644 --- a/frontend/app/components/api/op-file-upload/op-file-upload.service.ts +++ b/frontend/app/components/api/op-file-upload/op-file-upload.service.ts @@ -34,6 +34,11 @@ export interface UploadFile extends File { description: string; } +export interface UploadResult { + uploads: IPromise[]; + upload: IPromise; +} + export class OpenProjectFileUploadService { constructor(protected $q: IQService, protected Upload) { @@ -42,8 +47,8 @@ export class OpenProjectFileUploadService { /** * Upload multiple files using `ngFileUpload` and return a single promise. */ - public upload(url: string, files: UploadFile[]): IPromise { - return this.$q.all(_.map(files, (file: UploadFile) => this.Upload.upload({ + public upload(url: string, files: UploadFile[]): UploadResult { + const uploads = _.map(files, (file: UploadFile) => this.Upload.upload({ file, url, fields: { metadata: { @@ -51,7 +56,10 @@ export class OpenProjectFileUploadService { fileName: file.name, } } - }))); + })); + const upload = this.$q.all(uploads); + + return {uploads, upload}; } }