Skip to content

Commit 48b9b6d

Browse files
committed
fix: add boolean parameter to restrict or unrestrict the file
1 parent 70c0469 commit 48b9b6d

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed

docs/useCases.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,7 @@ import { restrictFile } from '@iqss/dataverse-client-javascript'
12781278

12791279
const fileId = 12345
12801280

1281-
restrictFile.execute(fileId)
1281+
restrictFile.execute(fileId, true)
12821282

12831283
/* ... */
12841284
```

src/files/domain/repositories/IFilesRepository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,5 @@ export interface IFilesRepository {
6262

6363
deleteFile(fileId: number | string): Promise<undefined>
6464

65-
restrictFile(fileId: number | string): Promise<undefined>
65+
restrictFile(fileId: number | string, restrict: boolean): Promise<undefined>
6666
}

src/files/domain/useCases/RestrictFile.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ export class RestrictFile implements UseCase<void> {
99
* More detailed information about the file restriction behavior can be found in https://guides.dataverse.org/en/latest/api/native-api.html#restrict-files
1010
*
1111
* @param {number | string} [fileId] - The File identifier, which can be a string (for persistent identifiers), or a number (for numeric identifiers).
12+
* @param {boolean} [restrict] - A boolean value that indicates whether the file should be restricted or unrestricted.
1213
* @returns {Promise<void>} -This method does not return anything upon successful completion.
1314
*/
14-
async execute(fileId: number | string): Promise<void> {
15-
return await this.filesRepository.restrictFile(fileId)
15+
async execute(fileId: number | string, restrict: boolean): Promise<void> {
16+
return await this.filesRepository.restrictFile(fileId, restrict)
1617
}
1718
}

src/files/infra/repositories/FilesRepository.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,11 @@ export class FilesRepository extends ApiRepository implements IFilesRepository {
302302
})
303303
}
304304

305-
public async restrictFile(fileId: number | string): Promise<undefined> {
306-
return this.doPut(this.buildApiEndpoint(this.filesResourceName, 'restrict', fileId), {})
305+
public async restrictFile(fileId: number | string, restrict: boolean): Promise<undefined> {
306+
return this.doPut(
307+
this.buildApiEndpoint(this.filesResourceName, 'restrict', fileId),
308+
restrict ? 'true' : 'false'
309+
)
307310
.then(() => undefined)
308311
.catch((error) => {
309312
throw error

test/unit/files/RestrictFile.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('execute', () => {
99

1010
const sut = new RestrictFile(filesRepositoryStub)
1111

12-
const actual = await sut.execute(1)
12+
const actual = await sut.execute(1, true)
1313

1414
expect(actual).toEqual(undefined)
1515
})
@@ -20,6 +20,6 @@ describe('execute', () => {
2020

2121
const sut = new RestrictFile(filesRepositoryStub)
2222

23-
await expect(sut.execute(1)).rejects.toThrow(WriteError)
23+
await expect(sut.execute(1, true)).rejects.toThrow(WriteError)
2424
})
2525
})

0 commit comments

Comments
 (0)