-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathReplaceFile.ts
More file actions
28 lines (25 loc) · 1.51 KB
/
ReplaceFile.ts
File metadata and controls
28 lines (25 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { UseCase } from '../../../core/domain/useCases/UseCase'
import { UploadedFileDTO } from '../dtos/UploadedFileDTO'
import { IFilesRepository } from '../repositories/IFilesRepository'
export class ReplaceFile implements UseCase<number> {
private filesRepository: IFilesRepository
constructor(filesRepository: IFilesRepository) {
this.filesRepository = filesRepository
}
/**
* Replaces an existing file.
*
* This method completes the flow initiated by the UploadFile use case, which involves replacing an existing file with a new one just uploaded.
* (https://guides.dataverse.org/en/latest/developers/s3-direct-upload-api.html#replacing-an-existing-file-in-the-dataset)
*
* Note: This use case can be used independently of the UploadFile use case, e.g., supporting scenarios in which the files already exist in S3 or have been uploaded via some out-of-band method.
*
* @param {number | string} [fileId] - The File identifier, which can be a string (for persistent identifiers), or a number (for numeric identifiers).
* @param {UploadedFileDTO} [uploadedFileDTO] - File DTO associated with the uploaded file.
* @returns {Promise<number>} A promise that resolves when the file has been successfully replaced and returns the new file identifier.
* @throws {WriteError} - If there are errors while writing data.
*/
async execute(fileId: number | string, uploadedFileDTO: UploadedFileDTO): Promise<number> {
return await this.filesRepository.replaceFile(fileId, uploadedFileDTO)
}
}