diff --git a/src/addons/mod/assign/services/assign-helper.ts b/src/addons/mod/assign/services/assign-helper.ts index 2da29183c..196d7607f 100644 --- a/src/addons/mod/assign/services/assign-helper.ts +++ b/src/addons/mod/assign/services/assign-helper.ts @@ -694,16 +694,40 @@ export class AddonModAssignHelperProvider { assignId: number, folderName: string, files: CoreFileEntry[], - offline = false, + offline: true, + userId?: number, + siteId?: string, + ): Promise; + async uploadOrStoreFiles( + assignId: number, + folderName: string, + files: CoreFileEntry[], + offline: false, + userId?: number, + siteId?: string, + ): Promise; + async uploadOrStoreFiles( + assignId: number, + folderName: string, + files: CoreFileEntry[], + offline: boolean, + userId?: number, + siteId?: string, + ): Promise; + async uploadOrStoreFiles( + assignId: number, + folderName: string, + files: CoreFileEntry[], + offline: boolean, userId?: number, siteId?: string, ): Promise { if (offline) { - return await this.storeSubmissionFiles(assignId, folderName, files, userId, siteId); + return this.storeSubmissionFiles(assignId, folderName, files, userId, siteId); } - return await this.uploadFiles(assignId, files, siteId); + return this.uploadFiles(assignId, files, siteId); } } diff --git a/src/addons/mod/assign/submission/file/services/handler.ts b/src/addons/mod/assign/submission/file/services/handler.ts index 72c93d843..f1b52ea2f 100644 --- a/src/addons/mod/assign/submission/file/services/handler.ts +++ b/src/addons/mod/assign/submission/file/services/handler.ts @@ -278,7 +278,7 @@ export class AddonModAssignSubmissionFileHandlerService implements AddonModAssig plugin: AddonModAssignPlugin, inputData: AddonModAssignSubmissionFileData, pluginData: AddonModAssignSubmissionFilePluginData, - offline?: boolean, + offline = false, userId?: number, siteId?: string, ): Promise { diff --git a/src/addons/mod/data/services/data-helper.ts b/src/addons/mod/data/services/data-helper.ts index ef3ba57d1..400ee6752 100644 --- a/src/addons/mod/data/services/data-helper.ts +++ b/src/addons/mod/data/services/data-helper.ts @@ -542,7 +542,7 @@ export class AddonModDataHelperProvider { dataId: number, entryId: number, entryContents: AddonModDataEntryFields, - offline: boolean = false, + offline = false, siteId?: string, ): Promise { if (!inputData) { @@ -766,6 +766,33 @@ export class AddonModDataHelperProvider { * @param siteId Site ID. If not defined, current site. * @return Promise resolved with the itemId for the uploaded file/s. */ + async uploadOrStoreFiles( + dataId: number, + itemId: number, + entryId: number, + fieldId: number, + files: CoreFileEntry[], + offline: true, + siteId?: string, + ): Promise; + async uploadOrStoreFiles( + dataId: number, + itemId: number, + entryId: number, + fieldId: number, + files: CoreFileEntry[], + offline: false, + siteId?: string, + ): Promise; + async uploadOrStoreFiles( + dataId: number, + itemId: number, + entryId: number, + fieldId: number, + files: CoreFileEntry[], + offline: boolean, + siteId?: string, + ): Promise; async uploadOrStoreFiles( dataId: number, itemId: number = 0, diff --git a/src/addons/mod/forum/components/post/post.ts b/src/addons/mod/forum/components/post/post.ts index cd394baf3..f08ae93e8 100644 --- a/src/addons/mod/forum/components/post/post.ts +++ b/src/addons/mod/forum/components/post/post.ts @@ -287,7 +287,7 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy, OnChanges const attachment = await AddonModForumHelper.uploadOrStoreReplyFiles( this.forum.id, this.post.id, - files, + files as CoreFileEntry[], false, ); diff --git a/src/addons/mod/forum/services/forum-helper.ts b/src/addons/mod/forum/services/forum-helper.ts index b3a570eef..140853e36 100644 --- a/src/addons/mod/forum/services/forum-helper.ts +++ b/src/addons/mod/forum/services/forum-helper.ts @@ -445,11 +445,17 @@ export class AddonModForumHelperProvider { * @param userId User the reply belongs to. If not defined, current user in site. * @return Promise resolved if success, rejected otherwise. */ - async storeReplyFiles(forumId: number, postId: number, files: any[], siteId?: string, userId?: number): Promise { + async storeReplyFiles( + forumId: number, + postId: number, + files: CoreFileEntry[], + siteId?: string, + userId?: number, + ): Promise { // Get the folder where to store the files. const folderPath = await AddonModForumOffline.getReplyFolder(forumId, postId, siteId, userId); - await CoreFileUploader.storeFilesToUpload(folderPath, files); + return CoreFileUploader.storeFilesToUpload(folderPath, files); } /** @@ -485,9 +491,9 @@ export class AddonModForumHelperProvider { ): Promise { if (offline) { return this.storeNewDiscussionFiles(forumId, timecreated, files, siteId); - } else { - return CoreFileUploader.uploadOrReuploadFiles(files, AddonModForumProvider.COMPONENT, forumId, siteId); } + + return CoreFileUploader.uploadOrReuploadFiles(files, AddonModForumProvider.COMPONENT, forumId, siteId); } /** @@ -501,19 +507,35 @@ export class AddonModForumHelperProvider { * @param userId User the reply belongs to. If not defined, current user in site. * @return Promise resolved if success. */ - uploadOrStoreReplyFiles( + async uploadOrStoreReplyFiles( forumId: number, postId: number, - files: any[], + files: CoreFileEntry[], + offline: true, + siteId?: string, + userId?: number, + ): Promise; + async uploadOrStoreReplyFiles( + forumId: number, + postId: number, + files: CoreFileEntry[], + offline: false, + siteId?: string, + userId?: number, + ): Promise; + async uploadOrStoreReplyFiles( + forumId: number, + postId: number, + files: CoreFileEntry[], offline: boolean, siteId?: string, userId?: number, - ): Promise { + ): Promise { if (offline) { return this.storeReplyFiles(forumId, postId, files, siteId, userId); - } else { - return CoreFileUploader.uploadOrReuploadFiles(files, AddonModForumProvider.COMPONENT, forumId, siteId); } + + return CoreFileUploader.uploadOrReuploadFiles(files, AddonModForumProvider.COMPONENT, forumId, siteId); } }