Skip to content

Commit 7acecf9

Browse files
committed
Added: createCollection docs and index.ts tweaks
1 parent 1b2a5d4 commit 7acecf9

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

docs/useCases.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,39 @@ The `collectionIdOrAlias` is a generic collection identifier, which can be eithe
100100

101101
If no collection identifier is specified, the default collection identifier; `root` will be used. If you want to search for a different collection, you must add the collection identifier as a parameter in the use case call.
102102

103+
### Collections Write Use Cases
104+
105+
#### Create a Collection
106+
107+
Creates a new Collection, given a [CollectionDTO](../src/collections/domain/dtos/CollectionDTO.ts) object and an optional parent collection identifier, which defaults to `root`.
108+
109+
##### Example call:
110+
111+
```typescript
112+
import { createCollection } from '@iqss/dataverse-client-javascript'
113+
114+
/* ... */
115+
116+
const collectionDTO: CollectionDTO = {
117+
alias: alias,
118+
name: 'Test Collection',
119+
contacts: ['[email protected]'],
120+
type: CollectionType.DEPARTMENT
121+
}
122+
123+
createCollection.execute(collectionDTO).then((createdCollectionId: number) => {
124+
/* ... */
125+
})
126+
127+
/* ... */
128+
```
129+
130+
_See [use case](../src/collections/domain/useCases/CreateCollection.ts) implementation_.
131+
132+
The above example creates the new collection in the `root` collection since no collection identifier is specified. If you want to create the collection in a different collection, you must add the collection identifier as a second parameter in the use case call.
133+
134+
The use case returns a number, which is the identifier of the created collection.
135+
103136
## Datasets
104137

105138
### Datasets Read Use Cases

src/collections/domain/useCases/CreateCollection.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ export class CreateCollection implements UseCase<number> {
1111
}
1212

1313
/**
14-
* TODO
14+
* Creates a new collection, given a CollectionDTO object and an optional collection identifier, which defaults to root.
15+
*
16+
* @param {CollectionDTO} [newCollection] - CollectionDTO object including the new collection data.
17+
* @param {string} [parentCollectionId] - Specifies the parent collection identifier (optional, defaults to root).
18+
* @returns {Promise<number>} - The created collection identifier.
19+
* @throws {WriteError} - If there are errors while writing data.
1520
*/
1621
async execute(
1722
newCollection: CollectionDTO,

src/collections/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ const createCollection = new CreateCollection(collectionsRepository)
1010

1111
export { getCollection, createCollection }
1212
export { Collection } from './domain/models/Collection'
13+
export { CollectionDTO } from './domain/dtos/CollectionDTO'

0 commit comments

Comments
 (0)